提交 5e29a910 编写于 作者: M Michael Ellerman 提交者: Shuah Khan

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: NMichael Ellerman <mpe@ellerman.id.au>
Signed-off-by: NShuah Khan <shuahkh@osg.samsung.com>
上级 7fe5f1c1
...@@ -16,8 +16,9 @@ else ...@@ -16,8 +16,9 @@ else
echo "Not an x86 target, can't build breakpoints selftests" echo "Not an x86 target, can't build breakpoints selftests"
endif endif
run_tests: TEST_PROGS := breakpoint_test
@./breakpoint_test || echo "breakpoints selftests: [FAIL]"
include ../lib.mk
clean: clean:
rm -fr breakpoint_test rm -fr breakpoint_test
all: all:
run_tests: TEST_PROGS := on-off-test.sh
@/bin/bash ./on-off-test.sh || echo "cpu-hotplug selftests: [FAIL]"
include ../lib.mk
run_full_test: run_full_test:
@/bin/bash ./on-off-test.sh -a || echo "cpu-hotplug selftests: [FAIL]" @/bin/bash ./on-off-test.sh -a || echo "cpu-hotplug selftests: [FAIL]"
......
文件模式从 100644 更改为 100755
...@@ -5,8 +5,9 @@ test_objs = open-unlink create-read ...@@ -5,8 +5,9 @@ test_objs = open-unlink create-read
all: $(test_objs) all: $(test_objs)
run_tests: all TEST_PROGS := efivarfs.sh
@/bin/bash ./efivarfs.sh || echo "efivarfs selftests: [FAIL]"
include ../lib.mk
clean: clean:
rm -f $(test_objs) rm -f $(test_objs)
文件模式从 100644 更改为 100755
...@@ -18,8 +18,9 @@ execveat.denatured: execveat ...@@ -18,8 +18,9 @@ execveat.denatured: execveat
%: %.c %: %.c
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^
run_tests: all TEST_PROGS := execveat
./execveat
include ../lib.mk
clean: clean:
rm -rf $(BINARIES) $(DEPS) subdir.moved execveat.moved xxxxx* rm -rf $(BINARIES) $(DEPS) subdir.moved execveat.moved xxxxx*
...@@ -3,25 +3,9 @@ ...@@ -3,25 +3,9 @@
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests" # No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
all: all:
fw_filesystem: TEST_PROGS := fw_filesystem.sh fw_userhelper.sh
@if /bin/sh ./fw_filesystem.sh ; then \
echo "fw_filesystem: ok"; \
else \
echo "fw_filesystem: [FAIL]"; \
exit 1; \
fi
fw_userhelper: include ../lib.mk
@if /bin/sh ./fw_userhelper.sh ; then \
echo "fw_userhelper: ok"; \
else \
echo "fw_userhelper: [FAIL]"; \
exit 1; \
fi
run_tests: all fw_filesystem fw_userhelper
# Nothing to clean up. # Nothing to clean up.
clean: clean:
.PHONY: all clean run_tests fw_filesystem fw_userhelper
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
all: all:
run_tests: TEST_PROGS := ftracetest
@/bin/sh ./ftracetest || echo "ftrace selftests: [FAIL]"
include ../lib.mk
clean: clean:
rm -rf logs/* rm -rf logs/*
...@@ -18,8 +18,9 @@ else ...@@ -18,8 +18,9 @@ else
echo "Not an x86 target, can't build msgque selftest" echo "Not an x86 target, can't build msgque selftest"
endif endif
run_tests: all TEST_PROGS := msgque_test
./msgque_test
include ../lib.mk
clean: clean:
rm -fr ./msgque_test rm -fr ./msgque_test
...@@ -3,8 +3,9 @@ CFLAGS += -I../../../../usr/include/ ...@@ -3,8 +3,9 @@ CFLAGS += -I../../../../usr/include/
all: kcmp_test all: kcmp_test
run_tests: all TEST_PROGS := kcmp_test
@./kcmp_test || echo "kcmp_test: [FAIL]"
include ../lib.mk
clean: clean:
$(RM) kcmp_test kcmp-test-file $(RM) kcmp_test kcmp-test-file
define RUN_TESTS
@for TEST in $(TEST_PROGS); do \
(./$$TEST && echo "selftests: $$TEST [PASS]") || echo "selftests: $$TEST [FAIL]"; \
done;
endef
run_tests: all
$(RUN_TESTS)
.PHONY: run_tests all clean
...@@ -5,9 +5,9 @@ CFLAGS += -I../../../../include/ ...@@ -5,9 +5,9 @@ CFLAGS += -I../../../../include/
all: all:
gcc $(CFLAGS) memfd_test.c -o memfd_test gcc $(CFLAGS) memfd_test.c -o memfd_test
run_tests: all TEST_PROGS := memfd_test
gcc $(CFLAGS) memfd_test.c -o memfd_test
@./memfd_test || echo "memfd_test: [FAIL]" include ../lib.mk
build_fuse: build_fuse:
gcc $(CFLAGS) fuse_mnt.c `pkg-config fuse --cflags --libs` -o fuse_mnt gcc $(CFLAGS) fuse_mnt.c `pkg-config fuse --cflags --libs` -o fuse_mnt
......
all: all:
run_tests: include ../lib.mk
@/bin/bash ./on-off-test.sh -r 2 || echo "memory-hotplug selftests: [FAIL]"
override RUN_TESTS := ./on-off-test.sh -r 2 || echo "selftests: memory-hotplug [FAIL]"
run_full_test: run_full_test:
@/bin/bash ./on-off-test.sh || echo "memory-hotplug selftests: [FAIL]" @/bin/bash ./on-off-test.sh || echo "memory-hotplug selftests: [FAIL]"
......
文件模式从 100644 更改为 100755
...@@ -5,13 +5,9 @@ all: unprivileged-remount-test ...@@ -5,13 +5,9 @@ all: unprivileged-remount-test
unprivileged-remount-test: unprivileged-remount-test.c unprivileged-remount-test: unprivileged-remount-test.c
gcc -Wall -O2 unprivileged-remount-test.c -o unprivileged-remount-test gcc -Wall -O2 unprivileged-remount-test.c -o unprivileged-remount-test
# Allow specific tests to be selected. include ../lib.mk
test_unprivileged_remount: unprivileged-remount-test
@if [ -f /proc/self/uid_map ] ; then ./unprivileged-remount-test ; fi
run_tests: all test_unprivileged_remount override RUN_TESTS := if [ -f /proc/self/uid_map ] ; then ./unprivileged-remount-test ; fi
clean: clean:
rm -f unprivileged-remount-test rm -f unprivileged-remount-test
.PHONY: all test_unprivileged_remount
...@@ -2,9 +2,12 @@ all: ...@@ -2,9 +2,12 @@ all:
gcc -O2 mq_open_tests.c -o mq_open_tests -lrt gcc -O2 mq_open_tests.c -o mq_open_tests -lrt
gcc -O2 -o mq_perf_tests mq_perf_tests.c -lrt -lpthread -lpopt gcc -O2 -o mq_perf_tests mq_perf_tests.c -lrt -lpthread -lpopt
run_tests: include ../lib.mk
@./mq_open_tests /test1 || echo "mq_open_tests: [FAIL]"
@./mq_perf_tests || echo "mq_perf_tests: [FAIL]" override define RUN_TESTS
@./mq_open_tests /test1 || echo "selftests: mq_open_tests [FAIL]"
@./mq_perf_tests || echo "selftests: mq_perf_tests [FAIL]"
endef
clean: clean:
rm -f mq_open_tests mq_perf_tests rm -f mq_open_tests mq_perf_tests
...@@ -11,9 +11,9 @@ all: $(NET_PROGS) ...@@ -11,9 +11,9 @@ all: $(NET_PROGS)
%: %.c %: %.c
$(CC) $(CFLAGS) -o $@ $^ $(CC) $(CFLAGS) -o $@ $^
run_tests: all TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh
@/bin/sh ./run_netsocktests || echo "sockettests: [FAIL]"
@/bin/sh ./run_afpackettests || echo "afpackettests: [FAIL]" include ../lib.mk
./test_bpf.sh
clean: clean:
$(RM) $(NET_PROGS) $(RM) $(NET_PROGS)
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
...@@ -6,5 +6,6 @@ all: peeksiginfo ...@@ -6,5 +6,6 @@ all: peeksiginfo
clean: clean:
rm -f peeksiginfo rm -f peeksiginfo
run_tests: all TEST_PROGS := peeksiginfo
@./peeksiginfo || echo "peeksiginfo selftests: [FAIL]"
include ../lib.mk
...@@ -5,8 +5,9 @@ all: get_size ...@@ -5,8 +5,9 @@ all: get_size
get_size: get_size.c get_size: get_size.c
$(CC) -static -ffreestanding -nostartfiles -s $< -o $@ $(CC) -static -ffreestanding -nostartfiles -s $< -o $@
run_tests: all TEST_PROGS := get_size
./get_size
include ../lib.mk
clean: clean:
$(RM) get_size $(RM) get_size
...@@ -4,16 +4,9 @@ ...@@ -4,16 +4,9 @@
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests". # No binaries, but make sure arg-less "make" doesn't trigger "run_tests".
all: all:
# Allow specific tests to be selected. TEST_PROGS := run_numerictests run_stringtests
test_num:
@/bin/sh ./run_numerictests
test_string: include ../lib.mk
@/bin/sh ./run_stringtests
run_tests: all test_num test_string
# Nothing to clean up. # Nothing to clean up.
clean: clean:
.PHONY: all run_tests clean test_num test_string
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
...@@ -3,5 +3,6 @@ ...@@ -3,5 +3,6 @@
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests" # No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
all: all:
run_tests: all TEST_PROGS := test_user_copy.sh
./test_user_copy.sh
include ../lib.mk
...@@ -9,8 +9,9 @@ all: $(BINARIES) ...@@ -9,8 +9,9 @@ all: $(BINARIES)
%: %.c %: %.c
$(CC) $(CFLAGS) -o $@ $^ -lrt $(CC) $(CFLAGS) -o $@ $^ -lrt
run_tests: all TEST_PROGS := run_vmtests
@/bin/sh ./run_vmtests || (echo "vmtests: [FAIL]"; exit 1)
include ../lib.mk
clean: clean:
$(RM) $(BINARIES) $(RM) $(BINARIES)
文件模式从 100644 更改为 100755
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册