Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'linux-kselftest-next-5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest

Pull kselftest updates from Shuah Khan:

- speed up headers_install done during selftest build

- add generic make nesting support

- add support to select individual tests:

Selftests build/install generates run_kselftest.sh script to run
selftests on a target system. Currently the script doesn't have
support for selecting individual tests. Add support for it.

With this enhancement, user can select test collections (or tests)
individually. 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".

* tag 'linux-kselftest-next-5.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest:
doc: dev-tools: kselftest.rst: Update examples and paths
selftests/run_kselftest.sh: Make each test individually selectable
selftests: Extract run_kselftest.sh and generate stand-alone test list
selftests: Add missing gitignore entries
selftests: more general make nesting support
selftests: use "$(MAKE)" instead of "make" for headers_install

+135 -41
+22 -13
Documentation/dev-tools/kselftest.rst
··· 125 125 Install selftests 126 126 ================= 127 127 128 - You can use the kselftest_install.sh tool to install selftests in the 129 - default location, which is tools/testing/selftests/kselftest, or in a 130 - user specified location. 128 + You can use the "install" target of "make" (which calls the `kselftest_install.sh` 129 + tool) to install selftests in the default location (`tools/testing/selftests/kselftest_install`), 130 + or in a user specified location via the `INSTALL_PATH` "make" variable. 131 131 132 132 To install selftests in default location:: 133 133 134 - $ cd tools/testing/selftests 135 - $ ./kselftest_install.sh 134 + $ make -C tools/testing/selftests install 136 135 137 136 To install selftests in a user specified location:: 138 137 139 - $ cd tools/testing/selftests 140 - $ ./kselftest_install.sh install_dir 138 + $ make -C tools/testing/selftests install INSTALL_PATH=/some/other/path 141 139 142 140 Running installed selftests 143 141 =========================== 144 142 145 - Kselftest install as well as the Kselftest tarball provide a script 146 - named "run_kselftest.sh" to run the tests. 143 + Found in the install directory, as well as in the Kselftest tarball, 144 + is a script named `run_kselftest.sh` to run the tests. 147 145 148 146 You can simply do the following to run the installed Kselftests. Please 149 147 note some tests will require root privileges:: 150 148 151 - $ cd kselftest 149 + $ cd kselftest_install 152 150 $ ./run_kselftest.sh 151 + 152 + To see the list of available tests, the `-l` option can be used:: 153 + 154 + $ ./run_kselftest.sh -l 155 + 156 + The `-c` option can be used to run all the tests from a test collection, or 157 + the `-t` option for specific single tests. Either can be used multiple times:: 158 + 159 + $ ./run_kselftest.sh -c bpf -c seccomp -t timers:posix_timers -t timer:nanosleep 160 + 161 + For other features see the script usage output, seen with the `-h` option. 153 162 154 163 Packaging selftests 155 164 =================== ··· 169 160 $ make -C tools/testing/selftests gen_tar 170 161 171 162 This generates a tarball in the `INSTALL_PATH/kselftest-packages` directory. By 172 - default, `.gz` format is used. The tar format can be overridden by specifying 173 - a `FORMAT` make variable. Any value recognized by `tar's auto-compress`_ option 174 - is supported, such as:: 163 + default, `.gz` format is used. The tar compression format can be overridden by 164 + specifying a `FORMAT` make variable. Any value recognized by `tar's auto-compress`_ 165 + option is supported, such as:: 175 166 176 167 $ make -C tools/testing/selftests gen_tar FORMAT=.xz 177 168
+11 -23
tools/testing/selftests/Makefile
··· 88 88 # of the targets gets built. 89 89 FORCE_TARGETS ?= 90 90 91 - # Clear LDFLAGS and MAKEFLAGS if called from main 92 - # Makefile to avoid test build failures when test 93 - # Makefile doesn't have explicit build rules. 94 - ifeq (1,$(MAKELEVEL)) 91 + # Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides 92 + # implicit rules to sub-test Makefiles which avoids build failures in test 93 + # Makefile that don't have explicit build rules. 94 + ifeq (,$(LINK.c)) 95 95 override LDFLAGS = 96 96 override MAKEFLAGS = 97 97 endif ··· 206 206 # Avoid changing the rest of the logic here and lib.mk. 207 207 INSTALL_PATH := $(KSFT_INSTALL_PATH) 208 208 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 209 + TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt 209 210 210 211 install: all 211 212 ifdef INSTALL_PATH ··· 215 214 install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ 216 215 install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ 217 216 install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ 217 + install -m 744 run_kselftest.sh $(INSTALL_PATH)/ 218 + rm -f $(TEST_LIST) 218 219 @ret=1; \ 219 220 for TARGET in $(TARGETS); do \ 220 221 BUILD_TARGET=$$BUILD/$$TARGET; \ ··· 225 222 ret=$$((ret * $$?)); \ 226 223 done; exit $$ret; 227 224 228 - @# Ask all targets to emit their test scripts 229 - echo "#!/bin/sh" > $(ALL_SCRIPT) 230 - echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT) 231 - echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT) 232 - echo ". ./kselftest/runner.sh" >> $(ALL_SCRIPT) 233 - echo "ROOT=\$$PWD" >> $(ALL_SCRIPT) 234 - echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT) 235 - echo " logfile=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT) 236 - echo " cat /dev/null > \$$logfile" >> $(ALL_SCRIPT) 237 - echo "fi" >> $(ALL_SCRIPT) 238 225 239 - @# While building run_kselftest.sh skip also non-existent TARGET dirs: 226 + @# Ask all targets to emit their test scripts 227 + @# While building kselftest-list.text skip also non-existent TARGET dirs: 240 228 @# they could be the result of a build failure and should NOT be 241 229 @# included in the generated runlist. 242 230 for TARGET in $(TARGETS); do \ 243 231 BUILD_TARGET=$$BUILD/$$TARGET; \ 244 232 [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ 245 - echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ 246 - echo "cd $$TARGET" >> $(ALL_SCRIPT); \ 247 - echo -n "run_many" >> $(ALL_SCRIPT); \ 248 233 echo -n "Emit Tests for $$TARGET\n"; \ 249 - $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ 250 - echo "" >> $(ALL_SCRIPT); \ 251 - echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ 234 + $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \ 235 + -C $$TARGET emit_tests >> $(TEST_LIST); \ 252 236 done; 253 - 254 - chmod u+x $(ALL_SCRIPT) 255 237 else 256 238 $(error Error: set INSTALL_PATH to use install) 257 239 endif
+2
tools/testing/selftests/firmware/.gitignore
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + fw_namespace
+4 -5
tools/testing/selftests/lib.mk
··· 47 47 khdr: 48 48 ifndef KSFT_KHDR_INSTALL_DONE 49 49 ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) 50 - make --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install 50 + $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install 51 51 else 52 - make --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \ 52 + $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$OUTPUT/usr \ 53 53 ARCH=$(ARCH) -C $(top_srcdir) headers_install 54 54 endif 55 55 endif ··· 107 107 emit_tests: 108 108 for TEST in $(TEST_GEN_PROGS) $(TEST_CUSTOM_PROGS) $(TEST_PROGS); do \ 109 109 BASENAME_TEST=`basename $$TEST`; \ 110 - echo " \\"; \ 111 - echo -n " \"$$BASENAME_TEST\""; \ 112 - done; \ 110 + echo "$(COLLECTION):$$BASENAME_TEST"; \ 111 + done 113 112 114 113 # define if isn't already. It is undefined in make O= case. 115 114 ifeq ($(RM),)
+2
tools/testing/selftests/netfilter/.gitignore
··· 1 + # SPDX-License-Identifier: GPL-2.0-only 2 + nf-queue
+1
tools/testing/selftests/ptrace/.gitignore
··· 1 1 # SPDX-License-Identifier: GPL-2.0-only 2 2 get_syscall_info 3 3 peeksiginfo 4 + vmaccess
+93
tools/testing/selftests/run_kselftest.sh
··· 1 + #!/bin/sh 2 + # SPDX-License-Identifier: GPL-2.0 3 + # 4 + # Run installed kselftest tests. 5 + # 6 + BASE_DIR=$(realpath $(dirname $0)) 7 + cd $BASE_DIR 8 + TESTS="$BASE_DIR"/kselftest-list.txt 9 + if [ ! -r "$TESTS" ] ; then 10 + echo "$0: Could not find list of tests to run ($TESTS)" >&2 11 + available="" 12 + else 13 + available="$(cat "$TESTS")" 14 + fi 15 + 16 + . ./kselftest/runner.sh 17 + ROOT=$PWD 18 + 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')" 86 + fi 87 + 88 + collections=$(echo "$available" | cut -d: -f1 | uniq) 89 + for collection in $collections ; do 90 + [ -w /dev/kmsg ] && echo "kselftest: Running tests in $collection" >> /dev/kmsg 91 + tests=$(echo "$available" | grep "^$collection:" | cut -d: -f2) 92 + ($dryrun cd "$collection" && $dryrun run_many $tests) 93 + done