Commit 283ac6d5 authored by Shuah Khan's avatar Shuah Khan

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

Commit b2d35fa5 ("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: b2d35fa5 ("selftests: add headers_install to lib.mk")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
Reviewed-by: default avatarKhalid Aziz <khalid.aziz@oracle.com>
Reviewed-by: default avatarAnders Roxell <anders.roxell@linaro.org>
Signed-off-by: default avatarShuah Khan <shuah@kernel.org>
parent 6edf2e37
...@@ -6,7 +6,7 @@ TEST_PROGS := run.sh ...@@ -6,7 +6,7 @@ TEST_PROGS := run.sh
include ../lib.mk include ../lib.mk
all: khdr all:
@for DIR in $(SUBDIRS); do \ @for DIR in $(SUBDIRS); do \
BUILD_TARGET=$(OUTPUT)/$$DIR; \ BUILD_TARGET=$(OUTPUT)/$$DIR; \
mkdir $$BUILD_TARGET -p; \ mkdir $$BUILD_TARGET -p; \
......
...@@ -19,6 +19,7 @@ TEST_GEN_FILES := \ ...@@ -19,6 +19,7 @@ TEST_GEN_FILES := \
TEST_PROGS := run.sh TEST_PROGS := run.sh
top_srcdir = ../../../../.. top_srcdir = ../../../../..
KSFT_KHDR_INSTALL := 1
include ../../lib.mk include ../../lib.mk
$(TEST_GEN_FILES): $(HEADERS) $(TEST_GEN_FILES): $(HEADERS)
...@@ -16,8 +16,6 @@ TEST_PROGS_EXTENDED := gpio-mockup-chardev ...@@ -16,8 +16,6 @@ TEST_PROGS_EXTENDED := gpio-mockup-chardev
GPIODIR := $(realpath ../../../gpio) GPIODIR := $(realpath ../../../gpio)
GPIOOBJ := gpio-utils.o GPIOOBJ := gpio-utils.o
include ../lib.mk
all: $(TEST_PROGS_EXTENDED) all: $(TEST_PROGS_EXTENDED)
override define CLEAN override define CLEAN
...@@ -25,7 +23,9 @@ override define CLEAN ...@@ -25,7 +23,9 @@ override define CLEAN
$(MAKE) -C $(GPIODIR) OUTPUT=$(GPIODIR)/ clean $(MAKE) -C $(GPIODIR) OUTPUT=$(GPIODIR)/ clean
endef endef
$(TEST_PROGS_EXTENDED):| khdr KSFT_KHDR_INSTALL := 1
include ../lib.mk
$(TEST_PROGS_EXTENDED): $(GPIODIR)/$(GPIOOBJ) $(TEST_PROGS_EXTENDED): $(GPIODIR)/$(GPIOOBJ)
$(GPIODIR)/$(GPIOOBJ): $(GPIODIR)/$(GPIOOBJ):
......
all: all:
top_srcdir = ../../../.. top_srcdir = ../../../..
KSFT_KHDR_INSTALL := 1
UNAME_M := $(shell uname -m) UNAME_M := $(shell uname -m)
LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/ucall.c lib/sparsebit.c LIBKVM = lib/assert.c lib/elf.c lib/io.c lib/kvm_util.c lib/ucall.c lib/sparsebit.c
...@@ -44,7 +45,6 @@ $(OUTPUT)/libkvm.a: $(LIBKVM_OBJ) ...@@ -44,7 +45,6 @@ $(OUTPUT)/libkvm.a: $(LIBKVM_OBJ)
all: $(STATIC_LIBS) all: $(STATIC_LIBS)
$(TEST_GEN_PROGS): $(STATIC_LIBS) $(TEST_GEN_PROGS): $(STATIC_LIBS)
$(STATIC_LIBS):| khdr
cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib .. cscope: include_paths = $(LINUX_TOOL_INCLUDE) $(LINUX_HDR_PATH) include lib ..
cscope: cscope:
......
...@@ -16,18 +16,18 @@ TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS)) ...@@ -16,18 +16,18 @@ TEST_GEN_PROGS := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS))
TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED))
TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES))
ifdef KSFT_KHDR_INSTALL
top_srcdir ?= ../../../.. top_srcdir ?= ../../../..
include $(top_srcdir)/scripts/subarch.include include $(top_srcdir)/scripts/subarch.include
ARCH ?= $(SUBARCH) ARCH ?= $(SUBARCH)
all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
.PHONY: khdr .PHONY: khdr
khdr: khdr:
make ARCH=$(ARCH) -C $(top_srcdir) headers_install make ARCH=$(ARCH) -C $(top_srcdir) headers_install
ifdef KSFT_KHDR_INSTALL all: khdr $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES):| khdr else
all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
endif endif
.ONESHELL: .ONESHELL:
......
...@@ -6,6 +6,7 @@ TEST_PROGS := hwtstamp_config rxtimestamp timestamping txtimestamp ...@@ -6,6 +6,7 @@ TEST_PROGS := hwtstamp_config rxtimestamp timestamping txtimestamp
all: $(TEST_PROGS) all: $(TEST_PROGS)
top_srcdir = ../../../../.. top_srcdir = ../../../../..
KSFT_KHDR_INSTALL := 1
include ../../lib.mk include ../../lib.mk
clean: clean:
......
...@@ -4,6 +4,7 @@ APIDIR := ../../../../include/uapi ...@@ -4,6 +4,7 @@ APIDIR := ../../../../include/uapi
TEST_GEN_FILES = action.o TEST_GEN_FILES = action.o
top_srcdir = ../../../../.. top_srcdir = ../../../../..
KSFT_KHDR_INSTALL := 1
include ../../lib.mk include ../../lib.mk
CLANG ?= clang CLANG ?= clang
......
...@@ -25,6 +25,7 @@ TEST_GEN_FILES += virtual_address_range ...@@ -25,6 +25,7 @@ TEST_GEN_FILES += virtual_address_range
TEST_PROGS := run_vmtests TEST_PROGS := run_vmtests
KSFT_KHDR_INSTALL := 1
include ../lib.mk include ../lib.mk
$(OUTPUT)/userfaultfd: LDLIBS += -lpthread $(OUTPUT)/userfaultfd: LDLIBS += -lpthread
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment