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

Configure Feed

Select the types of activity you want to include in your feed.

selftests: error out if kernel header files are not yet built

As per a discussion with Muhammad Usama Anjum [1], the following is how
one is supposed to build selftests:

make headers && make -C tools/testing/selftests/mm

Change the selftest build system's lib.mk to fail out with a helpful
message if that prerequisite "make headers" has not been done yet.

[1] https://lore.kernel.org/all/bf910fa5-0c96-3707-cce4-5bcc656b6274@collabora.com/

[jhubbard@nvidia.com: abort the make process the first time headers aren't detected]
Link: https://lkml.kernel.org/r/14573e7e-f2ad-ff34-dfbd-3efdebee51ed@nvidia.com
[anders.roxell@linaro.org: fix out-of-tree builds]
Link: https://lkml.kernel.org/r/20230613074931.666966-1-anders.roxell@linaro.org
Link: https://lkml.kernel.org/r/20230606071637.267103-12-jhubbard@nvidia.com
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
Reviewed-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Tested-by: Muhammad Usama Anjum <usama.anjum@collabora.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

John Hubbard and committed by
Andrew Morton
9fc96c7c 01d6c48a

+57 -4
+20 -1
tools/testing/selftests/Makefile
··· 145 145 abs_objtree := $(realpath $(abs_objtree)) 146 146 BUILD := $(abs_objtree)/kselftest 147 147 KHDR_INCLUDES := -isystem ${abs_objtree}/usr/include 148 + KHDR_DIR := ${abs_objtree}/usr/include 148 149 else 149 150 BUILD := $(CURDIR) 150 151 abs_srctree := $(shell cd $(top_srcdir) && pwd) 151 152 KHDR_INCLUDES := -isystem ${abs_srctree}/usr/include 153 + KHDR_DIR := ${abs_srctree}/usr/include 152 154 DEFAULT_INSTALL_HDR_PATH := 1 153 155 endif 154 156 ··· 164 162 # all isn't the first target in the file. 165 163 .DEFAULT_GOAL := all 166 164 167 - all: 165 + all: kernel_header_files 168 166 @ret=1; \ 169 167 for TARGET in $(TARGETS); do \ 170 168 BUILD_TARGET=$$BUILD/$$TARGET; \ ··· 174 172 $(if $(FORCE_TARGETS),|| exit); \ 175 173 ret=$$((ret * $$?)); \ 176 174 done; exit $$ret; 175 + 176 + kernel_header_files: 177 + @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \ 178 + if [ $$? -ne 0 ]; then \ 179 + RED='\033[1;31m'; \ 180 + NOCOLOR='\033[0m'; \ 181 + echo; \ 182 + echo -e "$${RED}error$${NOCOLOR}: missing kernel header files."; \ 183 + echo "Please run this and try again:"; \ 184 + echo; \ 185 + echo " cd $(top_srcdir)"; \ 186 + echo " make headers"; \ 187 + echo; \ 188 + exit 1; \ 189 + fi 190 + 191 + .PHONY: kernel_header_files 177 192 178 193 run_tests: all 179 194 @for TARGET in $(TARGETS); do \
+37 -3
tools/testing/selftests/lib.mk
··· 44 44 selfdir = $(realpath $(dir $(filter %/lib.mk,$(MAKEFILE_LIST)))) 45 45 top_srcdir = $(selfdir)/../../.. 46 46 47 - ifeq ($(KHDR_INCLUDES),) 48 - KHDR_INCLUDES := -isystem $(top_srcdir)/usr/include 47 + ifeq ("$(origin O)", "command line") 48 + KBUILD_OUTPUT := $(O) 49 49 endif 50 + 51 + ifneq ($(KBUILD_OUTPUT),) 52 + # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot 53 + # expand a shell special character '~'. We use a somewhat tedious way here. 54 + abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) 55 + $(if $(abs_objtree),, \ 56 + $(error failed to create output directory "$(KBUILD_OUTPUT)")) 57 + # $(realpath ...) resolves symlinks 58 + abs_objtree := $(realpath $(abs_objtree)) 59 + KHDR_DIR := ${abs_objtree}/usr/include 60 + else 61 + abs_srctree := $(shell cd $(top_srcdir) && pwd) 62 + KHDR_DIR := ${abs_srctree}/usr/include 63 + endif 64 + 65 + KHDR_INCLUDES := -isystem $(KHDR_DIR) 50 66 51 67 # The following are built by lib.mk common compile rules. 52 68 # TEST_CUSTOM_PROGS should be used by tests that require ··· 74 58 TEST_GEN_PROGS_EXTENDED := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_PROGS_EXTENDED)) 75 59 TEST_GEN_FILES := $(patsubst %,$(OUTPUT)/%,$(TEST_GEN_FILES)) 76 60 77 - all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) 61 + all: kernel_header_files $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) \ 62 + $(TEST_GEN_FILES) 63 + 64 + kernel_header_files: 65 + @ls $(KHDR_DIR)/linux/*.h >/dev/null 2>/dev/null; \ 66 + if [ $$? -ne 0 ]; then \ 67 + RED='\033[1;31m'; \ 68 + NOCOLOR='\033[0m'; \ 69 + echo; \ 70 + echo -e "$${RED}error$${NOCOLOR}: missing kernel header files."; \ 71 + echo "Please run this and try again:"; \ 72 + echo; \ 73 + echo " cd $(top_srcdir)"; \ 74 + echo " make headers"; \ 75 + echo; \ 76 + exit 1; \ 77 + fi 78 + 79 + .PHONY: kernel_header_files 78 80 79 81 define RUN_TESTS 80 82 BASE_DIR="$(selfdir)"; \