]> www.infradead.org Git - users/hch/blktests.git/commitdiff
Support skipping tests from test{,_device}()
authorOmar Sandoval <osandov@fb.com>
Thu, 5 Mar 2020 01:21:51 +0000 (17:21 -0800)
committerOmar Sandoval <osandov@fb.com>
Sat, 7 Mar 2020 21:56:25 +0000 (13:56 -0800)
Most of the time, test requirements can be checked without much setup.
However, in some cases, it's not possible to know if the test can be run
until we're halfway through the test. Allow setting SKIP_REASON from the
test function. This should only be used as a last resort.

check
new
tests/meta/014 [new file with mode: 0755]
tests/meta/014.out [new file with mode: 0644]
tests/meta/015 [new file with mode: 0755]
tests/meta/015.out [new file with mode: 0644]

diff --git a/check b/check
index 0b6f2d687fa579bc3d23a7171310044553c8718b..398eca05e3a4ce33c3cdcb0a8e295903f7d52a0b 100755 (executable)
--- a/check
+++ b/check
@@ -364,7 +364,9 @@ _call_test() {
 
                _cleanup
 
-               if ! diff "tests/${TEST_NAME}.out" "${seqres}.out" >/dev/null; then
+               if [[ -v SKIP_REASON ]]; then
+                       TEST_RUN["status"]="not run"
+               elif ! diff "tests/${TEST_NAME}.out" "${seqres}.out" >/dev/null; then
                        mv "${seqres}.out" "${seqres}.out.bad"
                        TEST_RUN["status"]=fail
                        TEST_RUN["reason"]=output
diff --git a/new b/new
index 9a2d25523e09405eb2e22cdd57e18318cf02c96d..31973ed1add2dca8322fe9abf1dea24c5fea79e0 100755 (executable)
--- a/new
+++ b/new
@@ -187,6 +187,12 @@ DESCRIPTION=""
 # failure. You should prefer letting the test fail because of broken output
 # over, say, checking the exit status of every command you run.
 #
+# If the test cannot be run, this function may set the \$SKIP_REASON variable
+# and return. In that case, the return value and output are ignored, and the
+# test is considered skipped. This should only be done when the requirements
+# can only be detected with a non-trivial amount of setup; use
+# group_requires(), requires(), and/or device_requires() instead when possible.
+#
 # Various variables are defined for the test:
 #    - \$TEST_NAME -- the full name of the test.
 #    - \$TMPDIR -- a temporary directory deleted after the test is run.
diff --git a/tests/meta/014 b/tests/meta/014
new file mode 100755 (executable)
index 0000000..0db1fb8
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2020 Omar Sandoval
+#
+# Test skipping from test().
+
+. tests/meta/rc
+
+DESCRIPTION="skip in test()"
+
+test() {
+       SKIP_REASON="(╯°□°)╯︵ ┻━┻"
+}
diff --git a/tests/meta/014.out b/tests/meta/014.out
new file mode 100644 (file)
index 0000000..b6a7d3b
--- /dev/null
@@ -0,0 +1,2 @@
+Running meta/014
+Test complete
diff --git a/tests/meta/015 b/tests/meta/015
new file mode 100755 (executable)
index 0000000..3dc588b
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-3.0+
+# Copyright (C) 2020 Omar Sandoval
+#
+# Test skipping from test_device().
+
+. tests/meta/rc
+
+DESCRIPTION="skip in test_device()"
+
+test_device() {
+       SKIP_REASON="(╯°□°)╯︵ ┻━┻"
+}
diff --git a/tests/meta/015.out b/tests/meta/015.out
new file mode 100644 (file)
index 0000000..88092d0
--- /dev/null
@@ -0,0 +1,2 @@
+Running meta/015
+Test complete