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