OSDN Git Service

tests: convert t4100-dvh-partition-limits.sh to use init.sh
authorJim Meyering <meyering@redhat.com>
Thu, 18 Nov 2010 12:06:57 +0000 (13:06 +0100)
committerJim Meyering <meyering@redhat.com>
Sat, 20 Nov 2010 16:03:02 +0000 (17:03 +0100)
* tests/t4100-dvh-partition-limits.sh: Convert.

tests/t4100-dvh-partition-limits.sh

index 1016077..23f84a1 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/sh
+# enforce limits on partition start sector and length
 
 # Copyright (C) 2008-2010 Free Software Foundation, Inc.
 
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-test_description='enforce limits on partition start sector and length'
-
-# Need root privileges to use mount.
-privileges_required_=1
-
-: ${srcdir=.}
-. $srcdir/test-lib.sh
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+require_root_
 require_xfs_
 ss=$sector_size_
 
@@ -29,7 +25,7 @@ ss=$sector_size_
 # Otherwise, due to an inherent 32-bit-XFS limit, dd would fail to
 # create the file of size > 16TiB
 if test $(uname -m) != x86_64; then
-  test $ss -le 2048 || exit 77
+  test $ss -le 2048 || skip_ 'this test works only on a 64-bit system'
 fi
 
 ####################################################
@@ -40,29 +36,23 @@ fs=fs_file
 mp=`pwd`/mount-point
 n=4096
 
-test_expect_success \
-    'create an XFS file system' \
-    '
-    dd if=/dev/zero of=$fs bs=1MB count=2 seek=20 &&
-    mkfs.xfs -f -q $fs &&
-    mkdir "$mp"
-
-    '
+# create an XFS file system
+dd if=/dev/zero of=$fs bs=1MB count=2 seek=20 || fail=1
+mkfs.xfs -f -q $fs || fail=1
+mkdir "$mp" || fail=1
 
 # Unmount upon interrupt, failure, etc., as well as upon normal completion.
 cleanup_() { cd "$test_dir_" && umount "$mp" > /dev/null 2>&1; }
 
-test_expect_success \
-    'mount it' \
-    '
-    mount -o loop $fs "$mp" &&
-    cd "$mp"
+# mount it
+mount -o loop $fs "$mp" || fail=1
+cd "$mp" || fail=1
 
