Index: tests/sys/geom/class/eli/attach_test.sh =================================================================== --- tests/sys/geom/class/eli/attach_test.sh +++ tests/sys/geom/class/eli/attach_test.sh @@ -22,17 +22,13 @@ # Be sure it doesn't detach on read. atf_check dd if=/dev/${md}.eli of=/dev/null status=none - sleep 1 - if [ ! -c /dev/${md}.eli ]; then + wait_for 5 0.1 "[ -c /dev/${md}.eli ]" || atf_fail "Detached on last close of a reader" - fi # It should detach on last close of a writer true > /dev/${md}.eli - sleep 1 - if [ -c /dev/${md}.eli ]; then + wait_for 5 0.1 "! [ -c /dev/${md}.eli ]" || atf_fail "Did not detach on last close of a writer" - fi } attach_d_cleanup() Index: tests/sys/geom/class/eli/detach_test.sh =================================================================== --- tests/sys/geom/class/eli/detach_test.sh +++ tests/sys/geom/class/eli/detach_test.sh @@ -22,19 +22,14 @@ # Be sure it doesn't detach before 'detach -l'. atf_check dd if=/dev/${md}.eli of=/dev/null status=none - sleep 1 - if [ ! -c /dev/${md}.eli ]; then + wait_for 5 0.1 "[ -c /dev/${md}.eli ]" || atf_fail "provider detached on last close without detach -l" - fi atf_check geli detach -l ${md} - if [ ! -c /dev/${md}.eli ]; then + wait_for 5 0.1 "[ -c /dev/${md}.eli ]" || atf_fail "Provider detached before last close" - fi atf_check dd if=/dev/${md}.eli of=/dev/null status=none - sleep 1 - if [ -c /dev/${md}.eli ]; then + wait_for 5 0.1 "! [ -c /dev/${md}.eli ]" || atf_fail "Provider did not detach on last close" - fi } detach_l_cleanup() { Index: tests/sys/geom/class/eli/kill_test.sh =================================================================== --- tests/sys/geom/class/eli/kill_test.sh +++ tests/sys/geom/class/eli/kill_test.sh @@ -24,11 +24,9 @@ # Kill attached provider. atf_check geli kill ${md} - sleep 1 # Provider should be automatically detached. - if [ -c /dev/${md}.eli ]; then + wait_for 5 0.1 "! [ -c /dev/${md}.eli ]" || atf_fail "Provider did not detach when killed" - fi # We cannot use keyfile1 anymore. atf_check -s not-exit:0 -e match:"Cannot read metadata" \ Index: tests/sys/geom/class/eli/onetime_test.sh =================================================================== --- tests/sys/geom/class/eli/onetime_test.sh +++ tests/sys/geom/class/eli/onetime_test.sh @@ -113,17 +113,13 @@ # Be sure it doesn't detach on read. atf_check dd if=/dev/${md}.eli of=/dev/null status=none - sleep 1 - if [ ! -c /dev/${md}.eli ]; then + wait_for 5 0.1 "[ -c /dev/${md}.eli ]" || atf_fail "Provider detached when a reader closed" - fi # It should detach when a writer closes true > /dev/${md}.eli - sleep 1 - if [ -c /dev/${md}.eli ]; then + wait_for 5 0.1 "! [ -c /dev/${md}.eli ]" || atf_fail "Provider didn't detach on last close of a writer" - fi } onetime_d_cleanup() { Index: tests/sys/geom/class/gate/ggate_test.sh =================================================================== --- tests/sys/geom/class/gate/ggate_test.sh +++ tests/sys/geom/class/gate/ggate_test.sh @@ -1,5 +1,8 @@ # $FreeBSD$ +ATF_TEST=true +. $(atf_get_srcdir)/../geom_subr.sh + PIDFILE=ggated.pid PLAINFILES=plainfiles PORT=33080 @@ -194,7 +197,7 @@ if [ -f "md.devs" ]; then while read test_md; do - mdconfig -d -u $test_md 2>/dev/null + wait_for 5 0.1 "mdconfig -d -u $test_md" done < md.devs rm md.devs fi @@ -219,7 +222,6 @@ { ggate_device=$1 - while [ ! -c $ggate_device ]; do - sleep 0.5 - done + wait_for 5 0.1 "[ -c $ggate_device ]" || + atf_fail "ggate device was never created" } Index: tests/sys/geom/class/geom_subr.sh =================================================================== --- tests/sys/geom/class/geom_subr.sh +++ tests/sys/geom/class/geom_subr.sh @@ -5,12 +5,7 @@ devwait() { - while :; do - if [ -c /dev/${class}/${name} ]; then - return - fi - sleep 0.2 - done + wait_for 1000 0.2 "[ -c /dev/${class}/${name} ]" } attach_md() @@ -73,6 +68,22 @@ echo "1..0 # SKIP $error_message" exit 0 fi +} + +# wait for a condition to be true +# wait_for
+wait_for() +{ + local timeout=$1 + local dt=$2 + local expression=$3 + local starttime=$(date '+%s') + local endtime=$((starttime + timeout)) + while ! eval "$expression"; do + curtime=$(date '+%s') + [ $curtime -gt $endtime ] && return 1 + sleep $dt + done } : ${ATF_TEST=false} Index: tests/sys/geom/class/mirror/conf.sh =================================================================== --- tests/sys/geom/class/mirror/conf.sh +++ tests/sys/geom/class/mirror/conf.sh @@ -14,9 +14,7 @@ syncwait() { - while $(gmirror status -s $name | grep -q SYNCHRONIZING); do - sleep 0.1; - done + wait_for 1000 0.1 "! gmirror status -s $name | grep -q SYNCHRONIZING" } consumerrefs() Index: tests/sys/geom/class/mirror/sync_error.sh =================================================================== --- tests/sys/geom/class/mirror/sync_error.sh +++ tests/sys/geom/class/mirror/sync_error.sh @@ -34,7 +34,6 @@ # a single active disk, gmirror has no choice but to fail the # synchronization and kick the new disk out of the mirror. atf_check gmirror insert $name $md2 - sleep 0.1 syncwait atf_check [ $(gmirror status -s $name | wc -l) -eq 1 ] atf_check -s exit:0 -o match:"DEGRADED $md1 \(ACTIVE\)" \