]> git.pld-linux.org Git - packages/parted.git/blob - 0045-tests-t3310-flags.sh-Query-libparted-for-all-flags-t.patch
- rel 4; tons of patches from FC
[packages/parted.git] / 0045-tests-t3310-flags.sh-Query-libparted-for-all-flags-t.patch
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
5  be tested
6
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.
10
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
13 cleared.
14
15 Plus minor changes:
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.
19
20 Signed-off-by: Brian C. Lane <bcl@redhat.com>
21 ---
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
27
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
35  
36 -check_PROGRAMS = print-align print-max dup-clobber duplicate fs-resize
37 +check_PROGRAMS = print-align print-flags print-max dup-clobber duplicate \
38 +  fs-resize
39  fs_resize_LDADD = \
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
43 new file mode 100644
44 index 0000000..3176ca6
45 --- /dev/null
46 +++ b/tests/print-flags.c
47 @@ -0,0 +1,56 @@
48 +/* Print the available flags for a particular partition. */
49 +
50 +#include <config.h>
51 +#include <parted/parted.h>
52 +#include <stdio.h>
53 +#include <stdlib.h>
54 +#include "progname.h"
55 +
56 +int
57 +main (int argc, char **argv)
58 +{
59 +       PedDevice *dev;
60 +       PedDisk *disk;
61 +       PedPartition *part;
62 +
63 +       set_program_name (argv[0]);
64 +
65 +       if (argc != 2 ) {
66 +               fprintf (stderr, "Usage: %s <device>\n", argv[0]);
67 +               return EXIT_FAILURE;
68 +       }
69 +
70 +       dev = ped_device_get(argv[1]);
71 +       if (!dev) {
72 +               fprintf (stderr, "Error: failed to create device %s\n",
73 +                                argv[1]);
74 +               return EXIT_FAILURE;
75 +       }
76 +       if (!ped_device_open (dev)) {
77 +               fprintf (stderr, "Error: failed to open device %s\n", argv[1]);
78 +               return EXIT_FAILURE;
79 +       }
80 +       disk = ped_disk_new (dev);
81 +       if (!disk) {
82 +               fprintf (stderr,
83 +                        "Error: failed to read partition table from device %s\n",
84 +                        argv[1]);
85 +               return EXIT_FAILURE;
86 +       }
87 +
88 +       part = ped_disk_get_partition (disk, 1);
89 +       if (!part) {
90 +               fprintf (stderr,
91 +                        "Error: failed to get partition 1 from device %s\n",
92 +                        argv[1]);
93 +               return EXIT_FAILURE;
94 +       }
95 +
96 +       for (PedPartitionFlag flag = PED_PARTITION_FIRST_FLAG;
97 +            flag <= PED_PARTITION_LAST_FLAG; flag++)
98 +       {
99 +               if (ped_partition_is_flag_available (part, flag))
100 +                       puts (ped_partition_flag_get_name (flag));
101 +       }
102 +       return EXIT_SUCCESS;
103 +}
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
108 @@ -1,5 +1,5 @@
109  #!/bin/sh
110 -# Exercise the exclusive, single-bit flags.
111 +# Exercise partition flags.
112  
113  # Copyright (C) 2010-2014 Free Software Foundation, Inc.
114  
115 @@ -16,35 +16,37 @@
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/>.
118  
119 -. "${srcdir=.}/init.sh"; path_prepend_ ../parted
120 +. "${srcdir=.}/init.sh"; path_prepend_ ../parted .
121  ss=$sector_size_
122  dev=dev-file
123  
124  extract_flags()
125  {
126 -  perl -nle '/^1:2048s:4095s:2048s::(?:P1)?:(.+);$/ and print $1' "$@"
127 +  perl -nle '/^1:2048s:4095s:2048s::(?:PTNNAME)?:(.+);$/ and print $1' "$@"
128  }
129  
130  for table_type in msdos gpt; do
131  
132 -  # Extract flag names of type $table_type from the texinfo documentation.
133    case $table_type in
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'
137 +           ;;
138 +    msdos) primary_or_name='primary'
139 +           ;;
140    esac
141 -  flags=$(sed -n '/^@node set/,/^@node/p' \
142 -                    "$abs_top_srcdir/doc/parted.texi" \
143 -                | perl -00 -ne \
144 -                    '/^\@item (\w+).*'"$search_term"'/s and print lc($1), "\n"')
145  
146    n_sectors=5000
147    dd if=/dev/null of=$dev bs=$ss seek=$n_sectors || fail=1
148  
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
154  
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; }
159 +
160    for mode in on_only on_and_off ; do
161      for flag in $flags; do
162  
163 @@ -53,18 +55,18 @@ for table_type in msdos gpt; do
164        case $flag in boot|lba|hidden) continue;; esac
165  
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
174  
175        if test $mode = on_and_off; then
176          # Turn it off
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
184        fi
185      done
186 -- 
187 2.7.4
188
This page took 0.05483 seconds and 3 git commands to generate.