parted/0045-tests-t3310-flags.sh-Query-libparted-for-all-flags-t.patch
Brian C. Lane c6a1bfceda - tests: t3310-flags.sh: skip pc98 when sector size != 512 (bcl)
- tests: Set optimal blocks to 64 for scsi_debug devices (bcl)
- tests: t3310-flags.sh: Add tests for remaining table types (mike.fleetwood)
- tests: t3310-flags.sh: Add test for dvh table flags (mike.fleetwood)
- tests: t3310-flags.sh: Add test for mac table flags (mike.fleetwood)
- libparted: Remove commented local variable from bsd_partition_set_flag()
  (mike.fleetwood)
- libparted: Fix to report success when setting lvm flag on bsd table
  (mike.fleetwood)
- tests: t3310-flags.sh: Add test for bsd table flags (mike.fleetwood)
- tests: t3310-flags.sh: Stop excluding certain flags from being tested
  (mike.fleetwood)
- tests: t3310-flags.sh: Query libparted for all flags to be tested
  (mike.fleetwood)
- libparted: only IEC units are treated as exact (petr.uzel)
- docs: Improve partition description in parted.texi (gareth.randall)
- Add support for NVMe devices (petr.uzel)
- libparted/dasd: correct the offset where the first partition begins
  (dongdwdw)
2016-10-04 16:53:44 -07:00

189 lines
5.9 KiB
Diff

