Skip to content

Commit

Permalink
selftests: remove duplicated all and clean target
Browse files Browse the repository at this point in the history
Currently, kselftest use TEST_PROGS, TEST_PROGS_EXTENDED, TEST_FILES to
indicate the test program, extended test program and test files. It is
easy to understand the purpose of these files. But mix of compiled and
uncompiled files lead to duplicated "all" and "clean" targets.

In order to remove the duplicated targets, introduce TEST_GEN_PROGS,
TEST_GEN_PROGS_EXTENDED, TEST_GEN_FILES to indicate the compiled
objects.

Also, the later patch will make use of TEST_GEN_XXX to redirect these
files to output directory indicated by KBUILD_OUTPUT or O.

And add this changes to "Contributing new tests(details)" of
Documentation/kselftest.txt.

Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com>
  • Loading branch information
bamvor.zhangjian@huawei.com authored and Shuah Khan committed Jan 5, 2017
1 parent 7ce7d89 commit 88baa78
Show file tree
Hide file tree
Showing 37 changed files with 118 additions and 255 deletions.
12 changes: 12 additions & 0 deletions Documentation/kselftest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,15 @@ In general, the rules for selftests are

* Don't cause the top-level "make run_tests" to fail if your feature is
unconfigured.

Contributing new tests(details)
===============================

* Use TEST_GEN_XXX if such binaries or files are generated during
compiling.
TEST_PROGS, TEST_GEN_PROGS mean it is the excutable tested by
default.
TEST_PROGS_EXTENDED, TEST_GEN_PROGS_EXTENDED mean it is the
executable which is not tested by default.
TEST_FILES, TEST_GEN_FILES mean it is the file which is used by
test.
10 changes: 2 additions & 8 deletions tools/testing/selftests/bpf/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
CFLAGS += -Wall -O2 -I../../../../usr/include

test_objs = test_verifier test_maps test_lru_map
TEST_GEN_PROGS = test_verifier test_maps test_lru_map

TEST_PROGS := test_verifier test_maps test_lru_map test_kmod.sh
TEST_FILES := $(test_objs)

all: $(test_objs)
TEST_PROGS := test_kmod.sh

include ../lib.mk

clean:
$(RM) $(test_objs)
10 changes: 3 additions & 7 deletions tools/testing/selftests/breakpoints/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@ uname_M := $(shell uname -m 2>/dev/null || echo not)
ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/x86/ -e s/x86_64/x86/)

ifeq ($(ARCH),x86)
TEST_PROGS := breakpoint_test
TEST_GEN_PROGS := breakpoint_test
endif
ifeq ($(ARCH),aarch64)
TEST_PROGS := breakpoint_test_arm64
TEST_GEN_PROGS := breakpoint_test_arm64
endif

TEST_PROGS += step_after_suspend_test

all: $(TEST_PROGS)
TEST_GEN_PROGS += step_after_suspend_test

include ../lib.mk

clean:
rm -fr breakpoint_test breakpoint_test_arm64 step_after_suspend_test
11 changes: 2 additions & 9 deletions tools/testing/selftests/capabilities/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
TEST_FILES := validate_cap
TEST_PROGS := test_execve

BINARIES := $(TEST_FILES) $(TEST_PROGS)
TEST_GEN_FILES := validate_cap
TEST_GEN_PROGS := test_execve

CFLAGS += -O2 -g -std=gnu99 -Wall
LDLIBS += -lcap-ng -lrt -ldl

all: $(BINARIES)

clean:
$(RM) $(BINARIES)

include ../lib.mk

8 changes: 1 addition & 7 deletions tools/testing/selftests/efivarfs/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
CFLAGS = -Wall

test_objs = open-unlink create-read

all: $(test_objs)

TEST_GEN_FILES := open-unlink create-read
TEST_PROGS := efivarfs.sh
TEST_FILES := $(test_objs)

include ../lib.mk

clean:
rm -f $(test_objs)
10 changes: 4 additions & 6 deletions tools/testing/selftests/exec/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
CFLAGS = -Wall
BINARIES = execveat
DEPS = execveat.symlink execveat.denatured script subdir
all: $(BINARIES) $(DEPS)

subdir:
mkdir -p $@
Expand All @@ -17,11 +14,12 @@ execveat.denatured: execveat
%: %.c
$(CC) $(CFLAGS) -o $@ $^

TEST_PROGS := execveat
TEST_GEN_PROGS := execveat
TEST_GEN_FILES := execveat.symlink execveat.denatured script subdir
# Makefile is a run-time dependency, since it's accessed by the execveat test
TEST_FILES := $(DEPS) Makefile
TEST_FILES := Makefile

include ../lib.mk

clean:
rm -rf $(BINARIES) $(DEPS) subdir.moved execveat.moved xxxxx*
rm -rf $(TEST_GEN_PROGS) $(TEST_GEN_FILES) subdir.moved execveat.moved xxxxx*
12 changes: 3 additions & 9 deletions tools/testing/selftests/futex/functional/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES)
LDFLAGS := $(LDFLAGS) -pthread -lrt

