[parted-devel] [PATCH] tests: t9030 wait for partition removal

Jim Meyering jim at meyering.net
Fri Nov 4 20:39:01 UTC 2011


Brian C. Lane wrote:
> From: "Brian C. Lane" <bcl at redhat.com>
>
> The removal of the partition may take enough time that the next
> mkpart will fail. Wait for it to be removed.
>
> Remove scsi_debug size and set the end of the partition to 8000s so
> that it will fit inside the default scsi_debug size of 8M. This
> prevents failures on machines with limited memory.
>
>  * tests/t9030-align-check.sh: wait for partition removal and use
>    smaller disk.
> ---
>  tests/t9030-align-check.sh |   12 ++++++++++--
>  1 files changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/tests/t9030-align-check.sh b/tests/t9030-align-check.sh
> index bc8ae09..805fa40 100644
> --- a/tests/t9030-align-check.sh
> +++ b/tests/t9030-align-check.sh
> @@ -25,7 +25,7 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
>    skip_ 'this system lacks a new-enough libblkid'
>
>  # create memory-backed device
> -scsi_debug_setup_ dev_size_mb=550 physblk_exp=3 lowest_aligned=7 > dev-name ||
> +scsi_debug_setup_ physblk_exp=3 lowest_aligned=7 > dev-name ||
>    skip_ 'failed to create scsi_debug device'
>  scsi_dev=$(cat dev-name)
>  p1=${scsi_dev}1
> @@ -34,7 +34,7 @@ parted -s $scsi_dev mklabel gpt || fail=1
>
>  i=60
>  while :; do
> -  parted -s $scsi_dev mkpart p1 ext2 ${i}s 80000s || fail=1
> +  parted -s $scsi_dev mkpart p1 ext2 ${i}s 8000s || fail=1
>    wait_for_dev_to_appear_ $p1 || fail=1
>    parted -s $scsi_dev align-check min 1 > out 2>&1
>    result=$?
> @@ -46,6 +46,14 @@ while :; do
>    parted -s $scsi_dev rm 1
>    i=$(expr $i + 1)
>    test $i = 70 && break
> +
> +  # Wait until partition is gone
> +  t=10
> +  while [ -e $p1 ]; do
> +    sleep 1
> +    t=$(expr $t - 1)
> +    test $t = 0 && break
> +  done
>  done
>
>  Exit $fail

Thanks for the patch.
In testing it, I realized that we were not exercising the
>512-byte-sector paths, because the device we created would
always have sector size of 512.  I was thinking about that because
with your smaller (8MB) disk, the 8000s partition shouldn't fit
for sector sizes of 1024 and larger, yet the test was passing.

The first step is to use the test-specified sector size when
creating the scsi_debug device.  That's the added sector_size=$ss arg.
The next is to reduce further the partition size to 800.  Then,
even with 4Kb sectors, the partition still fits easily.

Finally, in the spirit of never waiting even a second, unless
absolutely necessary I've replaced your loop with a use of the
just written wait_for_dev_to_disappear_ function.
So, I'll merge the following changes into your patch and
push that after the helper-adding commit at the end.

I'll push after you ACK.

diff --git a/tests/t9030-align-check.sh b/tests/t9030-align-check.sh
index 805fa40..ac80137 100644
--- a/tests/t9030-align-check.sh
+++ b/tests/t9030-align-check.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# exercise the new align-check command
+# exercise the align-check command

 # Copyright (C) 2009-2011 Free Software Foundation, Inc.

@@ -17,6 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
+ss=$sector_size_

 require_root_
 require_scsi_debug_module_
@@ -25,7 +26,7 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
   skip_ 'this system lacks a new-enough libblkid'

 # create memory-backed device
-scsi_debug_setup_ physblk_exp=3 lowest_aligned=7 > dev-name ||
+scsi_debug_setup_ physblk_exp=3 lowest_aligned=7 sector_size=$ss > dev-name ||
   skip_ 'failed to create scsi_debug device'
 scsi_dev=$(cat dev-name)
 p1=${scsi_dev}1
@@ -34,7 +35,7 @@ parted -s $scsi_dev mklabel gpt || fail=1

 i=60
 while :; do
-  parted -s $scsi_dev mkpart p1 ext2 ${i}s 8000s || fail=1
+  parted -s $scsi_dev mkpart p1 ext2 ${i}s 800s || fail=1
   wait_for_dev_to_appear_ $p1 || fail=1
   parted -s $scsi_dev align-check min 1 > out 2>&1
   result=$?
