Skip to content

Commit

Permalink
selftests: add headers_install to lib.mk
Browse files Browse the repository at this point in the history
If the kernel headers aren't installed we can't build all the tests.
Add a new make target rule 'khdr' in the file lib.mk to generate the
kernel headers and that gets include for every test-dir Makefile that
includes lib.mk If the testdir in turn have its own sub-dirs the
top_srcdir needs to be set to the linux-rootdir to be able to generate
the kernel headers.

Signed-off-by: Anders Roxell <[email protected]>
Reviewed-by: Fathi Boudra <[email protected]>
Signed-off-by: Shuah Khan (Samsung OSG) <[email protected]>
  • Loading branch information
roxell authored and Shuah Khan (Samsung OSG) committed Sep 5, 2018
1 parent c31d02d commit b2d35fa
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 28 deletions.
14 changes: 1 addition & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -299,19 +299,7 @@ KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION

# SUBARCH tells the usermode build what the underlying arch is. That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below. If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and
# SUBARCH is subsequently ignored.

SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
-e s/riscv.*/riscv/)
include scripts/subarch.include

# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions scripts/subarch.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SUBARCH tells the usermode build what the underlying arch is. That is set
# first, and if a usermode build is happening, the "ARCH=um" on the command
# line overrides the setting of ARCH below. If a native build is happening,
# then ARCH is assigned, getting whatever value it gets normally, and
# SUBARCH is subsequently ignored.

SUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
-e s/sun4u/sparc64/ \
-e s/arm.*/arm/ -e s/sa110/arm/ \
-e s/s390x/s390/ -e s/parisc64/parisc/ \
-e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
-e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ \
-e s/riscv.*/riscv/)
2 changes: 1 addition & 1 deletion tools/testing/selftests/android/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ TEST_PROGS := run.sh

include ../lib.mk

all:
all: khdr
@for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \
Expand Down
2 changes: 2 additions & 0 deletions tools/testing/selftests/android/ion/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ $(TEST_GEN_FILES): ipcsocket.c ionutils.c

TEST_PROGS := ion_test.sh

KSFT_KHDR_INSTALL := 1
top_srcdir = ../../../../..
include ../../lib.mk

$(OUTPUT)/ionapp_export: ionapp_export.c ipcsocket.c ionutils.c
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/futex/functional/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ TEST_GEN_FILES := \

TEST_PROGS := run.sh

top_srcdir = ../../../../..
include ../../lib.mk

$(TEST_GEN_FILES): $(HEADERS)
7 changes: 2 additions & 5 deletions tools/testing/selftests/gpio/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ endef
CFLAGS += -O2 -g -std=gnu99 -Wall -I../../../../usr/include/
LDLIBS += -lmount -I/usr/include/libmount

$(BINARIES): ../../../gpio/gpio-utils.o ../../../../usr/include/linux/gpio.h
$(BINARIES):| khdr
$(BINARIES): ../../../gpio/gpio-utils.o

../../../gpio/gpio-utils.o:
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C ../../../gpio

../../../../usr/include/linux/gpio.h:
make -C ../../../.. headers_install INSTALL_HDR_PATH=$(shell pwd)/../../../../usr/

7 changes: 2 additions & 5 deletions tools/testing/selftests/kvm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ $(LIBKVM_OBJ): $(OUTPUT)/%.o: %.c
$(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
$(AR) crs $@ $^

$(LINUX_HDR_PATH):
make -C $(top_srcdir) headers_install

all: $(STATIC_LIBS) $(LINUX_HDR_PATH)
all: $(STATIC_LIBS)
$(TEST_GEN_PROGS): $(STATIC_LIBS)
$(TEST_GEN_PROGS) $(LIBKVM_OBJ): | $(LINUX_HDR_PATH)
$(STATIC_LIBS):| khdr
12 changes: 12 additions & 0 deletions tools/testing/selftests/lib.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,20 @@ TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))

top_srcdir ?= ../../../..
include $(top_srcdir)/scripts/subarch.include
ARCH ?= $(SUBARCH)

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

.PHONY: khdr
khdr:
make ARCH=$(ARCH) -C $(top_srcdir) headers_install

ifdef KSFT_KHDR_INSTALL
$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr
endif

.ONESHELL:
define RUN_TEST_PRINT_RESULT
TEST_HDR_MSG="selftests: "`basename $$PWD`:" $$BASENAME_TEST"; \
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/net/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TEST_GEN_FILES += udpgso udpgso_bench_tx udpgso_bench_rx
TEST_GEN_PROGS = reuseport_bpf reuseport_bpf_cpu reuseport_bpf_numa
TEST_GEN_PROGS += reuseport_dualstack reuseaddr_conflict tls

KSFT_KHDR_INSTALL := 1
include ../lib.mk

$(OUTPUT)/reuseport_bpf_numa: LDFLAGS += -lnuma
Expand Down
1 change: 1 addition & 0 deletions tools/testing/selftests/networking/timestamping/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ TEST_PROGS := hwtstamp_config rxtimestamp timestamping txtimestamp

all: $(TEST_PROGS)

top_srcdir = ../../../../..
include ../../lib.mk

clean:
Expand Down
4 changes: 0 additions & 4 deletions tools/testing/selftests/vm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ TEST_PROGS := run_vmtests

include ../lib.mk

$(OUTPUT)/userfaultfd: ../../../../usr/include/linux/kernel.h
$(OUTPUT)/userfaultfd: LDLIBS += -lpthread

$(OUTPUT)/mlock-random-test: LDLIBS += -lcap

../../../../usr/include/linux/kernel.h:
make -C ../../../.. headers_install

0 comments on commit b2d35fa

Please sign in to comment.