Merge tag 'usb-6.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[linux-block.git] / tools / testing / selftests / run_kselftest.sh
CommitLineData
f0f0a5df
KC
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# Run installed kselftest tests.
5#
6BASE_DIR=$(realpath $(dirname $0))
7cd $BASE_DIR
8TESTS="$BASE_DIR"/kselftest-list.txt
9if [ ! -r "$TESTS" ] ; then
10 echo "$0: Could not find list of tests to run ($TESTS)" >&2
5da19184
KC
11 available=""
12else
13 available="$(cat "$TESTS")"
f0f0a5df 14fi
f0f0a5df
KC
15
16. ./kselftest/runner.sh
17ROOT=$PWD
18
5da19184
KC
19usage()
20{
21 cat <<EOF
22Usage: $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
f6a01213 29 -o | --override-timeout Number of seconds after which we timeout
5da19184
KC
30EOF
31 exit $1
32}
33
34COLLECTIONS=""
35TESTS=""
36dryrun=""
f6a01213 37kselftest_override_timeout=""
5da19184
KC
38while true; do
39 case "$1" in
40 -s | --summary)
41 logfile="$BASE_DIR"/output.log
42 cat /dev/null > $logfile
43 shift ;;
44 -t | --test)
45 TESTS="$TESTS $2"
46 shift 2 ;;
47 -c | --collection)
48 COLLECTIONS="$COLLECTIONS $2"
49 shift 2 ;;
50 -l | --list)
51 echo "$available"
52 exit 0 ;;
93f20eff 53 -d | --dry-run)
5da19184
KC
54 dryrun="echo"
55 shift ;;
f6a01213
LC
56 -o | --override-timeout)
57 kselftest_override_timeout="$2"
58 shift 2 ;;
5da19184
KC
59 -h | --help)
60 usage 0 ;;
61 "")
62 break ;;
63 *)
64 usage 1 ;;
65 esac
66done
67
68# Add all selected collections to the explicit test list.
69if [ -n "$COLLECTIONS" ]; then
70 for collection in $COLLECTIONS ; do
71 found="$(echo "$available" | grep "^$collection:")"
72 if [ -z "$found" ] ; then
73 echo "No such collection '$collection'" >&2
74 exit 1
75 fi
76 TESTS="$TESTS $found"
77 done
78fi
79# Replace available test list with explicitly selected tests.
80if [ -n "$TESTS" ]; then
81 valid=""
82 for test in $TESTS ; do
83 found="$(echo "$available" | grep "^${test}$")"
84 if [ -z "$found" ] ; then
85 echo "No such test '$test'" >&2
86 exit 1
87 fi
88 valid="$valid $found"
89 done
90 available="$(echo "$valid" | sed -e 's/ /\n/g')"
f0f0a5df
KC
91fi
92
301d6815 93collections=$(echo "$available" | cut -d: -f1 | sort | uniq)
f0f0a5df
KC
94for collection in $collections ; do
95 [ -w /dev/kmsg ] && echo "kselftest: Running tests in $collection" >> /dev/kmsg
96 tests=$(echo "$available" | grep "^$collection:" | cut -d: -f2)
5da19184 97 ($dryrun cd "$collection" && $dryrun run_many $tests)
f0f0a5df 98done