summaryrefslogtreecommitdiff
path: root/tests/t9010-big-sector.sh
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2009-11-02 11:35:02 +0100
committerJim Meyering <meyering@redhat.com>2009-11-02 11:37:45 +0100
commitcf6ec477c6808bf90e0c05ddd0c581ff6cb0de6f (patch)
tree951049f4437b3e8ae8a62ba486e92957b9f2941e /tests/t9010-big-sector.sh
parentb324a2b078f6e23f80fab78cc72a2ac19eef7e21 (diff)
downloadparted-cf6ec477c6808bf90e0c05ddd0c581ff6cb0de6f.tar.gz
tests: move scsi_debug framework into shared script
* tests/t-local.sh (-scsi_debug_cleanup_, wait_for_dev_to_appear_): (print_sd_names_, scsi_debug_setup_): New functions, factored out of ... * tests/t9010-big-sector.sh: ...this file.
Diffstat (limited to 'tests/t9010-big-sector.sh')
-rwxr-xr-xtests/t9010-big-sector.sh68
1 files changed, 3 insertions, 65 deletions
diff --git a/tests/t9010-big-sector.sh b/tests/t9010-big-sector.sh
index 180b07b..473bbf3 100755
--- a/tests/t9010-big-sector.sh
+++ b/tests/t9010-big-sector.sh
@@ -27,72 +27,10 @@ fi
require_root_
scsi_dev=
-cleanup_() { scsi_debug_cleanup_; }
-
-scsi_debug_cleanup_() {
- # Remove the module only if this script added it.
- test -z "$scsi_dev" && return
-
- # We have to insist. Otherwise, a single rmmod usually fails to remove it,
- # due either to "Resource temporarily unavailable" or to
- # "Module scsi_debug is in use".
- for i in 1 2 3; do rmmod scsi_debug && break; sleep .2 || sleep 1; done
-}
-
-# Helper function: wait 2s (via .1s increments) for FILE to appear.
-# Usage: wait_for_dev_to_appear_ /dev/sdg
-# Return 0 upon success, 1 upon failure.
-wait_for_dev_to_appear_()
+cleanup_()
{
- local file=$1
- 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 = 20 && break
- done
- return 1
-}
-
-print_sd_names_() { (cd /sys/block && printf '%s\n' sd*); }
-
-# Create a device using the scsi_debug module with the options passed to
-# this function as arguments. Upon success, print the name of the new device.
-scsi_debug_setup_()
-{
- # It is not trivial to determine the name of the device we're creating.
- # Record the names of all /sys/block/sd* devices *before* probing:
- print_sd_names_ > before
- modprobe scsi_debug "$@" || { rm -f before; return 1; }
-
- # Wait up to 2s (via .1s increments) for the list of devices to change.
- # Sleeping for a fraction of a second requires GNU sleep, so fall
- # back on sleeping 2x1s if that fails.
- # FIXME-portability: using "cmp - ..." probably requires GNU cmp.
- local incr=1
- local i=0
- while print_sd_names_ | cmp -s - before; do
- sleep .1 2>/dev/null || { sleep 1; incr=10; }
- i=$(expr $i + $incr); test $i = 20 && break
- done
-
- # Record the names of all /sys/block/sd* devices *after* probe+wait.
- print_sd_names_ > after
-
- # Determine which device names (if any) are new.
- # There could be more than one new device, and there have been a removal.
- local new_dev=$(comm -13 before after)
- rm -f before after
- case $new_dev in
- sd[a-z]) ;;
- sd[a-z][a-z]) ;;
- *) return 1 ;;
- esac
- local t=/dev/$new_dev
- wait_for_dev_to_appear_ $t
- echo $t
- return 0
+ # Remove the module only if this script added it.
+ test -n "$scsi_dev" && scsi_debug_cleanup_
}
# check for scsi_debug module