Skip to content

Commit

Permalink
selftests: enable O and KBUILD_OUTPUT
Browse files Browse the repository at this point in the history
Enable O and KBUILD_OUTPUT for kselftest. User could compile kselftest
to another directory by passing O or KBUILD_OUTPUT. And O is high
priority than KBUILD_OUTPUT.

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 80d443e commit a8ba798
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 75 deletions.
36 changes: 27 additions & 9 deletions tools/testing/selftests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,44 @@ override LDFLAGS =
override MAKEFLAGS =
endif

BUILD := $(O)
ifndef BUILD
BUILD := $(KBUILD_OUTPUT)
endif
ifndef BUILD
BUILD := $(shell pwd)
endif

export BUILD
all:
for TARGET in $(TARGETS); do \
make -C $$TARGET; \
for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \
mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
done;

run_tests: all
for TARGET in $(TARGETS); do \
make -C $$TARGET run_tests; \
BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
done;

hotplug:
for TARGET in $(TARGETS_HOTPLUG); do \
make -C $$TARGET; \
BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
done;

run_hotplug: hotplug
for TARGET in $(TARGETS_HOTPLUG); do \
make -C $$TARGET run_full_test; \
BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
done;

clean_hotplug:
for TARGET in $(TARGETS_HOTPLUG); do \
make -C $$TARGET clean; \
BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
done;

run_pstore_crash:
Expand All @@ -86,7 +101,8 @@ ifdef INSTALL_PATH
@# Ask all targets to install their files
mkdir -p $(INSTALL_PATH)
for TARGET in $(TARGETS); do \
make -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \
done;

@# Ask all targets to emit their test scripts
Expand All @@ -95,10 +111,11 @@ ifdef INSTALL_PATH
echo "ROOT=\$$PWD" >> $(ALL_SCRIPT)

for TARGET in $(TARGETS); do \
BUILD_TARGET=$$BUILD/$$TARGET; \
echo "echo ; echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \
echo "echo ========================================" >> $(ALL_SCRIPT); \
echo "cd $$TARGET" >> $(ALL_SCRIPT); \
make -s --no-print-directory -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \
echo "cd \$$ROOT" >> $(ALL_SCRIPT); \
done;

Expand All @@ -109,7 +126,8 @@ endif

clean:
for TARGET in $(TARGETS); do \
make -C $$TARGET clean; \
BUILD_TARGET=$$BUILD/$$TARGET; \
make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
done;

.PHONY: install
13 changes: 7 additions & 6 deletions tools/testing/selftests/exec/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ 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 := Makefile

EXTRA_CLEAN := subdir.moved execveat.moved xxxxx*
EXTRA_CLEAN := $(OUTPUT)/subdir.moved $(OUTPUT)/execveat.moved $(OUTPUT)/xxxxx*

include ../lib.mk

subdir:
$(OUTPUT)/subdir:
mkdir -p $@
script:
$(OUTPUT)/script:
echo '#!/bin/sh' > $@
echo 'exit $$*' >> $@
chmod +x $@
execveat.symlink: execveat
ln -s -f $< $@
execveat.denatured: execveat
$(OUTPUT)/execveat.symlink: $(OUTPUT)/execveat
cd $(OUTPUT) && ln -s -f $(shell basename $<) $(shell basename $@)
$(OUTPUT)/execveat.denatured: $(OUTPUT)/execveat
cp $< $@
chmod -x $@

2 changes: 1 addition & 1 deletion tools/testing/selftests/ftrace/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ all:

TEST_PROGS := ftracetest
TEST_FILES := test.d
EXTRA_CLEAN := logs/*
EXTRA_CLEAN := $(OUTPUT)/logs/*

include ../lib.mk
21 changes: 16 additions & 5 deletions tools/testing/selftests/futex/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@ SUBDIRS := functional
TEST_PROGS := run.sh

.PHONY: all clean
all:
for DIR in $(SUBDIRS); do $(MAKE) -C $$DIR $@ ; done

include ../lib.mk

all:
for DIR in $(SUBDIRS); do \
BUILD_TARGET=$$OUTPUT/$$DIR; \
mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
done

override define RUN_TESTS
./run.sh
@if [ `dirname $(OUTPUT)` = $(PWD) ]; then ./run.sh; fi
endef

override define INSTALL_RULE
mkdir -p $(INSTALL_PATH)
install -t $(INSTALL_PATH) $(TEST_PROGS) $(TEST_PROGS_EXTENDED) $(TEST_FILES)

@for SUBDIR in $(SUBDIRS); do \
$(MAKE) -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
BUILD_TARGET=$$OUTPUT/$$SUBDIR; \
mkdir $$BUILD_TARGET -p; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$SUBDIR INSTALL_PATH=$(INSTALL_PATH)/$$SUBDIR install; \
done;
endef

Expand All @@ -26,4 +33,8 @@ override define EMIT_TESTS
endef

clean:
for DIR in $(SUBDIRS); do $(MAKE) -C $$DIR $@ ; done
for DIR in $(SUBDIRS); do \
BUILD_TARGET=$$OUTPUT/$$DIR; \
mkdir $$BUILD_TARGET -p; \
make OUTPUT=$$BUILD_TARGET -C $$DIR $@;\
done
2 changes: 1 addition & 1 deletion tools/testing/selftests/kcmp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CFLAGS += -I../../../../usr/include/

TEST_GEN_PROGS := kcmp_test

EXTRA_CLEAN := kcmp-test-file
EXTRA_CLEAN := $(OUTPUT)/kcmp-test-file

include ../lib.mk

19 changes: 15 additions & 4 deletions tools/testing/selftests/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ CC := $(CROSS_COMPILE)gcc

define RUN_TESTS
@for TEST in $(TEST_GEN_PROGS) $(TEST_PROGS); do \
(./$$TEST && echo "selftests: $$TEST [PASS]") || echo "selftests: $$TEST [FAIL]"; \
BASENAME_TEST=`basename $$TEST`; \
cd `dirname $$TEST`; (./$$BASENAME_TEST && echo "selftests: $$BASENAME_TEST [PASS]") || echo "selftests: $$BASENAME_TEST [FAIL]"; cd -;\
done;
endef

Expand Down Expand Up @@ -33,19 +34,29 @@ endif

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

emit_tests:
$(EMIT_TESTS)

TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))

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

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

%: %.c
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) -o $@ $^
$(OUTPUT)/%:%.c
$(CC) $(CFLAGS) $(LDFLAGS) $(LDLIBS) $< -o $@

$(OUTPUT)/%.o:%.S
$(CC) $(ASFLAGS) -c $< -o $@

$(OUTPUT)/%:%.S
$(CC) $(ASFLAGS) $< -o $@

.PHONY: run_tests all clean install emit_tests
15 changes: 9 additions & 6 deletions tools/testing/selftests/powerpc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,35 @@ endif
all: $(SUB_DIRS)

$(SUB_DIRS):
$(MAKE) -k -C $@ all
BUILD_TARGET=$$OUTPUT/$@; mkdir -p $$BUILD_TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -k -C $@ all

include ../lib.mk

override define RUN_TESTS
@for TARGET in $(SUB_DIRS); do \
$(MAKE) -C $$TARGET run_tests; \
BUILD_TARGET=$$OUTPUT/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
done;
endef

override define INSTALL_RULE
@for TARGET in $(SUB_DIRS); do \
$(MAKE) -C $$TARGET install; \
BUILD_TARGET=$$OUTPUT/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET install;\
done;
endef

override define EMIT_TESTS
@for TARGET in $(SUB_DIRS); do \
$(MAKE) -s -C $$TARGET emit_tests; \
BUILD_TARGET=$$OUTPUT/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -s -C $$TARGET emit_tests;\
done;
endef

clean:
@for TARGET in $(SUB_DIRS); do \
$(MAKE) -C $$TARGET clean; \
done;
BUILD_TARGET=$$OUTPUT/$$TARGET; \
$(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ done;
rm -f tags

tags:
Expand Down
6 changes: 3 additions & 3 deletions tools/testing/selftests/powerpc/benchmarks/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ $(TEST_GEN_PROGS): ../harness.c

include ../../lib.mk

context_switch: ../utils.c
context_switch: CFLAGS += -maltivec -mvsx -mabi=altivec
context_switch: LDLIBS += -lpthread
$(OUTPUT)/context_switch: ../utils.c
$(OUTPUT)/context_switch: CFLAGS += -maltivec -mvsx -mabi=altivec
$(OUTPUT)/context_switch: LDLIBS += -lpthread
8 changes: 4 additions & 4 deletions tools/testing/selftests/powerpc/copyloops/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ EXTRA_SOURCES := validate.c ../harness.c

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
$(OUTPUT)/copyuser_64: CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_base
$(OUTPUT)/copyuser_power7: CPPFLAGS += -D COPY_LOOP=test___copy_tofrom_user_power7
$(OUTPUT)/memcpy_64: CPPFLAGS += -D COPY_LOOP=test_memcpy
$(OUTPUT)/memcpy_power7: CPPFLAGS += -D COPY_LOOP=test_memcpy_power7

$(TEST_GEN_PROGS): $(EXTRA_SOURCES)
2 changes: 1 addition & 1 deletion tools/testing/selftests/powerpc/dscr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ TEST_GEN_PROGS := dscr_default_test dscr_explicit_test dscr_user_test \

include ../../lib.mk

dscr_default_test: LDLIBS += -lpthread
$(OUTPUT)/dscr_default_test: LDLIBS += -lpthread

$(TEST_GEN_PROGS): ../harness.c
12 changes: 6 additions & 6 deletions tools/testing/selftests/powerpc/math/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ include ../../lib.mk
$(TEST_GEN_PROGS): ../harness.c
$(TEST_GEN_PROGS): CFLAGS += -O2 -g -pthread -m64 -maltivec

fpu_syscall: fpu_asm.S
fpu_preempt: fpu_asm.S
fpu_signal: fpu_asm.S
$(OUTPUT)/pu_syscall: fpu_asm.S
$(OUTPUT)/pu_preempt: fpu_asm.S
$(OUTPUT)/pu_signal: fpu_asm.S

vmx_syscall: vmx_asm.S
vmx_preempt: vmx_asm.S
vmx_signal: vmx_asm.S
$(OUTPUT)/mx_syscall: vmx_asm.S
$(OUTPUT)/mx_preempt: vmx_asm.S
$(OUTPUT)/mx_signal: vmx_asm.S

vsx_preempt: CFLAGS += -mvsx
vsx_preempt: vsx_asm.S
6 changes: 3 additions & 3 deletions tools/testing/selftests/powerpc/mm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ include ../../lib.mk

$(TEST_GEN_PROGS): ../harness.c

prot_sao: ../utils.c
$(OUTPUT)/prot_sao: ../utils.c

tempfile:
dd if=/dev/zero of=tempfile bs=64k count=1
$(OUTPUT)/tempfile:
dd if=/dev/zero of=$@ bs=64k count=1

16 changes: 8 additions & 8 deletions tools/testing/selftests/powerpc/pmu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,34 @@ all: $(TEST_GEN_PROGS) ebb
$(TEST_GEN_PROGS): $(EXTRA_SOURCES)

# loop.S can only be built 64-bit
count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES)
$(OUTPUT)/count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES)
$(CC) $(CFLAGS) -m64 -o $@ $^

per_event_excludes: ../utils.c
$(OUTPUT)/per_event_excludes: ../utils.c

DEFAULT_RUN_TESTS := $(RUN_TESTS)
override define RUN_TESTS
$(DEFAULT_RUN_TESTS)
$(MAKE) -C ebb run_tests
TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests
endef

DEFAULT_EMIT_TESTS := $(EMIT_TESTS)
override define EMIT_TESTS
$(DEFAULT_EMIT_TESTS)
$(MAKE) -s -C ebb emit_tests
TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -s -C $$TARGET emit_tests
endef

DEFAULT_INSTALL_RULE := $(INSTALL_RULE)
override define INSTALL_RULE
$(DEFAULT_INSTALL_RULE)
$(MAKE) -C ebb install
TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET: -C $$TARGET install
endef

clean:
$(RM) $(TEST_PROGS) loop.o
$(MAKE) -C ebb clean
$(RM) $(TEST_GEN_PROGS) $(OUTPUT)/loop.o
TARGET=ebb; BUILD_TARGET=$$OUTPUT/$$TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET: -C $$TARGET clean

ebb:
$(MAKE) -k -C $@ all
TARGET=$@; BUILD_TARGET=$$OUTPUT/$$TARGET; mkdir -p $$BUILD_TARGET; $(MAKE) OUTPUT=$$BUILD_TARGET -k -C $$TARGET all

.PHONY: all run_tests clean ebb
4 changes: 2 additions & 2 deletions tools/testing/selftests/powerpc/pmu/ebb/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ include ../../../lib.mk
$(TEST_GEN_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \
ebb.c ebb_handler.S trace.c busy_loop.S

instruction_count_test: ../loop.S
$(OUTPUT)/instruction_count_test: ../loop.S

lost_exception_test: ../lib.c
$(OUTPUT)/lost_exception_test: ../lib.c
8 changes: 4 additions & 4 deletions tools/testing/selftests/powerpc/switch_endian/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ TEST_GEN_PROGS := switch_endian_test

ASFLAGS += -O2 -Wall -g -nostdlib -m64

EXTRA_CLEAN = *.o check-reversed.S
EXTRA_CLEAN = $(OUTPUT)/*.o $(OUTPUT)/check-reversed.S

include ../../lib.mk

switch_endian_test: check-reversed.S
$(OUTPUT)/switch_endian_test: $(OUTPUT)/check-reversed.S

check-reversed.o: check.o
$(OUTPUT)/check-reversed.o: $(OUTPUT)/check.o
$(CROSS_COMPILE)objcopy -j .text --reverse-bytes=4 -O binary $< $@

check-reversed.S: check-reversed.o
$(OUTPUT)/check-reversed.S: $(OUTPUT)/check-reversed.o
hexdump -v -e '/1 ".byte 0x%02X\n"' $< > $@
Loading

0 comments on commit a8ba798

Please sign in to comment.