@@ -47,13 +48,8 @@ while :; do
   i=$(expr $i + 1)
   test $i = 70 && break

-  # Wait until partition is gone
-  t=10
-  while [ -e $p1 ]; do
-    sleep 1
-    t=$(expr $t - 1)
-    test $t = 0 && break
-  done
+  # Wait up to 10s for the partition file to disappear.
+  wait_for_dev_to_disappear_ $p1 10 || { fail=1; warn $p1 failed to disappear; }
 done

 Exit $fail
--
1.7.8.rc0.35.gee6df



>From 204df0a55d3eff84fad861949fc4c87371a94c92 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Fri, 4 Nov 2011 21:28:51 +0100
Subject: [PATCH] tests: add a helper function

* tests/t-lib-helpers.sh (wait_for_dev_to_disappear_): New function.
---
 tests/t-lib-helpers.sh |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/tests/t-lib-helpers.sh b/tests/t-lib-helpers.sh
index bb41139..3c41e7b 100644
--- a/tests/t-lib-helpers.sh
+++ b/tests/t-lib-helpers.sh
@@ -378,6 +378,21 @@ wait_for_dev_to_appear_()
   return 1
 }

+# Like the above, but don't hard-code the max timeout.
+wait_for_dev_to_disappear_()
+{
+  local file=$1
+  local n_sec=$2
+  local i=0
+  local incr=1
+  while :; do
+    ls "$file" > /dev/null 2>&1 || return 0
+    sleep .1 2>/dev/null || { sleep 1; incr=10; }
+    i=$(expr $i + $incr); test $i -ge $($n_sec \* 10) && break
+  done
+  return 1
+}
+
 device_mapper_required_()
 {
   . "$abs_top_srcdir/tests/lvm-utils.sh" \
--
1.7.8.rc0.35.gee6df





Here's your merged commit, with adjusted log:

>From 021774cd30af313afdeb6ba7f71b479f5f2e52b1 Mon Sep 17 00:00:00 2001
From: "Brian C. Lane" <bcl at redhat.com>
Date: Fri, 21 Oct 2011 13:46:53 -0700
Subject: [PATCH] tests: t9030 wait for partition removal

The removal of the partition may take enough time that the next
mkpart will fail.  Wait for it to be removed.

Remove scsi_debug size and set the end of the partition to 800s so that
it will fit inside the default scsi_debug size of 8M, even when sector
size is 4Kb. This prevents failures on machines with limited memory.

* tests/t9030-align-check.sh: Wait for partition removal and use
a smaller disk.
---
 tests/t9030-align-check.sh |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/tests/t9030-align-check.sh b/tests/t9030-align-check.sh
index bc8ae09..ac80137 100644
--- a/tests/t9030-align-check.sh
+++ b/tests/t9030-align-check.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# exercise the new align-check command
+# exercise the align-check command

 # Copyright (C) 2009-2011 Free Software Foundation, Inc.

@@ -17,6 +17,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.

 . "${srcdir=.}/init.sh"; path_prepend_ ../parted
+ss=$sector_size_

 require_root_
 require_scsi_debug_module_
@@ -25,7 +26,7 @@ grep '^#define USE_BLKID 1' "$CONFIG_HEADER" > /dev/null ||
   skip_ 'this system lacks a new-enough libblkid'

 # create memory-backed device
-scsi_debug_setup_ dev_size_mb=550 physblk_exp=3 lowest_aligned=7 > dev-name ||
+scsi_debug_setup_ physblk_exp=3 lowest_aligned=7 sector_size=$ss > dev-name ||
   skip_ 'failed to create scsi_debug device'
 scsi_dev=$(cat dev-name)
 p1=${scsi_dev}1
@@ -34,7 +35,7 @@ parted -s $scsi_dev mklabel gpt || fail=1

 i=60
 while :; do
-  parted -s $scsi_dev mkpart p1 ext2 ${i}s 80000s || fail=1
+  parted -s $scsi_dev mkpart p1 ext2 ${i}s 800s || fail=1
   wait_for_dev_to_appear_ $p1 || fail=1
   parted -s $scsi_dev align-check min 1 > out 2>&1
   result=$?
@@ -46,6 +47,9 @@ while :; do
   parted -s $scsi_dev rm 1
   i=$(expr $i + 1)
   test $i = 70 && break
+
+  # Wait up to 10s for the partition file to disappear.
+  wait_for_dev_to_disappear_ $p1 10 || { fail=1; warn $p1 failed to disappear; }
 done

 Exit $fail
--
1.7.8.rc0.35.gee6df



More information about the parted-devel mailing list