[PATCH 3/4] tests: t2100: use mkswap command, not parted's mkfs

Jim Meyering meyering at redhat.com
Fri Sep 18 06:23:09 UTC 2009


Now that we've removed mkfs, we must deal with the consequences.
Create swap file systems using mkswap.
Perhaps more troublesome, this test must now be run as root
and with an actual device that it can erase: parted could
create a swap file system on the first partition in a file,
but mkswap cannot.
* tests/t2100-mkswap.sh: Rework not to perof
---
 tests/t2100-mkswap.sh |   64 +++++++++++++++++++------------------------=
-----
 1 files changed, 25 insertions(+), 39 deletions(-)

diff --git a/tests/t2100-mkswap.sh b/tests/t2100-mkswap.sh
index 7650e53..95382b0 100755
--- a/tests/t2100-mkswap.sh
+++ b/tests/t2100-mkswap.sh
@@ -17,19 +17,21 @@

 test_description=3D'create linux-swap partitions'

+privileges_required_=3D1
+erasable_device_required_=3D1
+
 : ${srcdir=3D.}
 . $srcdir/test-lib.sh

 require_512_byte_sector_size_
+dev=3D$DEVICE_TO_ERASE

 ######################################################################
 # When creating a partition of type linux-swap(v1) in a DOS partition
 # table, ensure that the proper file system type (0x82) is used.
 # Some releases, e.g. parted-1.8.8 would mistakenly use 0x83.
 ######################################################################
-N=3D1M
-dev=3Dloop-file
-dev2=3Dloop-file-2
+N=3D5M
 test_expect_success \
     'create a file to simulate the underlying device' \
     'dd if=3D/dev/null of=3D$dev bs=3D1 seek=3D$N 2> /dev/null'
@@ -41,13 +43,22 @@ test_expect_success 'expect no output' 'compare out /=
dev/null'

 test_expect_success \
     'create a partition' \
-    'parted -s $dev mkpart primary 0 1 > out 2>&1'
+    'parted -s $dev mkpart primary "linux-swap(v1)" 0 2 > out 2>&1'
 test_expect_success 'expect no output' 'compare out /dev/null'

+# There's a race condition here: on udev-based systems, the partition#1
+# device, ${dev}1 (i.e., /dev/sde1) is not created immediately, and
+# without some delay, this mount command would fail.  Using a flash card
+# as $dev, the loop below typically iterates 7-20 times.
+test_expect_success \
+    'wait for new partition device to appear' \
+    'i=3D0; while :; do
+            test -e "${dev}1" && break; test $i =3D 90 && break;
+	    i=3D$(expr $i + 1); done'
+
 test_expect_success \
     'create a linux-swap file system' \
-    'parted -s $dev mkfs 1 "linux-swap(v1)" > out 2>&1'
-test_expect_success 'expect no output' 'compare out /dev/null'
+    'mkswap ${dev}1'

 # Extract the byte at offset 451.  It must be 0x82, not 0x83.
 test_expect_success \
@@ -55,51 +66,26 @@ test_expect_success \
     'od -t x1 -An -j450 -N1 $dev > out && echo " 82" > exp'
 test_expect_success 'expect it to be 82, not 83' 'compare out exp'

+# partition starts at offset 16384; swap UUID is 1036 bytes in
+# Save its UUID for later.
 test_expect_success \
-    'create another file to simulate the underlying device' \
-    'dd if=3D/dev/null of=3D$dev2 bs=3D1 seek=3D$N 2> /dev/null'
-
-test_expect_success \
-    'label another test disk' \
-    'parted -s $dev2 mklabel msdos > out 2>&1'
-test_expect_success 'expect no output' 'compare out /dev/null'
-
-test_expect_success \
-    'create another partition' \
-    'parted -s $dev2 mkpart primary 0 1 > out 2>&1'
-test_expect_success 'expect no output' 'compare out /dev/null'
+    'extract UUID 1' \
+    'od -t x1 -An -j1036 -N16 ${dev}1 > uuid1'

 test_expect_success \
     'create another linux-swap file system' \
-    'parted -s $dev2 mkfs 1 "linux-swap(v1)" > out 2>&1'
-test_expect_success 'expect no output' 'compare out /dev/null'
+    'mkswap ${dev}1'

-# partition starts at offset 16384; swap UUID is 1036 bytes in
-test_expect_success \
-    'extract UUID 1' \
-    'od -t x1 -An -j17420 -N16 $dev > uuid1'
 test_expect_success \
     'extract UUID 2' \
-    'od -t x1 -An -j17420 -N16 $dev2 > uuid2'
+    'od -t x1 -An -j1036 -N16 ${dev}1 > uuid2'
 test_expect_failure \
     'two linux-swap file systems have different UUIDs' \
     'compare uuid1 uuid2'

 test_expect_success \
-    'check linux-swap file system' \
-    'parted -s $dev2 check 1 > out 2>&1'
-test_expect_success 'expect no output' 'compare out /dev/null'
-
-test_expect_success \
-    'extract new UUID 2' \
-    'od -t x1 -An -j17420 -N16 $dev2 > uuid2-new'
-test_expect_success \
-    'check preserves linux-swap UUID' \
-    'compare uuid2 uuid2-new'
-
-test_expect_success \
-    'create a linux-swap file system via alias' \
-    'parted -s $dev mkfs 1 linux-swap > out 2>&1'
+    'create a partition, and specify its type via the alias, linux-swap'=
 \
+    'parted -s $dev mkpart primary linux-swap 2 3 > out 2>&1'
 test_expect_success 'expect no output' 'compare out /dev/null'

 test_done
--=20
1.6.5.rc1.192.g63b0




More information about the parted-devel mailing list