Blame SOURCES/0045-tests-t3310-flags.sh-Query-libparted-for-all-flags-t.patch

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