HEADERS := ../include/futextest.h
TARGETS := \
TEST_GEN_FILES := \
futex_wait_timeout \
futex_wait_wouldblock \
futex_requeue_pi \
Expand All @@ -12,14 +12,8 @@ TARGETS := \
futex_wait_uninitialized_heap \
futex_wait_private_mapped_file

TEST_PROGS := $(TARGETS) run.sh

.PHONY: all clean
all: $(TARGETS)

$(TARGETS): $(HEADERS)
TEST_PROGS := run.sh

include ../../lib.mk

clean:
rm -f $(TARGETS)
$(TEST_GEN_FILES): $(HEADERS)
7 changes: 1 addition & 6 deletions tools/testing/selftests/ipc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,7 @@ endif

CFLAGS += -I../../../../usr/include/

all:
$(CC) $(CFLAGS) msgque.c -o msgque_test

TEST_PROGS := msgque_test
TEST_GEN_PROGS := msgque

include ../lib.mk

clean:
rm -fr ./msgque_test
6 changes: 2 additions & 4 deletions tools/testing/selftests/kcmp/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
CFLAGS += -I../../../../usr/include/

all: kcmp_test

TEST_PROGS := kcmp_test
TEST_GEN_PROGS := kcmp_test

include ../lib.mk

clean:
$(RM) kcmp_test kcmp-test-file
$(RM) $(TEST_GEN_PROGS) kcmp-test-file
18 changes: 14 additions & 4 deletions tools/testing/selftests/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
CC := $(CROSS_COMPILE)gcc

define RUN_TESTS
@for TEST in $(TEST_PROGS); do \
@for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
(./$$TEST && echo "selftests: $$TEST [PASS]") || echo "selftests: $$TEST [FAIL]"; \
done;
endef
Expand All @@ -14,8 +14,13 @@ run_tests: all
define INSTALL_RULE
@if [ "X$(TEST_PROGS)$(TEST_PROGS_EXTENDED)$(TEST_FILES)" != "X" ]; then \
mkdir -p ${INSTALL_PATH}; \
echo "rsync -a $(TEST_DIRS) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
rsync -a $(TEST_DIRS) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
echo "rsync -a $(TEST_DIRS) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/"; \
rsync -a $(TEST_DIRS) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES) $(INSTALL_PATH)/; \
fi
@if [ "X$(TEST_GEN_PROGS)$(TEST_GEN_PROGS_EXTENDED)$(TEST_GEN_FILES)" != "X" ]; then \
mkdir -p ${INSTALL_PATH}; \
echo "rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/"; \
rsync -a $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(INSTALL_PATH)/; \
fi
endef

Expand All @@ -27,12 +32,17 @@ else
endif

define EMIT_TESTS
@for TEST in $(TEST_PROGS); do \
@for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
echo "(./$$TEST && echo \"selftests: $$TEST [PASS]\") || echo \"selftests: $$TEST [FAIL]\""; \
done;
endef

emit_tests:
$(EMIT_TESTS)

all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)

clean:
$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)

.PHONY: run_tests all clean install emit_tests
6 changes: 1 addition & 5 deletions tools/testing/selftests/membarrier/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
CFLAGS += -g -I../../../../usr/include/

TEST_PROGS := membarrier_test

all: $(TEST_PROGS)
TEST_GEN_PROGS := membarrier_test

include ../lib.mk

clean:
$(RM) $(TEST_PROGS)
14 changes: 3 additions & 11 deletions tools/testing/selftests/memfd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,11 @@ CFLAGS += -I../../../../include/uapi/
CFLAGS += -I../../../../include/
CFLAGS += -I../../../../usr/include/

TEST_PROGS := memfd_test

all: $(TEST_PROGS)

include ../lib.mk

build_fuse: fuse_mnt fuse_test
TEST_PROGS := run_fuse_test.sh
TEST_GEN_FILES := memfd_test fuse_mnt fuse_test

fuse_mnt.o: CFLAGS += $(shell pkg-config fuse --cflags)
fuse_mnt: LDFLAGS += $(shell pkg-config fuse --libs)

run_fuse: build_fuse
@./run_fuse_test.sh || echo "fuse_test: [FAIL]"
include ../lib.mk

clean:
$(RM) memfd_test fuse_test
6 changes: 2 additions & 4 deletions tools/testing/selftests/mount/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Makefile for mount selftests.
CFLAGS = -Wall \
-O2
all: unprivileged-remount-test

unprivileged-remount-test: unprivileged-remount-test.c
$(CC) $(CFLAGS) unprivileged-remount-test.c -o unprivileged-remount-test

TEST_GEN_PROGS := unprivileged-remount-test

include ../lib.mk