-    '
 dev=loop-file
 
 do_mkpart()
 {
+  set +x # Turn off tracing; otherwise, we pollute stderr.
   start_sector=$1
   end_sector=$2
   # echo '********' $(echo $end_sector - $start_sector + 1 |bc)
@@ -75,6 +65,7 @@ do_mkpart()
 # rather than start and end.
 do_mkpart_start_and_len()
 {
+  set +x # Turn off tracing; otherwise, we pollute stderr.
   start_sector=$1
   len=$2
   end_sector=$(echo $start_sector + $len - 1|bc)
@@ -83,31 +74,27 @@ do_mkpart_start_and_len()
 
 for table_type in dvh; do
 
-test_expect_success \
-    "$table_type: a partition length of 2^32-1 works." \
-    '
-    end=$(echo $n+2^32-2|bc) &&
-    do_mkpart $n $end
-    '
-
-test_expect_success \
-    'print the result' \
-    'parted -s $dev unit s p > out 2>&1 &&
-     sed -n "/^  *1  *$n/s/  */ /gp" out|sed "s/  *\$//" > k && mv k out &&
-     echo " 1 ${n}s ${end}s 4294967295s primary" > exp &&
-     diff -u out exp
-    '
-
-test_expect_failure \
-    "$table_type: a partition length of exactly 2^32 sectors provokes failure." \
-    'do_mkpart $n $(echo $n+2^32-1|bc) > err 2>&1'
+# a partition length of 2^32-1 works.
+end=$(echo $n+2^32-2|bc) || fail=1
+do_mkpart $n $end || fail=1
+
+# print the result
+parted -s $dev unit s p > out 2>&1 || fail=1
+sed -n "/^  *1  *$n/s/  */ /gp" out|sed "s/  *\$//" > k && mv k out || fail=1
+echo " 1 ${n}s ${end}s 4294967295s primary" > exp || fail=1
+compare out exp || fail=1
+
+# a partition length of exactly 2^32 sectors provokes failure.
+do_mkpart $n $(echo $n+2^32-1|bc) > err 2>&1
+test $? = 1 || fail=1
 
 bad_part_length()
 { echo "Error: partition length of $1 sectors exceeds the"\
   "$table_type-partition-table-imposed maximum of 4294967295"; }
-test_expect_success \
-    'check for new diagnostic' \
-    'bad_part_length 4294967296 > exp && diff -u err exp'
+
+# check for new diagnostic
+bad_part_length 4294967296 > exp || fail=1
+compare err exp || fail=1
 
 # FIXME: investigate this.
 # Unexpectedly to me, both of these failed with this same diagnostic:
@@ -120,13 +107,13 @@ test_expect_success \
 # but the diagnostic doesn't get displayed because of the wonders
 # of parted's exception mechanism.
 
-test_expect_failure \
-    "$table_type: a partition length of 2^32+1 sectors provokes failure." \
-    'do_mkpart $n $(echo $n+2^32|bc) > err 2>&1'
+# a partition length of 2^32+1 sectors must provoke failure.
+do_mkpart $n $(echo $n+2^32|bc) > err 2>&1
+test $? = 1 || fail=1
 
-test_expect_success \
-    'check for new diagnostic' \
-    'bad_part_length 4294967297 > exp && diff -u err exp'
+# check for new diagnostic
+bad_part_length 4294967297 > exp || fail=1
+compare err exp || fail=1
 
 # =========================================================
 # Now consider partition starting sector numbers.
@@ -134,9 +121,8 @@ bad_start_sector()
 { echo "Error: starting sector number, $1 exceeds the"\
   "$table_type-partition-table-imposed maximum of 4294967295"; }
 
-test_expect_success \
-    "$table_type: a partition start sector number of 2^32-1 works." \
-    'do_mkpart_start_and_len $(echo 2^32-1|bc) 1000'
+# a partition start sector number of 2^32-1 works.
+do_mkpart_start_and_len $(echo 2^32-1|bc) 1000 || fail=1
 
 # FIXME: this partition number 9 (not requested!) looks totally bogus
 # FIXME: For now, we just expect what the code produces.
@@ -153,27 +139,27 @@ Number  Start        End          Size   Type      File system  Name  Flags
 
 EOF
 
-test_expect_success \
-    'print the result' \
-    'parted -s $dev unit s p > out 2>&1 &&
-     sed "s/Disk .*:/Disk:/;s/ *$//" out > k && mv k out &&
-     diff -u out exp
-    '
-
-test_expect_failure \
-    "$table_type: a partition start sector number of 2^32 must fail." \
-    'do_mkpart_start_and_len $(echo 2^32|bc) 1000 > err 2>&1'
-test_expect_success \
-    'check for new diagnostic' \
-    'bad_start_sector 4294967296 > exp && diff -u err exp'
-
-test_expect_failure \
-    "$table_type: a partition start sector number of 2^32+1 must fail, too." \
-    'do_mkpart_start_and_len $(echo 2^32+1|bc) 1000 > err 2>&1'
-test_expect_success \
-    'check for new diagnostic' \
-    'bad_start_sector 4294967297 > exp && diff -u err exp'
+# print the result
+parted -s $dev unit s p > out 2>&1 || fail=1
+sed "s/Disk .*:/Disk:/;s/ *$//" out > k && mv k out || fail=1
+compare out exp || fail=1
+
+# a partition start sector number of 2^32 must fail
+do_mkpart_start_and_len $(echo 2^32|bc) 1000 > err 2>&1
+test $? = 1 || fail=1
+
+# check for new diagnostic
+bad_start_sector 4294967296 > exp || fail=1
+compare err exp || fail=1
+
+# a partition start sector number of 2^32+1 must fail, too.
+do_mkpart_start_and_len $(echo 2^32+1|bc) 1000 > err 2>&1
+test $? = 1 || fail=1
+
+# check for new diagnostic
+bad_start_sector 4294967297 > exp || fail=1
+compare err exp || fail=1
 
 done
 
-test_done
+Exit $fail