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

selftests: Fix test errors related to lib.mk khdr target

Commit b2d35fa5fc80 ("selftests: add headers_install to lib.mk") added
khdr target to run headers_install target from the main Makefile. The
logic uses KSFT_KHDR_INSTALL and top_srcdir as controls to initialize
variables and include files to run headers_install from the top level
Makefile. There are a few problems with this logic.

1. Exposes top_srcdir to all tests
2. Common logic impacts all tests
3. Uses KSFT_KHDR_INSTALL, top_srcdir, and khdr in an adhoc way. Tests
add "khdr" dependency in their Makefiles to TEST_PROGS_EXTENDED in
some cases, and STATIC_LIBS in other cases. This makes this framework
confusing to use.

The common logic that runs for all tests even when KSFT_KHDR_INSTALL
isn't defined by the test. top_srcdir is initialized to a default value
when test doesn't initialize it. It works for all tests without a sub-dir
structure and tests with sub-dir structure fail to build.

e.g: make -C sparc64/drivers/ or make -C drivers/dma-buf

../../lib.mk:20: ../../../../scripts/subarch.include: No such file or directory
make: *** No rule to make target '../../../../scripts/subarch.include'. Stop.

There is no reason to require all tests to define top_srcdir and there is
no need to require tests to add khdr dependency using adhoc changes to
TEST_* and other variables.

Fix it with a consistent use of KSFT_KHDR_INSTALL and top_srcdir from tests
that have the dependency on headers_install.

Change common logic to include khdr target define and "all" target with
dependency on khdr when KSFT_KHDR_INSTALL is defined.

Only tests that have dependency on headers_install have to define just
the KSFT_KHDR_INSTALL, and top_srcdir variables and there is no need to
specify khdr dependency in the test Makefiles.

Fixes: b2d35fa5fc80 ("selftests: add headers_install to lib.mk")
Cc: stable@vger.kernel.org
Signed-off-by: Shuah Khan <shuah@kernel.org>

+13 -9
+1 -1
tools/testing/selftests/android/Makefile
··· 6 6 7 7 include ../lib.mk 8 8 9 - all: khdr 9 + all: 10 10 @for DIR in $(SUBDIRS); do \ 11 11 BUILD_TARGET=$(OUTPUT)/$$DIR; \ 12 12 mkdir $$BUILD_TARGET -p; \
+1
tools/testing/selftests/futex/functional/Makefile
··· 19 19 TEST_PROGS := run.sh 20 20 21 21 top_srcdir = ../../../../.. 22 + KSFT_KHDR_INSTALL := 1 22 23 include ../../lib.mk 23 24 24 25 $(TEST_GEN_FILES): $(HEADERS)
+3 -3
tools/testing/selftests/gpio/Makefile
··· 10 10 GPIODIR := $(realpath ../../../gpio) 11 11 GPIOOBJ := gpio-utils.o 12 12 13 - include ../lib.mk 14 - 15 13 all: $(TEST_PROGS_EXTENDED) 16 14 17 15 override define CLEAN ··· 17 19 $(MAKE) -C $(GPIODIR) OUTPUT=$(GPIODIR)/ clean 18 20 endef 19 21 20 - $(TEST_PROGS_EXTENDED):| khdr 22 + KSFT_KHDR_INSTALL := 1 23 + include ../lib.mk 24 + 21 25 $(TEST_PROGS_EXTENDED): $(GPIODIR)/$(GPIOOBJ) 22 26 23 27 $(GPIODIR)/$(GPIOOBJ):
+1 -1
tools/testing/selftests/kvm/Makefile
··· 1 1 all: 2 2 3 3 top_srcdir = ../../../.. 4 + KSFT_KHDR_INSTALL := 1 4 5 UNAME_M := $(shell uname -m) 5 6 6 7 LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/ucall.c lib/sparsebit.c ··· 45 44 46 45 all: $(STATIC_LIBS) 47 46 $(TEST_GEN_PROGS): $(STATIC_LIBS) 48 - $(STATIC_LIBS):| khdr 49 47 50 48 cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. 51 49 cscope:
+4 -4
tools/testing/selftests/lib.mk
··· 16 16 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 17 17 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 18 18 19 + ifdef KSFT_KHDR_INSTALL 19 20 top_srcdir ?= ../../../.. 20 21 include $(top_srcdir)/scripts/subarch.include 21 22 ARCH ?= $(SUBARCH) 22 - 23 - all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 24 23 25 24 .PHONY: khdr 26 25 khdr: 27 26 make ARCH=$(ARCH) -C $(top_srcdir) headers_install 28 27 29 - ifdef KSFT_KHDR_INSTALL 30 - $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr 28 + all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 29 + else 30 + all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 31 31 endif 32 32 33 33 .ONESHELL:
+1
tools/testing/selftests/networking/timestamping/Makefile
··· 6 6 all: $(TEST_PROGS) 7 7 8 8 top_srcdir = ../../../../.. 9 + KSFT_KHDR_INSTALL := 1 9 10 include ../../lib.mk 10 11 11 12 clean:
+1
tools/testing/selftests/tc-testing/bpf/Makefile
··· 4 4 TEST_GEN_FILES = action.o 5 5 6 6 top_srcdir = ../../../../.. 7 + KSFT_KHDR_INSTALL := 1 7 8 include ../../lib.mk 8 9 9 10 CLANG ?= clang
+1
tools/testing/selftests/vm/Makefile
··· 25 25 26 26 TEST_PROGS := run_vmtests 27 27 28 + KSFT_KHDR_INSTALL := 1 28 29 include ../lib.mk 29 30 30 31 $(OUTPUT)/userfaultfd: LDLIBS += -lpthread