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