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

selftests: Introduce minimal shared logic for running tests

This adds a Make include file which most selftests can then include to
get the run_tests logic.

On its own this has the advantage of some reduction in repetition, and
also means the pass/fail message is defined in fewer places.

However the key advantage is it will allow us to implement install very
simply in a subsequent patch.

The default implementation just executes each program in $(TEST_PROGS).

We use a variable to hold the default implementation of $(RUN_TESTS)
because that gives us a clean way to override it if necessary, ie. using
override. The mount, memory-hotplug and mqueue tests use that to provide
a different implementation.

Tests are not run via /bin/bash, so if they are scripts they must be
executable, we add a+x to several.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>

authored by

Michael Ellerman and committed by
Shuah Khan
5e29a910 7fe5f1c1

+65 -67
+3 -2
tools/testing/selftests/breakpoints/Makefile
··· 16 16 echo "Not an x86 target, can't build breakpoints selftests" 17 17 endif 18 18 19 - run_tests: 20 - @./breakpoint_test || echo "breakpoints selftests: [FAIL]" 19 + TEST_PROGS := breakpoint_test 20 + 21 + include ../lib.mk 21 22 22 23 clean: 23 24 rm -fr breakpoint_test
+3 -2
tools/testing/selftests/cpu-hotplug/Makefile
··· 1 1 all: 2 2 3 - run_tests: 4 - @/bin/bash ./on-off-test.sh || echo "cpu-hotplug selftests: [FAIL]" 3 + TEST_PROGS := on-off-test.sh 4 + 5 + include ../lib.mk 5 6 6 7 run_full_test: 7 8 @/bin/bash ./on-off-test.sh -a || echo "cpu-hotplug selftests: [FAIL]"
tools/testing/selftests/cpu-hotplug/on-off-test.sh
+3 -2
tools/testing/selftests/efivarfs/Makefile
··· 5 5 6 6 all: $(test_objs) 7 7 8 - run_tests: all 9 - @/bin/bash ./efivarfs.sh || echo "efivarfs selftests: [FAIL]" 8 + TEST_PROGS := efivarfs.sh 9 + 10 + include ../lib.mk 10 11 11 12 clean: 12 13 rm -f $(test_objs)
tools/testing/selftests/efivarfs/efivarfs.sh
+3 -2
tools/testing/selftests/exec/Makefile
··· 18 18 %: %.c 19 19 $(CC) $(CFLAGS) -o $@ $^ 20 20 21 - run_tests: all 22 - ./execveat 21 + TEST_PROGS := execveat 22 + 23 + include ../lib.mk 23 24 24 25 clean: 25 26 rm -rf $(BINARIES) $(DEPS) subdir.moved execveat.moved xxxxx*
+2 -18
tools/testing/selftests/firmware/Makefile
··· 3 3 # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" 4 4 all: 5 5 6 - fw_filesystem: 7 - @if /bin/sh ./fw_filesystem.sh ; then \ 8 - echo "fw_filesystem: ok"; \ 9 - else \ 10 - echo "fw_filesystem: [FAIL]"; \ 11 - exit 1; \ 12 - fi 6 + TEST_PROGS := fw_filesystem.sh fw_userhelper.sh 13 7 14 - fw_userhelper: 15 - @if /bin/sh ./fw_userhelper.sh ; then \ 16 - echo "fw_userhelper: ok"; \ 17 - else \ 18 - echo "fw_userhelper: [FAIL]"; \ 19 - exit 1; \ 20 - fi 21 - 22 - run_tests: all fw_filesystem fw_userhelper 8 + include ../lib.mk 23 9 24 10 # Nothing to clean up. 25 11 clean: 26 - 27 - .PHONY: all clean run_tests fw_filesystem fw_userhelper
tools/testing/selftests/firmware/fw_filesystem.sh
tools/testing/selftests/firmware/fw_userhelper.sh
+3 -2
tools/testing/selftests/ftrace/Makefile
··· 1 1 all: 2 2 3 - run_tests: 4 - @/bin/sh ./ftracetest || echo "ftrace selftests: [FAIL]" 3 + TEST_PROGS := ftracetest 4 + 5 + include ../lib.mk 5 6 6 7 clean: 7 8 rm -rf logs/*
+3 -2
tools/testing/selftests/ipc/Makefile
··· 18 18 echo "Not an x86 target, can't build msgque selftest" 19 19 endif 20 20 21 - run_tests: all 22 - ./msgque_test 21 + TEST_PROGS := msgque_test 22 + 23 + include ../lib.mk 23 24 24 25 clean: 25 26 rm -fr ./msgque_test
+3 -2
tools/testing/selftests/kcmp/Makefile
··· 3 3 4 4 all: kcmp_test 5 5 6 - run_tests: all 7 - @./kcmp_test || echo "kcmp_test: [FAIL]" 6 + TEST_PROGS := kcmp_test 7 + 8 + include ../lib.mk 8 9 9 10 clean: 10 11 $(RM) kcmp_test kcmp-test-file
+10
tools/testing/selftests/lib.mk
··· 1 + define RUN_TESTS 2 + @for TEST in $(TEST_PROGS); do \ 3 + (./$$TEST && echo "selftests: $$TEST [PASS]") || echo "selftests: $$TEST [FAIL]"; \ 4 + done; 5 + endef 6 + 7 + run_tests: all 8 + $(RUN_TESTS) 9 + 10 + .PHONY: run_tests all clean
+3 -3
tools/testing/selftests/memfd/Makefile
··· 5 5 all: 6 6 gcc $(CFLAGS) memfd_test.c -o memfd_test 7 7 8 - run_tests: all 9 - gcc $(CFLAGS) memfd_test.c -o memfd_test 10 - @./memfd_test || echo "memfd_test: [FAIL]" 8 + TEST_PROGS := memfd_test 9 + 10 + include ../lib.mk 11 11 12 12 build_fuse: 13 13 gcc $(CFLAGS) fuse_mnt.c `pkg-config fuse --cflags --libs` -o fuse_mnt
+3 -2
tools/testing/selftests/memory-hotplug/Makefile
··· 1 1 all: 2 2 3 - run_tests: 4 - @/bin/bash ./on-off-test.sh -r 2 || echo "memory-hotplug selftests: [FAIL]" 3 + include ../lib.mk 4 + 5 + override RUN_TESTS := ./on-off-test.sh -r 2 || echo "selftests: memory-hotplug [FAIL]" 5 6 6 7 run_full_test: 7 8 @/bin/bash ./on-off-test.sh || echo "memory-hotplug selftests: [FAIL]"
tools/testing/selftests/memory-hotplug/on-off-test.sh
+2 -6
tools/testing/selftests/mount/Makefile
··· 5 5 unprivileged-remount-test: unprivileged-remount-test.c 6 6 gcc -Wall -O2 unprivileged-remount-test.c -o unprivileged-remount-test 7 7 8 - # Allow specific tests to be selected. 9 - test_unprivileged_remount: unprivileged-remount-test 10 - @if [ -f /proc/self/uid_map ] ; then ./unprivileged-remount-test ; fi 8 + include ../lib.mk 11 9 12 - run_tests: all test_unprivileged_remount 10 + override RUN_TESTS := if [ -f /proc/self/uid_map ] ; then ./unprivileged-remount-test ; fi 13 11 14 12 clean: 15 13 rm -f unprivileged-remount-test 16 - 17 - .PHONY: all test_unprivileged_remount
+6 -3
tools/testing/selftests/mqueue/Makefile
··· 2 2 gcc -O2 mq_open_tests.c -o mq_open_tests -lrt 3 3 gcc -O2 -o mq_perf_tests mq_perf_tests.c -lrt -lpthread -lpopt 4 4 5 - run_tests: 6 - @./mq_open_tests /test1 || echo "mq_open_tests: [FAIL]" 7 - @./mq_perf_tests || echo "mq_perf_tests: [FAIL]" 5 + include ../lib.mk 6 + 7 + override define RUN_TESTS 8 + @./mq_open_tests /test1 || echo "selftests: mq_open_tests [FAIL]" 9 + @./mq_perf_tests || echo "selftests: mq_perf_tests [FAIL]" 10 + endef 8 11 9 12 clean: 10 13 rm -f mq_open_tests mq_perf_tests
+4 -4
tools/testing/selftests/net/Makefile
··· 11 11 %: %.c 12 12 $(CC) $(CFLAGS) -o $@ $^ 13 13 14 - run_tests: all 15 - @/bin/sh ./run_netsocktests || echo "sockettests: [FAIL]" 16 - @/bin/sh ./run_afpackettests || echo "afpackettests: [FAIL]" 17 - ./test_bpf.sh 14 + TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh 15 + 16 + include ../lib.mk 17 + 18 18 clean: 19 19 $(RM) $(NET_PROGS)
tools/testing/selftests/net/run_afpackettests
tools/testing/selftests/net/run_netsocktests
+3 -2
tools/testing/selftests/ptrace/Makefile
··· 6 6 clean: 7 7 rm -f peeksiginfo 8 8 9 - run_tests: all 10 - @./peeksiginfo || echo "peeksiginfo selftests: [FAIL]" 9 + TEST_PROGS := peeksiginfo 10 + 11 + include ../lib.mk
+3 -2
tools/testing/selftests/size/Makefile
··· 5 5 get_size: get_size.c 6 6 $(CC) -static -ffreestanding -nostartfiles -s $< -o $@ 7 7 8 - run_tests: all 9 - ./get_size 8 + TEST_PROGS := get_size 9 + 10 + include ../lib.mk 10 11 11 12 clean: 12 13 $(RM) get_size
+2 -9
tools/testing/selftests/sysctl/Makefile
··· 4 4 # No binaries, but make sure arg-less "make" doesn't trigger "run_tests". 5 5 all: 6 6 7 - # Allow specific tests to be selected. 8 - test_num: 9 - @/bin/sh ./run_numerictests 7 + TEST_PROGS := run_numerictests run_stringtests 10 8 11 - test_string: 12 - @/bin/sh ./run_stringtests 13 - 14 - run_tests: all test_num test_string 9 + include ../lib.mk 15 10 16 11 # Nothing to clean up. 17 12 clean: 18 - 19 - .PHONY: all run_tests clean test_num test_string
tools/testing/selftests/sysctl/run_numerictests
tools/testing/selftests/sysctl/run_stringtests
+3 -2
tools/testing/selftests/user/Makefile
··· 3 3 # No binaries, but make sure arg-less "make" doesn't trigger "run_tests" 4 4 all: 5 5 6 - run_tests: all 7 - ./test_user_copy.sh 6 + TEST_PROGS := test_user_copy.sh 7 + 8 + include ../lib.mk
+3 -2
tools/testing/selftests/vm/Makefile
··· 9 9 %: %.c 10 10 $(CC) $(CFLAGS) -o $@ $^ -lrt 11 11 12 - run_tests: all 13 - @/bin/sh ./run_vmtests || (echo "vmtests: [FAIL]"; exit 1) 12 + TEST_PROGS := run_vmtests 13 + 14 + include ../lib.mk 14 15 15 16 clean: 16 17 $(RM) $(BINARIES)
tools/testing/selftests/vm/run_vmtests