Skip to content

Commit

Permalink
selftests/kselftest/runner/run_one(): allow running non-executable files
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sj-aws authored and torvalds committed Nov 9, 2021
1 parent 2128f4e commit 303f8e2
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions tools/testing/selftests/kselftest/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ tap_timeout()
{
# Make sure tests will time out if utility is available.
if [ -x /usr/bin/timeout ] ; then
/usr/bin/timeout --foreground "$kselftest_timeout" "$1"
/usr/bin/timeout --foreground "$kselftest_timeout" $1
else
"$1"
$1
fi
}

Expand Down Expand Up @@ -65,17 +65,25 @@ run_one()

TEST_HDR_MSG="selftests: $DIR: $BASENAME_TEST"
echo "# $TEST_HDR_MSG"
if [ ! -x "$TEST" ]; then
echo -n "# Warning: file $TEST is "
if [ ! -e "$TEST" ]; then
echo "missing!"
else
echo "not executable, correct this."
fi
if [ ! -e "$TEST" ]; then
echo "# Warning: file $TEST is missing!"
echo "not ok $test_num $TEST_HDR_MSG"
else
cmd="./$BASENAME_TEST"
if [ ! -x "$TEST" ]; then
echo "# Warning: file $TEST is not executable"

if [ $(head -n 1 "$TEST" | cut -c -2) = "#!" ]
then
interpreter=$(head -n 1 "$TEST" | cut -c 3-)
cmd="$interpreter ./$BASENAME_TEST"
else
echo "not ok $test_num $TEST_HDR_MSG"
return
fi
fi
cd `dirname $TEST` > /dev/null
((((( tap_timeout ./$BASENAME_TEST 2>&1; echo $? >&3) |
((((( tap_timeout "$cmd" 2>&1; echo $? >&3) |
tap_prefix >&4) 3>&1) |
(read xs; exit $xs)) 4>>"$logfile" &&
echo "ok $test_num $TEST_HDR_MSG") ||
Expand Down

0 comments on commit 303f8e2

Please sign in to comment.