Skip to content

Commit 303f8e2

Browse files
sj-awstorvalds
authored andcommitted
selftests/kselftest/runner/run_one(): allow running non-executable files
When running a test program, 'run_one()' checks if the program has the execution permission and fails if it doesn't. However, it's easy to mistakenly lose the permissions, as some common tools like 'diff' don't support the permission change well[1]. Compared to that, making mistakes in the test program's path would only rare, as those are explicitly listed in 'TEST_PROGS'. Therefore, it might make more sense to resolve the situation on our own and run the program. For this reason, this commit makes the test program runner function still print the warning message but to try parsing the interpreter of the program and to explicitly run it with the interpreter, in this case. [1] https://lore.kernel.org/mm-commits/[email protected]/ Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: SeongJae Park <[email protected]> Suggested-by: Greg Kroah-Hartman <[email protected]> Cc: Shuah Khan <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2128f4e commit 303f8e2

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

tools/testing/selftests/kselftest/runner.sh

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ tap_timeout()
3333
{
3434
# Make sure tests will time out if utility is available.
3535
if [ -x /usr/bin/timeout ] ; then
36-
/usr/bin/timeout --foreground "$kselftest_timeout" "$1"
36+
/usr/bin/timeout --foreground "$kselftest_timeout" $1
3737
else
38-
"$1"
38+
$1
3939
fi
4040
}
4141

@@ -65,17 +65,25 @@ run_one()
6565

6666
TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
6767
echo "# $TEST_HDR_MSG"
68-
if [ ! -x "$TEST" ]; then
69-
echo -n "# Warning: file $TEST is "
70-
if [ ! -e "$TEST" ]; then
71-
echo "missing!"
72-
else
73-
echo "not executable, correct this."
74-
fi
68+
if [ ! -e "$TEST" ]; then
69+
echo "# Warning: file $TEST is missing!"
7570
echo "not ok $test_num $TEST_HDR_MSG"
7671
else
72+
cmd="./$BASENAME_TEST"
73+
if [ ! -x "$TEST" ]; then
74+
echo "# Warning: file $TEST is not executable"
75+
76+
if [ $(head -n 1 "$TEST" | cut -c -2) = "#!" ]
77+
then
78+
interpreter=$(head -n 1 "$TEST" | cut -c 3-)
79+
cmd="$interpreter ./$BASENAME_TEST"
80+
else
81+
echo "not ok $test_num $TEST_HDR_MSG"
82+
return
83+
fi
84+
fi
7785
cd `dirname $TEST` > /dev/null
78-
((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) |
86+
((((( tap_timeout "$cmd" 2>&1; echo $? >&3) |
7987
tap_prefix >&4) 3>&1) |
8088
(read xs; exit $xs)) 4>>"$logfile" &&
8189
echo "ok $test_num $TEST_HDR_MSG") ||

0 commit comments

Comments
 (0)