TEST_PROGS := unprivileged-remount-test
override RUN_TESTS := if [ -f /proc/self/uid_map ] ; \
then \
./unprivileged-remount-test ; \
Expand All @@ -17,5 +17,3 @@ override RUN_TESTS := if [ -f /proc/self/uid_map ] ; \
fi
override EMIT_TESTS := echo "$(RUN_TESTS)"

clean:
rm -f unprivileged-remount-test
6 changes: 1 addition & 5 deletions tools/testing/selftests/mqueue/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
CFLAGS += -O2
LDLIBS = -lrt -lpthread -lpopt
TEST_PROGS := mq_open_tests mq_perf_tests

all: $(TEST_PROGS)
TEST_GEN_PROGS := mq_open_tests mq_perf_tests

include ../lib.mk

Expand All @@ -16,5 +14,3 @@ override define EMIT_TESTS
echo "./mq_perf_tests || echo \"selftests: mq_perf_tests [FAIL]\""
endef

clean:
rm -f mq_open_tests mq_perf_tests
13 changes: 4 additions & 9 deletions tools/testing/selftests/net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,15 @@
CFLAGS = -Wall -Wl,--no-as-needed -O2 -g
CFLAGS += -I../../../../usr/include/

NET_PROGS = socket
NET_PROGS += psock_fanout psock_tpacket
NET_PROGS += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
NET_PROGS += reuseport_dualstack

all: $(NET_PROGS)
reuseport_bpf_numa: LDFLAGS += -lnuma
%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^

TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh
TEST_FILES := $(NET_PROGS)
TEST_GEN_FILES = socket
TEST_GEN_FILES += psock_fanout psock_tpacket
TEST_GEN_FILES += reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
TEST_GEN_FILES += reuseport_dualstack

include ../lib.mk

clean:
$(RM) $(NET_PROGS)
9 changes: 1 addition & 8 deletions tools/testing/selftests/nsfs/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
TEST_PROGS := owner pidns
TEST_GEN_PROGS := owner pidns

CFLAGS := -Wall -Werror

all: owner pidns
owner: owner.c
pidns: pidns.c

clean:
$(RM) owner pidns

include ../lib.mk
9 changes: 2 additions & 7 deletions tools/testing/selftests/powerpc/alignment/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
TEST_PROGS := copy_unaligned copy_first_unaligned paste_unaligned paste_last_unaligned

all: $(TEST_PROGS)

$(TEST_PROGS): ../harness.c ../utils.c copy_paste_unaligned_common.c
TEST_GEN_PROGS := copy_unaligned copy_first_unaligned paste_unaligned paste_last_unaligned

include ../../lib.mk

clean:
rm -f $(TEST_PROGS)
$(TEST_GEN_PROGS): ../harness.c ../utils.c copy_paste_unaligned_common.c
11 changes: 3 additions & 8 deletions tools/testing/selftests/powerpc/benchmarks/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
TEST_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall
TEST_GEN_PROGS := gettimeofday context_switch mmap_bench futex_bench null_syscall

CFLAGS += -O2

all: $(TEST_PROGS)
$(TEST_GEN_PROGS): ../harness.c

$(TEST_PROGS): ../harness.c
include ../../lib.mk

context_switch: ../utils.c
context_switch: CFLAGS += -maltivec -mvsx -mabi=altivec
context_switch: LDLIBS += -lpthread

include ../../lib.mk

clean:
rm -f $(TEST_PROGS) *.o
9 changes: 2 additions & 7 deletions tools/testing/selftests/powerpc/context_switch/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
TEST_PROGS := cp_abort

all: $(TEST_PROGS)

$(TEST_PROGS): ../harness.c ../utils.c
TEST_GEN_PROGS := cp_abort

include ../../lib.mk

clean:
rm -f $(TEST_PROGS)
$(TEST_GEN_PROGS): ../harness.c ../utils.c
11 changes: 3 additions & 8 deletions tools/testing/selftests/powerpc/copyloops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,14 @@ CFLAGS += -maltivec
# Use our CFLAGS for the implicit .S rule
ASFLAGS = $(CFLAGS)

TEST_PROGS := copyuser_64 copyuser_power7 memcpy_64 memcpy_power7
TEST_GEN_PROGS := copyuser_64 copyuser_power7 memcpy_64 memcpy_power7
EXTRA_SOURCES := validate.c ../harness.c

all: $(TEST_PROGS)
include ../../lib.mk

copyuser_64: CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_base
copyuser_power7: CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_power7
memcpy_64: CPPFLAGS += -D COPY_LOOP=test_memcpy
memcpy_power7: CPPFLAGS += -D COPY_LOOP=test_memcpy_power7

$(TEST_PROGS): $(EXTRA_SOURCES)

include ../../lib.mk

clean:
rm -f $(TEST_PROGS) *.o
$(TEST_GEN_PROGS): $(EXTRA_SOURCES)
Loading

0 comments on commit 88baa78

Please sign in to comment.