Skip to content

Commit 5da1918

Browse files
keesshuahkh
authored andcommitted
selftests/run_kselftest.sh: Make each test individually selectable
Currently with run_kselftest.sh there is no way to choose which test we could run. All the tests listed in kselftest-list.txt are all run every time. This patch enhanced the run_kselftest.sh to make the test collections (or tests) individually selectable. e.g.: $ ./run_kselftest.sh -c seccomp -t timers:posix_timers -t timers:nanosleep Additionally adds a way to list all known tests with "-l", usage with "-h", and perform a dry run without running tests with "-n". Co-developed-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Signed-off-by: Kees Cook <keescook@chromium.org> Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent f0f0a5d commit 5da1918

1 file changed

Lines changed: 71 additions & 6 deletions

File tree

tools/testing/selftests/run_kselftest.sh

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,86 @@ cd $BASE_DIR
88
TESTS="$BASE_DIR"/kselftest-list.txt
99
if [ ! -r "$TESTS" ] ; then
1010
echo "$0: Could not find list of tests to run ($TESTS)" >&2
11-
exit 1
11+
available=""
12+
else
13+
available="$(cat "$TESTS")"
1214
fi
13-
available="$(cat "$TESTS")"
1415

1516
. ./kselftest/runner.sh
1617
ROOT=$PWD
1718

18-
if [ "$1" = "--summary" ] ; then
19-
logfile="$BASE_DIR"/output.log
20-
cat /dev/null > $logfile
19+
usage()
20+
{
21+
cat <<EOF
22+
Usage: $0 [OPTIONS]
23+
-s | --summary Print summary with detailed log in output.log
24+
-t | --test COLLECTION:TEST Run TEST from COLLECTION
25+
-c | --collection COLLECTION Run all tests from COLLECTION
26+
-l | --list List the available collection:test entries
27+
-d | --dry-run Don't actually run any tests
28+
-h | --help Show this usage info
29+
EOF
30+
exit $1
31+
}
32+
33+
COLLECTIONS=""
34+
TESTS=""
35+
dryrun=""
36+
while true; do
37+
case "$1" in
38+
-s | --summary)
39+
logfile="$BASE_DIR"/output.log
40+
cat /dev/null > $logfile
41+
shift ;;
42+
-t | --test)
43+
TESTS="$TESTS $2"
44+
shift 2 ;;
45+
-c | --collection)
46+
COLLECTIONS="$COLLECTIONS $2"
47+
shift 2 ;;
48+
-l | --list)
49+
echo "$available"
50+
exit 0 ;;
51+
-n | --dry-run)
52+
dryrun="echo"
53+
shift ;;
54+
-h | --help)
55+
usage 0 ;;
56+
"")
57+
break ;;
58+
*)
59+
usage 1 ;;
60+
esac
61+
done
62+
63+
# Add all selected collections to the explicit test list.
64+
if [ -n "$COLLECTIONS" ]; then
65+
for collection in $COLLECTIONS ; do
66+
found="$(echo "$available" | grep "^$collection:")"
67+
if [ -z "$found" ] ; then
68+
echo "No such collection '$collection'" >&2
69+
exit 1
70+
fi
71+
TESTS="$TESTS $found"
72+
done
73+
fi
74+
# Replace available test list with explicitly selected tests.
75+
if [ -n "$TESTS" ]; then
76+
valid=""
77+
for test in $TESTS ; do
78+
found="$(echo "$available" | grep "^${test}$")"
79+
if [ -z "$found" ] ; then
80+
echo "No such test '$test'" >&2
81+
exit 1
82+
fi
83+
valid="$valid $found"
84+
done
85+
available="$(echo "$valid" | sed -e 's/ /\n/g')"
2186
fi
2287

2388
collections=$(echo "$available" | cut -d: -f1 | uniq)
2489
for collection in $collections ; do
2590
[ -w /dev/kmsg ] && echo "kselftest: Running tests in $collection" >> /dev/kmsg
2691
tests=$(echo "$available" | grep "^$collection:" | cut -d: -f2)
27-
(cd "$collection" && run_many $tests)
92+
($dryrun cd "$collection" && $dryrun run_many $tests)
2893
done

0 commit comments

Comments
 (0)