From 450dbead63306b242e8159c85641698bddf6d19e Mon Sep 17 00:00:00 2001
From: Mike Fleetwood <mike.fleetwood@googlemail.com>
Date: Sat, 1 Oct 2016 16:40:16 +0100
Subject: [PATCH 45/53] tests: t3310-flags.sh: Query libparted for all flags to
be tested
Replace scanning the documentation for an incomplete list of flags with
querying libparted for the complete list of supported flags via the
added helper print-flags.
Correct $ME -> $ME_ in the warning messages. Improve the warning
messages by including the table type and flag name not correctly set or
cleared.
Plus minor changes:
(1) use slightly longer variable name primary_or_name;
(2) use longer test partition name PTNNAME; and
(3) stop shortening parted unit command to u.
Signed-off-by: Brian C. Lane <bcl@redhat.com>
---
tests/Makefile.am | 3 ++-
tests/print-flags.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/t3310-flags.sh | 32 ++++++++++++++++--------------
3 files changed, 75 insertions(+), 16 deletions(-)
create mode 100644 tests/print-flags.c
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6a06dce..a840304 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -92,7 +92,8 @@ EXTRA_DIST = \
init.cfg init.sh t-lib-helpers.sh gpt-header-munge \
gpt-header-move msdos-overlap
-check_PROGRAMS = print-align print-max dup-clobber duplicate fs-resize
+check_PROGRAMS = print-align print-flags print-max dup-clobber duplicate \
+ fs-resize
fs_resize_LDADD = \
$(top_builddir)/libparted/fs/libparted-fs-resize.la \
$(top_builddir)/libparted/libparted.la
diff --git a/tests/print-flags.c b/tests/print-flags.c
new file mode 100644
index 0000000..3176ca6
--- /dev/null
+++ b/tests/print-flags.c
@@ -0,0 +1,56 @@
+/* Print the available flags for a particular partition. */
+
+#include <config.h>
+#include <parted/parted.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "progname.h"
+
+int
+main (int argc, char **argv)
+{
+ PedDevice *dev;
+ PedDisk *disk;
+ PedPartition *part;
+
+ set_program_name (argv[0]);
+
+ if (argc != 2 ) {
+ fprintf (stderr, "Usage: %s <device>\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ dev = ped_device_get(argv[1]);
+ if (!dev) {
+ fprintf (stderr, "Error: failed to create device %s\n",
+ argv[1]);
+ return EXIT_FAILURE;
+ }
+ if (!ped_device_open (dev)) {
+ fprintf (stderr, "Error: failed to open device %s\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+ disk = ped_disk_new (dev);
+ if (!disk) {
+ fprintf (stderr,
+ "Error: failed to read partition table from device %s\n",
+ argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ part = ped_disk_get_partition (disk, 1);
+ if (!part) {
+ fprintf (stderr,
+ "Error: failed to get partition 1 from device %s\n",
+ argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ for (PedPartitionFlag flag = PED_PARTITION_FIRST_FLAG;
+ flag <= PED_PARTITION_LAST_FLAG; flag++)
+ {
+ if (ped_partition_is_flag_available (part, flag))
+ puts (ped_partition_flag_get_name (flag));
+ }
+ return EXIT_SUCCESS;
+}
diff --git a/tests/t3310-flags.sh b/tests/t3310-flags.sh
index cb3024a..85a673a 100644
--- a/tests/t3310-flags.sh
+++ b/tests/t3310-flags.sh
@@ -1,5 +1,5 @@
#!/bin/sh
-# Exercise the exclusive, single-bit flags.
+# Exercise partition flags.
# Copyright (C) 2010-2014 Free Software Foundation, Inc.
@@ -16,35 +16,37 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted .
ss=$sector_size_
dev=dev-file
extract_flags()
{
- perl -nle '/^1:2048s:4095s:2048s::(?:P1)?:(.+);$/ and print $1' "$@"
+ perl -nle '/^1:2048s:4095s:2048s::(?:PTNNAME)?:(.+);$/ and print $1' "$@"
}
for table_type in msdos gpt; do
- # Extract flag names of type $table_type from the texinfo documentation.
case $table_type in
- msdos) search_term=MS-DOS; pri_or_name=pri;;
- gpt) search_term=GPT; pri_or_name=P1;;
+ gpt) primary_or_name='PTNNAME'
+ ;;
+ msdos) primary_or_name='primary'
+ ;;
esac
- flags=$(sed -n '/^@node set/,/^@node/p' \
- "$abs_top_srcdir/doc/parted.texi" \
- | perl -00 -ne \
- '/^\@item (\w+).*'"$search_term"'/s and print lc($1), "\n"')
n_sectors=5000
dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
parted -s $dev mklabel $table_type \
- mkpart $pri_or_name ext2 $((1*2048))s $((2*2048-1))s \
+ mkpart $primary_or_name ext2 $((1*2048))s $((2*2048-1))s \
> out 2> err || fail=1
compare /dev/null out || fail=1
+ # Query libparted for the available flags for this test partition.
+ flags=`print-flags $dev` \
+ || { warn_ "$ME_: $table_type: failed to get available flags";
+ fail=1; continue; }
+
for mode in on_only on_and_off ; do
for flag in $flags; do
@@ -53,18 +55,18 @@ for table_type in msdos gpt; do
case $flag in boot|lba|hidden) continue;; esac
# Turn on each flag, one at a time.
- parted -m -s $dev set 1 $flag on u s print > raw 2> err || fail=1
+ parted -m -s $dev set 1 $flag on unit s print > raw 2> err || fail=1
extract_flags raw > out
grep -F "$flag" out \
- || { warn_ "$ME: flag not turned on: $(cat out)"; fail=1; }
+ || { warn_ "$ME_: $table_type: flag '$flag' not turned on: $(cat out)"; fail=1; }
compare /dev/null err || fail=1
if test $mode = on_and_off; then
# Turn it off
- parted -m -s $dev set 1 $flag off u s print > raw 2> err || fail=1
+ parted -m -s $dev set 1 $flag off unit s print > raw 2> err || fail=1
extract_flags raw > out
grep -F "$flag" out \
- && { warn_ "$ME: flag not turned off: $(cat out)"; fail=1; }
+ && { warn_ "$ME_: $table_type: flag '$flag' not turned off: $(cat out)"; fail=1; }
compare /dev/null err || fail=1
fi
done
--
2.7.4