Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: allow runners to override the timeout

The default timeout for selftests tests is 45 seconds. Although
we already have 13 settings for tests of about 96 sefltests which
use a timeout greater than this, we want to try to avoid encouraging
more tests to forcing a higher test timeout as selftests strives to
run all tests quickly. Selftests also uses the timeout as a non-fatal
error. Only tests runners which have control over a system would know
if to treat a timeout as fatal or not.

To help with all this:

o Enhance documentation to avoid future increases of insane timeouts
o Add the option to allow overriding the default timeout with test
runners with a command line option

Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Tested-by:Muhammad Usama Anjum <usama.anjum@collabora.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Luis Chamberlain and committed by
Shuah Khan
f6a01213 1977ecea

+37 -1
+22
Documentation/dev-tools/kselftest.rst
··· 168 168 169 169 For other features see the script usage output, seen with the `-h` option. 170 170 171 + Timeout for selftests 172 + ===================== 173 + 174 + Selftests are designed to be quick and so a default timeout is used of 45 175 + seconds for each test. Tests can override the default timeout by adding 176 + a settings file in their directory and set a timeout variable there to the 177 + configured a desired upper timeout for the test. Only a few tests override 178 + the timeout with a value higher than 45 seconds, selftests strives to keep 179 + it that way. Timeouts in selftests are not considered fatal because the 180 + system under which a test runs may change and this can also modify the 181 + expected time it takes to run a test. If you have control over the systems 182 + which will run the tests you can configure a test runner on those systems to 183 + use a greater or lower timeout on the command line as with the `-o` or 184 + the `--override-timeout` argument. For example to use 165 seconds instead 185 + one would use: 186 + 187 + $ ./run_kselftest.sh --override-timeout 165 188 + 189 + You can look at the TAP output to see if you ran into the timeout. Test 190 + runners which know a test must run under a specific time can then optionally 191 + treat these timeouts then as fatal. 192 + 171 193 Packaging selftests 172 194 =================== 173 195
+10 -1
tools/testing/selftests/kselftest/runner.sh
··· 8 8 export per_test_logging= 9 9 10 10 # Defaults for "settings" file fields: 11 - # "timeout" how many seconds to let each test run before failing. 11 + # "timeout" how many seconds to let each test run before running 12 + # over our soft timeout limit. 12 13 export kselftest_default_timeout=45 13 14 14 15 # There isn't a shell-agnostic way to find the path of a sourced file, ··· 89 88 value=$(echo "$line" | cut -d= -f2-) 90 89 eval "kselftest_$field"="$value" 91 90 done < "$settings" 91 + fi 92 + 93 + # Command line timeout overrides the settings file 94 + if [ -n "$kselftest_override_timeout" ]; then 95 + kselftest_timeout="$kselftest_override_timeout" 96 + echo "# overriding timeout to $kselftest_timeout" >> "$logfile" 97 + else 98 + echo "# timeout set to $kselftest_timeout" >> "$logfile" 92 99 fi 93 100 94 101 TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
+5
tools/testing/selftests/run_kselftest.sh
··· 26 26 -l | --list List the available collection:test entries 27 27 -d | --dry-run Don't actually run any tests 28 28 -h | --help Show this usage info 29 + -o | --override-timeout Number of seconds after which we timeout 29 30 EOF 30 31 exit $1 31 32 } ··· 34 33 COLLECTIONS="" 35 34 TESTS="" 36 35 dryrun="" 36 + kselftest_override_timeout="" 37 37 while true; do 38 38 case "$1" in 39 39 -s | --summary) ··· 53 51 -d | --dry-run) 54 52 dryrun="echo" 55 53 shift ;; 54 + -o | --override-timeout) 55 + kselftest_override_timeout="$2" 56 + shift 2 ;; 56 57 -h | --help) 57 58 usage 0 ;; 58 59 "")