Blame SOURCES/0050-tests-t3310-flags.sh-Add-test-for-mac-table-flags.patch

0cb0b9
From 81b397bbc9eb270ef0b3ed52d40c3a76ecd9ac80 Mon Sep 17 00:00:00 2001
0cb0b9
From: Mike Fleetwood <mike.fleetwood@googlemail.com>
0cb0b9
Date: Sat, 1 Oct 2016 16:40:21 +0100
0cb0b9
Subject: [PATCH 50/53] tests: t3310-flags.sh: Add test for mac table flags
0cb0b9
0cb0b9
MAC partition table reserves partition 1 for the partition map
0cb0b9
partition, so the created test partition will be number 2.  Adapt
0cb0b9
accordingly.
0cb0b9
0cb0b9
Setting flags 'root' and 'swap' also sets the partition name to 'root'
0cb0b9
and 'swap' respectively, so no longer match the partition name in
0cb0b9
extract_flags().
0cb0b9
0cb0b9
Don't test lvm and raid flags as they fail to be cleared with a single
0cb0b9
set off command.  See FIXME comment in the test for more details.
0cb0b9
0cb0b9
Signed-off-by: Brian C. Lane <bcl@redhat.com>
0cb0b9
---
0cb0b9
 tests/print-flags.c  | 12 +++++++-----
0cb0b9
 tests/t3310-flags.sh | 27 ++++++++++++++++++++++-----
0cb0b9
 2 files changed, 29 insertions(+), 10 deletions(-)
0cb0b9
0cb0b9
diff --git a/tests/print-flags.c b/tests/print-flags.c
0cb0b9
index 3176ca6..db088e8 100644
0cb0b9
--- a/tests/print-flags.c
0cb0b9
+++ b/tests/print-flags.c
0cb0b9
@@ -12,11 +12,12 @@ main (int argc, char **argv)
0cb0b9
 	PedDevice *dev;
0cb0b9
 	PedDisk *disk;
0cb0b9
 	PedPartition *part;
0cb0b9
+	int partnum;
0cb0b9
 
0cb0b9
 	set_program_name (argv[0]);
0cb0b9
 
0cb0b9
-	if (argc != 2 ) {
0cb0b9
-		fprintf (stderr, "Usage: %s <device>\n", argv[0]);
0cb0b9
+	if (argc != 3 ) {
0cb0b9
+		fprintf (stderr, "Usage: %s <device> <ptnnum>\n", argv[0]);
0cb0b9
 		return EXIT_FAILURE;
0cb0b9
 	}
0cb0b9
 
0cb0b9
@@ -38,11 +39,12 @@ main (int argc, char **argv)
0cb0b9
 		return EXIT_FAILURE;
0cb0b9
 	}
0cb0b9
 
0cb0b9
-	part = ped_disk_get_partition (disk, 1);
0cb0b9
+	partnum = atoi (argv[2]);
0cb0b9
+	part = ped_disk_get_partition (disk, partnum);
0cb0b9
 	if (!part) {
0cb0b9
 		fprintf (stderr,
0cb0b9
-		         "Error: failed to get partition 1 from device %s\n",
0cb0b9
-		         argv[1]);
0cb0b9
+		         "Error: failed to get partition %d from device %s\n",
0cb0b9
+		         partnum, argv[1]);
0cb0b9
 		return EXIT_FAILURE;
0cb0b9
 	}
0cb0b9
 
0cb0b9
diff --git a/tests/t3310-flags.sh b/tests/t3310-flags.sh
0cb0b9
index 3f80213..672160d 100644
0cb0b9
--- a/tests/t3310-flags.sh
0cb0b9
+++ b/tests/t3310-flags.sh
0cb0b9
@@ -22,16 +22,22 @@ dev=dev-file
0cb0b9
 
0cb0b9
 extract_flags()
0cb0b9
 {
0cb0b9
-  perl -nle '/^1:2048s:4095s:2048s::(?:PTNNAME)?:(.+);$/ and print $1' "$@"
0cb0b9
+  perl -nle '/^[^:]*:2048s:4095s:2048s::[^:]*:(.+);$/ and print $1' "$@"
0cb0b9
 }
0cb0b9
 
0cb0b9
-for table_type in bsd gpt msdos; do
0cb0b9
+for table_type in bsd gpt mac msdos; do
0cb0b9
+  ptn_num=1
0cb0b9
 
0cb0b9
   case $table_type in
0cb0b9
     bsd)   primary_or_name=''
0cb0b9
            ;;
0cb0b9
     gpt)   primary_or_name='PTNNAME'
0cb0b9
            ;;
0cb0b9
+    mac)   primary_or_name='PTNNAME'
0cb0b9
+           # MAC table has the partition map partition as the first
0cb0b9
+           # partition so the created test partition will be number 2.
0cb0b9
+           ptn_num=2
0cb0b9
+           ;;
0cb0b9
     msdos) primary_or_name='primary'
0cb0b9
            ;;
0cb0b9
   esac
0cb0b9
@@ -45,14 +51,25 @@ for table_type in bsd gpt msdos; do
0cb0b9
   compare /dev/null out || fail=1
0cb0b9
 
0cb0b9
   # Query libparted for the available flags for this test partition.
0cb0b9
-  flags=`print-flags $dev` \
0cb0b9
+  flags=`print-flags $dev $ptn_num` \
0cb0b9
     || { warn_ "$ME_: $table_type: failed to get available flags";
0cb0b9
          fail=1; continue; }
0cb0b9
+  case $table_type in
0cb0b9
+    mac)   # FIXME: Setting root or swap flags also sets the partition
0cb0b9
+           # name to root or swap respectively.  Probably intended
0cb0b9
+           # behaviour.  Setting lvm or raid flags after root or swap
0cb0b9
+           # takes two goes to clear the lvm or raid flag.  Is this
0cb0b9
+           # intended?  For now don't test lvm or raid flags as this
0cb0b9
+           # test only tries to clear the flags once which causes this
0cb0b9
+           # test to fail.
0cb0b9
+           flags=`echo "$flags" | egrep -v 'lvm|raid'`
0cb0b9
+           ;;
0cb0b9
+  esac
0cb0b9
 
0cb0b9
   for mode in on_only on_and_off ; do
0cb0b9
     for flag in $flags; do
0cb0b9
       # Turn on each flag, one at a time.
0cb0b9
-      parted -m -s $dev set 1 $flag on unit s print > raw 2> err || fail=1
0cb0b9
+      parted -m -s $dev set $ptn_num $flag on unit s print > raw 2> err || fail=1
0cb0b9
       extract_flags raw > out
0cb0b9
       grep -w "$flag" out \
0cb0b9
         || { warn_ "$ME_: $table_type: flag '$flag' not turned on: $(cat out)"; fail=1; }
0cb0b9
@@ -60,7 +77,7 @@ for table_type in bsd gpt msdos; do
0cb0b9
 
0cb0b9
       if test $mode = on_and_off; then
0cb0b9
         # Turn it off
0cb0b9
-        parted -m -s $dev set 1 $flag off unit s print > raw 2> err || fail=1
0cb0b9
+        parted -m -s $dev set $ptn_num $flag off unit s print > raw 2> err || fail=1
0cb0b9
         extract_flags raw > out
0cb0b9
         grep -w "$flag" out \
0cb0b9
           && { warn_ "$ME_: $table_type: flag '$flag' not turned off: $(cat out)"; fail=1; }
0cb0b9
-- 
0cb0b9
2.7.4
0cb0b9