1 From 450dbead63306b242e8159c85641698bddf6d19e Mon Sep 17 00:00:00 2001
2 From: Mike Fleetwood <mike.fleetwood@googlemail.com>
3 Date: Sat, 1 Oct 2016 16:40:16 +0100
4 Subject: [PATCH 45/53] tests: t3310-flags.sh: Query libparted for all flags to
7 Replace scanning the documentation for an incomplete list of flags with
8 querying libparted for the complete list of supported flags via the
9 added helper print-flags.
11 Correct $ME -> $ME_ in the warning messages. Improve the warning
12 messages by including the table type and flag name not correctly set or
16 (1) use slightly longer variable name primary_or_name;
17 (2) use longer test partition name PTNNAME; and
18 (3) stop shortening parted unit command to u.
20 Signed-off-by: Brian C. Lane <bcl@redhat.com>
22 tests/Makefile.am | 3 ++-
23 tests/print-flags.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++
24 tests/t3310-flags.sh | 32 ++++++++++++++++--------------
25 3 files changed, 75 insertions(+), 16 deletions(-)
26 create mode 100644 tests/print-flags.c
28 diff --git a/tests/Makefile.am b/tests/Makefile.am
29 index 6a06dce..a840304 100644
30 --- a/tests/Makefile.am
31 +++ b/tests/Makefile.am
32 @@ -92,7 +92,8 @@ EXTRA_DIST = \
33 init.cfg init.sh t-lib-helpers.sh gpt-header-munge \
34 gpt-header-move msdos-overlap
36 -check_PROGRAMS = print-align print-max dup-clobber duplicate fs-resize
37 +check_PROGRAMS = print-align print-flags print-max dup-clobber duplicate \
40 $(top_builddir)/libparted/fs/libparted-fs-resize.la \
41 $(top_builddir)/libparted/libparted.la
42 diff --git a/tests/print-flags.c b/tests/print-flags.c
44 index 0000000..3176ca6
46 +++ b/tests/print-flags.c
48 +/* Print the available flags for a particular partition. */
51 +#include <parted/parted.h>
54 +#include "progname.h"
57 +main (int argc, char **argv)
63 + set_program_name (argv[0]);
66 + fprintf (stderr, "Usage: %s <device>\n", argv[0]);
67 + return EXIT_FAILURE;
70 + dev = ped_device_get(argv[1]);
72 + fprintf (stderr, "Error: failed to create device %s\n",
74 + return EXIT_FAILURE;
76 + if (!ped_device_open (dev)) {
77 + fprintf (stderr, "Error: failed to open device %s\n", argv[1]);
78 + return EXIT_FAILURE;
80 + disk = ped_disk_new (dev);
83 + "Error: failed to read partition table from device %s\n",
85 + return EXIT_FAILURE;
88 + part = ped_disk_get_partition (disk, 1);
91 + "Error: failed to get partition 1 from device %s\n",
93 + return EXIT_FAILURE;
96 + for (PedPartitionFlag flag = PED_PARTITION_FIRST_FLAG;
97 + flag <= PED_PARTITION_LAST_FLAG; flag++)
99 + if (ped_partition_is_flag_available (part, flag))
100 + puts (ped_partition_flag_get_name (flag));
102 + return EXIT_SUCCESS;
104 diff --git a/tests/t3310-flags.sh b/tests/t3310-flags.sh
105 index cb3024a..85a673a 100644
106 --- a/tests/t3310-flags.sh
107 +++ b/tests/t3310-flags.sh
110 -# Exercise the exclusive, single-bit flags.
111 +# Exercise partition flags.
113 # Copyright (C) 2010-2014 Free Software Foundation, Inc.
116 # You should have received a copy of the GNU General Public License
117 # along with this program. If not, see <http://www.gnu.org/licenses/>.
119 -. "${srcdir=.}/init.sh"; path_prepend_ ../parted
120 +. "${srcdir=.}/init.sh"; path_prepend_ ../parted .
126 - perl -nle '/^1:2048s:4095s:2048s::(?:P1)?:(.+);$/ and print $1' "$@"
127 + perl -nle '/^1:2048s:4095s:2048s::(?:PTNNAME)?:(.+);$/ and print $1' "$@"
130 for table_type in msdos gpt; do
132 - # Extract flag names of type $table_type from the texinfo documentation.
134 - msdos) search_term=MS-DOS; pri_or_name=pri;;
135 - gpt) search_term=GPT; pri_or_name=P1;;
136 + gpt) primary_or_name='PTNNAME'
138 + msdos) primary_or_name='primary'
141 - flags=$(sed -n '/^@node set/,/^@node/p' \
142 - "$abs_top_srcdir/doc/parted.texi" \
144 - '/^\@item (\w+).*'"$search_term"'/s and print lc($1), "\n"')
147 dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
149 parted -s $dev mklabel $table_type \
150 - mkpart $pri_or_name ext2 $((1*2048))s $((2*2048-1))s \
151 + mkpart $primary_or_name ext2 $((1*2048))s $((2*2048-1))s \
152 > out 2> err || fail=1
153 compare /dev/null out || fail=1
155 + # Query libparted for the available flags for this test partition.
156 + flags=`print-flags $dev` \
157 + || { warn_ "$ME_: $table_type: failed to get available flags";
158 + fail=1; continue; }
160 for mode in on_only on_and_off ; do
161 for flag in $flags; do
163 @@ -53,18 +55,18 @@ for table_type in msdos gpt; do
164 case $flag in boot|lba|hidden) continue;; esac
166 # Turn on each flag, one at a time.
167 - parted -m -s $dev set 1 $flag on u s print > raw 2> err || fail=1
168 + parted -m -s $dev set 1 $flag on unit s print > raw 2> err || fail=1
169 extract_flags raw > out
170 grep -F "$flag" out \
171 - || { warn_ "$ME: flag not turned on: $(cat out)"; fail=1; }
172 + || { warn_ "$ME_: $table_type: flag '$flag' not turned on: $(cat out)"; fail=1; }
173 compare /dev/null err || fail=1
175 if test $mode = on_and_off; then
177 - parted -m -s $dev set 1 $flag off u s print > raw 2> err || fail=1
178 + parted -m -s $dev set 1 $flag off unit s print > raw 2> err || fail=1
179 extract_flags raw > out
180 grep -F "$flag" out \
181 - && { warn_ "$ME: flag not turned off: $(cat out)"; fail=1; }
182 + && { warn_ "$ME_: $table_type: flag '$flag' not turned off: $(cat out)"; fail=1; }
183 compare /dev/null err || fail=1