1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# 4# Run installed kselftest tests. 5# 6 7# Fallback to readlink if realpath is not available 8if which realpath > /dev/null; then 9 BASE_DIR=$(realpath $(dirname $0)) 10else 11 BASE_DIR=$(readlink -f $(dirname $0)) 12fi 13 14cd $BASE_DIR 15TESTS="$BASE_DIR"/kselftest-list.txt 16if [ ! -r "$TESTS" ] ; then 17 echo "$0: Could not find list of tests to run ($TESTS)" >&2 18 available="" 19else 20 available="$(cat "$TESTS")" 21fi 22 23. ./kselftest/runner.sh 24ROOT=$PWD 25 26usage() 27{ 28 cat <<EOF 29Usage: $0 [OPTIONS] 30 -s | --summary Print summary with detailed log in output.log (conflict with -p) 31 -p | --per-test-log Print test log in /tmp with each test name (conflict with -s) 32 -t | --test COLLECTION:TEST Run TEST from COLLECTION 33 -c | --collection COLLECTION Run all tests from COLLECTION 34 -l | --list List the available collection:test entries 35 -d | --dry-run Don't actually run any tests 36 -n | --netns Run each test in namespace 37 -h | --help Show this usage info 38 -o | --override-timeout Number of seconds after which we timeout 39EOF 40 exit $1 41} 42 43COLLECTIONS="" 44TESTS="" 45dryrun="" 46kselftest_override_timeout="" 47while true; do 48 case "$1" in 49 -s | --summary) 50 logfile="$BASE_DIR"/output.log 51 cat /dev/null > $logfile 52 shift ;; 53 -p | --per-test-log) 54 per_test_logging=1 55 shift ;; 56 -t | --test) 57 TESTS="$TESTS $2" 58 shift 2 ;; 59 -c | --collection) 60 COLLECTIONS="$COLLECTIONS $2" 61 shift 2 ;; 62 -l | --list) 63 echo "$available" 64 exit 0 ;; 65 -d | --dry-run) 66 dryrun="echo" 67 shift ;; 68 -n | --netns) 69 RUN_IN_NETNS=1 70 shift ;; 71 -o | --override-timeout) 72 kselftest_override_timeout="$2" 73 shift 2 ;; 74 -h | --help) 75 usage 0 ;; 76 "") 77 break ;; 78 *) 79 usage 1 ;; 80 esac 81done 82 83# Add all selected collections to the explicit test list. 84if [ -n "$COLLECTIONS" ]; then 85 for collection in $COLLECTIONS ; do 86 found="$(echo "$available" | grep "^$collection:")" 87 if [ -z "$found" ] ; then 88 echo "No such collection '$collection'" >&2 89 exit 1 90 fi 91 TESTS="$TESTS $found" 92 done 93fi 94# Replace available test list with explicitly selected tests. 95if [ -n "$TESTS" ]; then 96 valid="" 97 for test in $TESTS ; do 98 found="$(echo "$available" | grep "^${test}$")" 99 if [ -z "$found" ] ; then 100 echo "No such test '$test'" >&2 101 exit 1 102 fi 103 valid="$valid $found" 104 done 105 available="$(echo "$valid" | sed -e 's/ /\n/g')" 106fi 107 108collections=$(echo "$available" | cut -d: -f1 | sort | uniq) 109for collection in $collections ; do 110 [ -w /dev/kmsg ] && echo "kselftest: Running tests in $collection" >> /dev/kmsg 111 tests=$(echo "$available" | grep "^$collection:" | cut -d: -f2) 112 ($dryrun cd "$collection" && $dryrun run_many $tests) 113done 114