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

selftests/kselftest/runner.sh: Pass optional command parameters in environment

Some testcases allow for optional commandline parameters but as of now
there is now way to provide such arguments to the runner script.

Add support to retrieve such optional command parameters fron environment
variables named so as to include the all-uppercase test executable name,
sanitized substituting any non-acceptable varname characters with "_",
following the pattern:

KSELFTEST_<UPPERCASE_SANITIZED_TEST_NAME>_ARGS="options"

Optional command parameters support is not available if 'tr' is not
installed on the test system.

Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

authored by

Cristian Marussi and committed by
Shuah Khan
e005ff01 cfb92440

+29 -1
+29 -1
tools/testing/selftests/kselftest/runner.sh
··· 18 18 exit 1 19 19 fi 20 20 21 + TR_CMD=$(command -v tr) 22 + 21 23 # If Perl is unavailable, we must fall back to line-at-a-time prefixing 22 24 # with sed instead of unbuffered output. 23 25 tap_prefix() ··· 51 49 52 50 # Reset any "settings"-file variables. 53 51 export kselftest_timeout="$kselftest_default_timeout" 52 + 53 + # Safe default if tr not available 54 + kselftest_cmd_args_ref="KSELFTEST_ARGS" 55 + 56 + # Optional arguments for this command, possibly defined as an 57 + # environment variable built using the test executable in all 58 + # uppercase and sanitized substituting non acceptable shell 59 + # variable name characters with "_" as in: 60 + # 61 + # KSELFTEST_<UPPERCASE_SANITIZED_TESTNAME>_ARGS="<options>" 62 + # 63 + # e.g. 64 + # 65 + # rtctest --> KSELFTEST_RTCTEST_ARGS="/dev/rtc1" 66 + # 67 + # cpu-on-off-test.sh --> KSELFTEST_CPU_ON_OFF_TEST_SH_ARGS="-a -p 10" 68 + # 69 + if [ -n "$TR_CMD" ]; then 70 + BASENAME_SANITIZED=$(echo "$BASENAME_TEST" | \ 71 + $TR_CMD -d "[:blank:][:cntrl:]" | \ 72 + $TR_CMD -c "[:alnum:]_" "_" | \ 73 + $TR_CMD [:lower:] [:upper:]) 74 + kselftest_cmd_args_ref="KSELFTEST_${BASENAME_SANITIZED}_ARGS" 75 + fi 76 + 54 77 # Load per-test-directory kselftest "settings" file. 55 78 settings="$BASE_DIR/$DIR/settings" 56 79 if [ -r "$settings" ] ; then ··· 96 69 echo "# Warning: file $TEST is missing!" 97 70 echo "not ok $test_num $TEST_HDR_MSG" 98 71 else 99 - cmd="./$BASENAME_TEST" 72 + eval kselftest_cmd_args="\$${kselftest_cmd_args_ref:-}" 73 + cmd="./$BASENAME_TEST $kselftest_cmd_args" 100 74 if [ ! -x "$TEST" ]; then 101 75 echo "# Warning: file $TEST is not executable" 102 76