]> www.infradead.org Git - users/sagi/blktests.git/commitdiff
Add support for test timeout
authorOmar Sandoval <osandov@fb.com>
Wed, 10 May 2017 17:33:02 +0000 (10:33 -0700)
committerOmar Sandoval <osandov@fb.com>
Wed, 10 May 2017 17:37:34 +0000 (10:37 -0700)
Add a configurable per-test timeout. By default, tests will run fully.
If $TIMEOUT is set, tests may restrict themselves to that timeout. So,
e.g., `TIMEOUT=30 ./check -g quick -g timed` can be used to do a quick
sanity test without doing the full run.

Signed-off-by: Omar Sandoval <osandov@fb.com>
Documentation/running-tests.md
common/fio
common/rc
new
tests/block/001
tests/block/003
tests/block/004
tests/block/005
tests/block/006
tests/block/007

index 1581ee4ce5fd7f3a929a527824ce68acc013dd97..c0bd9006fec36b179b068eb8ae5e760e95bac250 100644 (file)
@@ -18,6 +18,8 @@ Finally, there are a couple of basic groups:
   pass reliably.
 - The `quick` group is a subset of `auto` comprising tests that complete
   "quickly" (i.e., in ~30 seconds or less on reasonable hardware).
+- The `timed` group comprises tests that honor the configured test timeout (see
+  below)
 
 `./check` can execute individual tests or test groups, as well as exclude tests
 or test groups. See `./check -h`.
@@ -36,3 +38,14 @@ and will overwrite any data on these devices.
 ```sh
 TEST_DEVS=(/dev/nvme0n1 /dev/sdb)
 ```
+
+### Test Timeout
+
+Many tests can take a long time to run. By setting the `TIMEOUT` variable, you
+can limit the runtime of each test to a specific length (in seconds).
+
+```sh
+TIMEOUT=30
+```
+
+Note that only tests in the `timed` group honor the timeout.
index 1e9f5ece20a3346c7b36430db13ec9c76493ea8b..285b9be2053bf824f79bd922606f5d1734161d72 100644 (file)
@@ -150,13 +150,20 @@ FIO_TERSE_FIELDS=(
 # The possible fields are specified above. The optional $FIO_PERF_PREFIX
 # variable is prepended to the field name when reporting.
 _fio_perf() {
-       _fio_perf_run "$@"
+       _run_fio "$@"
        _fio_perf_report
 }
 
-_fio_perf_run() {
-       fio --output="$TMPDIR/fio_perf" --output-format=terse --terse-version=4 \
-               --group_reporting=1 "$@"
+# Wrapper around fio that handles:
+#     - Recording perf results
+#     - $TIMEOUT
+# You should usually use this instead of calling fio directly.
+_run_fio() {
+       local args=(--output="$TMPDIR/fio_perf" --output-format=terse --terse-version=4 --group_reporting=1)
+       if [[ -v TIMEOUT ]]; then
+               args+=(--runtime="$TIMEOUT")
+       fi
+       fio "${args[@]}" "$@"
 }
 
 _fio_perf_report() {
index 42f0f264736473964cf6a477d8fc7e6556f2b35b..b9cd5ba88e28b28281190b60023965714c1f2f5d 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -29,6 +29,15 @@ _error() {
        exit 1
 }
 
+# If a test runs multiple "subtests", then each subtest should typically run
+# for TIMEOUT / number of subtests.
+_divide_timeout() {
+       local num_tests="$1"
+       if [[ -v TIMEOUT ]]; then
+               ((TIMEOUT = (TIMEOUT + num_tests - 1) / num_tests))
+       fi
+}
+
 _have_root() {
        if [[ $EUID -ne 0 ]]; then
                SKIP_REASON="not running as root"
diff --git a/new b/new
index d7583b354514d483e77f43ceee737b5cdc2da9b7..93daa3825baf06ee74f68697c4a372302ca33f17 100755 (executable)
--- a/new
+++ b/new
@@ -156,9 +156,10 @@ cat << EOF > "tests/${test_name}"
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 # TODO: if this test shouldn't be run by default, remove the "auto" group. If
-# this test runs quickly, add it to the "quick" group. Add any other groups
-# describing what functionality this tests (e.g., "discard" or "hotplug"). Feel
-# free to create new groups if it makes sense.
+# this test runs quickly, add it to the "quick" group. If this test honors the
+# configured \$TIMEOUT, add it to the "timed" group.
+# Add any other groups describing what functionality this tests (e.g.,
+# "discard" or "hotplug"). Feel free to create new groups if it makes sense.
 TEST_GROUPS=($category auto)
 # TODO: fill in a very brief description of what this test does. The
 # description should complete the sentence "This test will...". For example,
index a3e8ae6ddc4c1998f0f64ede96e868b5a93d4e3c..66a0bc44d1f0aa2c2a7f7fa4e8a41030f4c971cc 100755 (executable)
@@ -21,7 +21,7 @@
 
 . common/scsi_debug
 
-TEST_GROUPS=(block auto hotplug)
+TEST_GROUPS=(block auto timed hotplug)
 DESCRIPTION="stress device hotplugging"
 
 prepare() {
@@ -47,19 +47,25 @@ stress_scsi_debug() {
                host="${target%%:*}"
                scan="${target#*:}"
                scan="${scan//:/ }"
-               for ((i = 0; i < 100; i++)); do
+               while [[ ! -e "$TMPDIR/stop" ]]; do
                        echo "${scan}" > "/sys/class/scsi_host/host${host}/scan"
                        echo 1 > "/sys/class/scsi_device/${target}/device/delete"
                done
                ) &
        done
+       sleep "$TIMEOUT"
+       touch "$TMPDIR/stop"
        wait
+       rm -f "$TMPDIR/stop"
        modprobe -r scsi_debug
 }
 
 test() {
        echo "Running ${TEST_NAME}"
 
+       : ${TIMEOUT:=30}
+       _divide_timeout 2
+
        echo "Stressing sd"
        stress_scsi_debug add_host=4 num_tgts=1 ptype=0
 
index 1bef25c477ec126301c2a79655e1ecb327940893..127a4021d1fb461b5489702b5cddb610a90d126e 100755 (executable)
@@ -17,7 +17,7 @@
 # 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_GROUPS=(block auto discard)
+TEST_GROUPS=(block auto timed discard)
 DESCRIPTION="run various discard sizes"
 
 prepare() {
index 51a7f4fac62021a1c287c17084e274f49c9e4768..f79dcb9b11b51b46859ec52d5e62231f11333fa3 100755 (executable)
@@ -17,7 +17,7 @@
 # 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_GROUPS=(block auto flush)
+TEST_GROUPS=(block auto timed flush)
 DESCRIPTION="run lots of flushes"
 
 prepare() {
index b4e82cf2f1acfe47b6e468ceb68d7d51e2234e48..751799ea4c7f69d0503b5d52f8fbb5f00b68d992 100755 (executable)
@@ -17,7 +17,7 @@
 # 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_GROUPS=(block auto sched)
+TEST_GROUPS=(block auto timed sched)
 DESCRIPTION="switch schedulers while doing IO"
 
 prepare() {
@@ -36,7 +36,7 @@ test_device() {
        fi
 
        # start fio job
-       _fio_perf_run --bs=4k --rw=randread --norandommap \
+       _run_fio --bs=4k --rw=randread --norandommap \
                --name=reads --filename="$TEST_DEV" --size="$size" \
                --numjobs=8 --direct=1 &
 
index 21577f8b2f48b334d20c7f52cfdf1f1c7eaac706..aae91c3e5268b7cf0a5c595b6c02940dc666fae6 100755 (executable)
@@ -20,7 +20,7 @@
 # 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_GROUPS=(block auto)
+TEST_GROUPS=(block auto timed)
 DESCRIPTION="run null-blk in blocking mode"
 
 prepare() {
@@ -30,19 +30,22 @@ prepare() {
 test() {
        echo "Running ${TEST_NAME}"
 
+       _divide_timeout 2
+       FIO_PERF_FIELDS=("read iops")
+
        modprobe -r null_blk
        if ! modprobe null_blk queue_mode=2 submit_queues=2 blocking=1; then
                return 1
        fi
 
        # run sync test
-       fio --bs=4k --ioengine=sync --rw=randread --norandommap --name=reads \
-               --filename=/dev/nullb0 --size=5g --direct=1 >> "$FULL"
+       _run_fio --bs=4k --ioengine=sync --rw=randread --norandommap --name=sync \
+               --filename=/dev/nullb0 --size=5g --direct=1
 
        # run async test
-       fio --bs=4k --ioengine=sync --rw=randread --norandommap --name=reads \
-               --ioengine=libaio --iodepth=8 --numjobs=4 \
-               --filename=/dev/nullb0 --size=5g --direct=1 >> "$FULL"
+       _run_fio --bs=4k --ioengine=libaio --iodepth=8 --numjobs=4 \
+               --rw=randread --norandommap --name=async \
+               --filename=/dev/nullb0 --size=5g --direct=1
 
        modprobe -r null_blk
 
index deeb55467efbc07207bb09f1f2425c66a9e2b5d7..daa861d7f5f7c397d1122042d7ec3acfe8533eff 100755 (executable)
@@ -19,7 +19,7 @@
 
 . common/iopoll
 
-TEST_GROUPS=(block auto poll)
+TEST_GROUPS=(block auto timed poll)
 DESCRIPTION="test classic and hybrid IO polling"
 
 prepare() {
@@ -45,6 +45,7 @@ run_fio_job() {
 test_device() {
        echo "Running ${TEST_NAME}"
 
+       _divide_timeout 4
        FIO_PERF_FIELDS=("read iops" "read lat mean" "system cpu")
 
        # no polling, run job