| .. | .. |
|---|
| 1 | 1 | # SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | 2 | TARGETS = android |
|---|
| 3 | +TARGETS += arm64 |
|---|
| 3 | 4 | TARGETS += bpf |
|---|
| 4 | 5 | TARGETS += breakpoints |
|---|
| 5 | 6 | TARGETS += capabilities |
|---|
| 6 | 7 | TARGETS += cgroup |
|---|
| 8 | +TARGETS += clone3 |
|---|
| 9 | +TARGETS += core |
|---|
| 7 | 10 | TARGETS += cpufreq |
|---|
| 8 | 11 | TARGETS += cpu-hotplug |
|---|
| 12 | +TARGETS += damon |
|---|
| 13 | +TARGETS += drivers/dma-buf |
|---|
| 9 | 14 | TARGETS += efivarfs |
|---|
| 10 | 15 | TARGETS += exec |
|---|
| 11 | 16 | TARGETS += filesystems |
|---|
| 17 | +TARGETS += filesystems/binderfs |
|---|
| 18 | +TARGETS += filesystems/epoll |
|---|
| 12 | 19 | TARGETS += firmware |
|---|
| 20 | +TARGETS += fpu |
|---|
| 13 | 21 | TARGETS += ftrace |
|---|
| 14 | 22 | TARGETS += futex |
|---|
| 15 | 23 | TARGETS += gpio |
|---|
| 16 | 24 | TARGETS += intel_pstate |
|---|
| 17 | 25 | TARGETS += ipc |
|---|
| 26 | +TARGETS += ir |
|---|
| 18 | 27 | TARGETS += kcmp |
|---|
| 28 | +TARGETS += kexec |
|---|
| 19 | 29 | TARGETS += kvm |
|---|
| 20 | 30 | TARGETS += lib |
|---|
| 31 | +TARGETS += livepatch |
|---|
| 32 | +TARGETS += lkdtm |
|---|
| 21 | 33 | TARGETS += membarrier |
|---|
| 22 | 34 | TARGETS += memfd |
|---|
| 23 | 35 | TARGETS += memory-hotplug |
|---|
| 36 | +TARGETS += mincore |
|---|
| 24 | 37 | TARGETS += mount |
|---|
| 25 | 38 | TARGETS += mqueue |
|---|
| 26 | 39 | TARGETS += net |
|---|
| 40 | +TARGETS += net/forwarding |
|---|
| 41 | +TARGETS += net/mptcp |
|---|
| 27 | 42 | TARGETS += netfilter |
|---|
| 28 | 43 | TARGETS += nsfs |
|---|
| 44 | +TARGETS += pidfd |
|---|
| 45 | +TARGETS += pid_namespace |
|---|
| 29 | 46 | TARGETS += powerpc |
|---|
| 30 | 47 | TARGETS += proc |
|---|
| 31 | 48 | TARGETS += pstore |
|---|
| 32 | 49 | TARGETS += ptrace |
|---|
| 50 | +TARGETS += openat2 |
|---|
| 33 | 51 | TARGETS += rseq |
|---|
| 34 | 52 | TARGETS += rtc |
|---|
| 35 | 53 | TARGETS += seccomp |
|---|
| .. | .. |
|---|
| 40 | 58 | TARGETS += static_keys |
|---|
| 41 | 59 | TARGETS += sync |
|---|
| 42 | 60 | TARGETS += sysctl |
|---|
| 61 | +TARGETS += tc-testing |
|---|
| 62 | +TARGETS += timens |
|---|
| 43 | 63 | ifneq (1, $(quicktest)) |
|---|
| 44 | 64 | TARGETS += timers |
|---|
| 45 | 65 | endif |
|---|
| 66 | +TARGETS += tmpfs |
|---|
| 67 | +TARGETS += tpm2 |
|---|
| 46 | 68 | TARGETS += user |
|---|
| 47 | 69 | TARGETS += vm |
|---|
| 48 | 70 | TARGETS += x86 |
|---|
| .. | .. |
|---|
| 54 | 76 | TARGETS_HOTPLUG = cpu-hotplug |
|---|
| 55 | 77 | TARGETS_HOTPLUG += memory-hotplug |
|---|
| 56 | 78 | |
|---|
| 57 | | -# Clear LDFLAGS and MAKEFLAGS if called from main |
|---|
| 58 | | -# Makefile to avoid test build failures when test |
|---|
| 59 | | -# Makefile doesn't have explicit build rules. |
|---|
| 60 | | -ifeq (1,$(MAKELEVEL)) |
|---|
| 79 | +# User can optionally provide a TARGETS skiplist. |
|---|
| 80 | +SKIP_TARGETS ?= |
|---|
| 81 | +ifneq ($(SKIP_TARGETS),) |
|---|
| 82 | + TMP := $(filter-out $(SKIP_TARGETS), $(TARGETS)) |
|---|
| 83 | + override TARGETS := $(TMP) |
|---|
| 84 | +endif |
|---|
| 85 | + |
|---|
| 86 | +# User can set FORCE_TARGETS to 1 to require all targets to be successfully |
|---|
| 87 | +# built; make will fail if any of the targets cannot be built. If |
|---|
| 88 | +# FORCE_TARGETS is not set (the default), make will succeed if at least one |
|---|
| 89 | +# of the targets gets built. |
|---|
| 90 | +FORCE_TARGETS ?= |
|---|
| 91 | + |
|---|
| 92 | +# Clear LDFLAGS and MAKEFLAGS when implicit rules are missing. This provides |
|---|
| 93 | +# implicit rules to sub-test Makefiles which avoids build failures in test |
|---|
| 94 | +# Makefile that don't have explicit build rules. |
|---|
| 95 | +ifeq (,$(LINK.c)) |
|---|
| 61 | 96 | override LDFLAGS = |
|---|
| 62 | 97 | override MAKEFLAGS = |
|---|
| 63 | 98 | endif |
|---|
| 64 | 99 | |
|---|
| 65 | | -ifneq ($(KBUILD_SRC),) |
|---|
| 100 | +# Append kselftest to KBUILD_OUTPUT and O to avoid cluttering |
|---|
| 101 | +# KBUILD_OUTPUT with selftest objects and headers installed |
|---|
| 102 | +# by selftests Makefile or lib.mk. |
|---|
| 103 | +ifdef building_out_of_srctree |
|---|
| 66 | 104 | override LDFLAGS = |
|---|
| 67 | 105 | endif |
|---|
| 68 | 106 | |
|---|
| 69 | | -BUILD := $(O) |
|---|
| 70 | | -ifndef BUILD |
|---|
| 71 | | - BUILD := $(KBUILD_OUTPUT) |
|---|
| 72 | | -endif |
|---|
| 73 | | -ifndef BUILD |
|---|
| 74 | | - BUILD := $(shell pwd) |
|---|
| 107 | +top_srcdir ?= ../../.. |
|---|
| 108 | + |
|---|
| 109 | +ifeq ("$(origin O)", "command line") |
|---|
| 110 | + KBUILD_OUTPUT := $(O) |
|---|
| 75 | 111 | endif |
|---|
| 76 | 112 | |
|---|
| 77 | | -# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header |
|---|
| 78 | | -# printing from tests. Applicable to run_tests case where run_tests adds |
|---|
| 79 | | -# TAP header prior running tests and when a test program invokes another |
|---|
| 80 | | -# with system() call. Export it here to cover override RUN_TESTS defines. |
|---|
| 81 | | -export KSFT_TAP_LEVEL=`echo 1` |
|---|
| 113 | +ifneq ($(KBUILD_OUTPUT),) |
|---|
| 114 | + # Make's built-in functions such as $(abspath ...), $(realpath ...) cannot |
|---|
| 115 | + # expand a shell special character '~'. We use a somewhat tedious way here. |
|---|
| 116 | + abs_objtree := $(shell cd $(top_srcdir) && mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd) |
|---|
| 117 | + $(if $(abs_objtree),, \ |
|---|
| 118 | + $(error failed to create output directory "$(KBUILD_OUTPUT)")) |
|---|
| 119 | + # $(realpath ...) resolves symlinks |
|---|
| 120 | + abs_objtree := $(realpath $(abs_objtree)) |
|---|
| 121 | + BUILD := $(abs_objtree)/kselftest |
|---|
| 122 | +else |
|---|
| 123 | + BUILD := $(CURDIR) |
|---|
| 124 | + DEFAULT_INSTALL_HDR_PATH := 1 |
|---|
| 125 | +endif |
|---|
| 82 | 126 | |
|---|
| 127 | +# Prepare for headers install |
|---|
| 128 | +include $(top_srcdir)/scripts/subarch.include |
|---|
| 129 | +ARCH ?= $(SUBARCH) |
|---|
| 130 | +export KSFT_KHDR_INSTALL_DONE := 1 |
|---|
| 83 | 131 | export BUILD |
|---|
| 84 | | -all: |
|---|
| 85 | | - @for TARGET in $(TARGETS); do \ |
|---|
| 86 | | - BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 87 | | - mkdir $$BUILD_TARGET -p; \ |
|---|
| 88 | | - make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ |
|---|
| 89 | | - done; |
|---|
| 132 | + |
|---|
| 133 | +# build and run gpio when output directory is the src dir. |
|---|
| 134 | +# gpio has dependency on tools/gpio and builds tools/gpio |
|---|
| 135 | +# objects in the src directory in all cases making the src |
|---|
| 136 | +# repo dirty even when objects are relocated. |
|---|
| 137 | +ifneq (1,$(DEFAULT_INSTALL_HDR_PATH)) |
|---|
| 138 | + TMP := $(filter-out gpio, $(TARGETS)) |
|---|
| 139 | + TARGETS := $(TMP) |
|---|
| 140 | +endif |
|---|
| 141 | + |
|---|
| 142 | +# set default goal to all, so make without a target runs all, even when |
|---|
| 143 | +# all isn't the first target in the file. |
|---|
| 144 | +.DEFAULT_GOAL := all |
|---|
| 145 | + |
|---|
| 146 | +# Install headers here once for all tests. KSFT_KHDR_INSTALL_DONE |
|---|
| 147 | +# is used to avoid running headers_install from lib.mk. |
|---|
| 148 | +# Invoke headers install with --no-builtin-rules to avoid circular |
|---|
| 149 | +# dependency in "make kselftest" case. In this case, second level |
|---|
| 150 | +# make inherits builtin-rules which will use the rule generate |
|---|
| 151 | +# Makefile.o and runs into |
|---|
| 152 | +# "Circular Makefile.o <- prepare dependency dropped." |
|---|
| 153 | +# and headers_install fails and test compile fails. |
|---|
| 154 | +# |
|---|
| 155 | +# O= KBUILD_OUTPUT cases don't run into this error, since main Makefile |
|---|
| 156 | +# invokes them as sub-makes and --no-builtin-rules is not necessary, |
|---|
| 157 | +# but doesn't cause any failures. Keep it simple and use the same |
|---|
| 158 | +# flags in both cases. |
|---|
| 159 | +# Local build cases: "make kselftest", "make -C" - headers are installed |
|---|
| 160 | +# in the default INSTALL_HDR_PATH usr/include. |
|---|
| 161 | +khdr: |
|---|
| 162 | +ifeq (1,$(DEFAULT_INSTALL_HDR_PATH)) |
|---|
| 163 | + $(MAKE) --no-builtin-rules ARCH=$(ARCH) -C $(top_srcdir) headers_install |
|---|
| 164 | +else |
|---|
| 165 | + $(MAKE) --no-builtin-rules INSTALL_HDR_PATH=$$BUILD/usr \ |
|---|
| 166 | + ARCH=$(ARCH) -C $(top_srcdir) headers_install |
|---|
| 167 | +endif |
|---|
| 168 | + |
|---|
| 169 | +all: khdr |
|---|
| 170 | + @ret=1; \ |
|---|
| 171 | + for TARGET in $(TARGETS); do \ |
|---|
| 172 | + BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 173 | + mkdir $$BUILD_TARGET -p; \ |
|---|
| 174 | + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET \ |
|---|
| 175 | + $(if $(FORCE_TARGETS),|| exit); \ |
|---|
| 176 | + ret=$$((ret * $$?)); \ |
|---|
| 177 | + done; exit $$ret; |
|---|
| 90 | 178 | |
|---|
| 91 | 179 | run_tests: all |
|---|
| 92 | 180 | @for TARGET in $(TARGETS); do \ |
|---|
| 93 | 181 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 94 | | - make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ |
|---|
| 182 | + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ |
|---|
| 95 | 183 | done; |
|---|
| 96 | 184 | |
|---|
| 97 | 185 | hotplug: |
|---|
| 98 | 186 | @for TARGET in $(TARGETS_HOTPLUG); do \ |
|---|
| 99 | 187 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 100 | | - make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ |
|---|
| 188 | + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET;\ |
|---|
| 101 | 189 | done; |
|---|
| 102 | 190 | |
|---|
| 103 | 191 | run_hotplug: hotplug |
|---|
| 104 | 192 | @for TARGET in $(TARGETS_HOTPLUG); do \ |
|---|
| 105 | 193 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 106 | | - make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ |
|---|
| 194 | + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ |
|---|
| 107 | 195 | done; |
|---|
| 108 | 196 | |
|---|
| 109 | 197 | clean_hotplug: |
|---|
| 110 | 198 | @for TARGET in $(TARGETS_HOTPLUG); do \ |
|---|
| 111 | 199 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 112 | | - make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ |
|---|
| 200 | + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ |
|---|
| 113 | 201 | done; |
|---|
| 114 | 202 | |
|---|
| 115 | 203 | run_pstore_crash: |
|---|
| 116 | | - make -C pstore run_crash |
|---|
| 204 | + $(MAKE) -C pstore run_crash |
|---|
| 117 | 205 | |
|---|
| 118 | | -INSTALL_PATH ?= install |
|---|
| 119 | | -INSTALL_PATH := $(abspath $(INSTALL_PATH)) |
|---|
| 206 | +# Use $BUILD as the default install root. $BUILD points to the |
|---|
| 207 | +# right output location for the following cases: |
|---|
| 208 | +# 1. output_dir=kernel_src |
|---|
| 209 | +# 2. a separate output directory is specified using O= KBUILD_OUTPUT |
|---|
| 210 | +# 3. a separate output directory is specified using KBUILD_OUTPUT |
|---|
| 211 | +# Avoid conflict with INSTALL_PATH set by the main Makefile |
|---|
| 212 | +# |
|---|
| 213 | +KSFT_INSTALL_PATH ?= $(BUILD)/kselftest_install |
|---|
| 214 | +KSFT_INSTALL_PATH := $(abspath $(KSFT_INSTALL_PATH)) |
|---|
| 215 | +# Avoid changing the rest of the logic here and lib.mk. |
|---|
| 216 | +INSTALL_PATH := $(KSFT_INSTALL_PATH) |
|---|
| 120 | 217 | ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh |
|---|
| 218 | +TEST_LIST := $(INSTALL_PATH)/kselftest-list.txt |
|---|
| 121 | 219 | |
|---|
| 122 | | -install: |
|---|
| 220 | +install: all |
|---|
| 123 | 221 | ifdef INSTALL_PATH |
|---|
| 124 | 222 | @# Ask all targets to install their files |
|---|
| 125 | | - mkdir -p $(INSTALL_PATH) |
|---|
| 126 | | - @for TARGET in $(TARGETS); do \ |
|---|
| 127 | | - BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 128 | | - make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ |
|---|
| 129 | | - done; |
|---|
| 130 | | - |
|---|
| 131 | | - @# Ask all targets to emit their test scripts |
|---|
| 132 | | - echo "#!/bin/sh" > $(ALL_SCRIPT) |
|---|
| 133 | | - echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT) |
|---|
| 134 | | - echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT) |
|---|
| 135 | | - echo "ROOT=\$$PWD" >> $(ALL_SCRIPT) |
|---|
| 136 | | - echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT) |
|---|
| 137 | | - echo " OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT) |
|---|
| 138 | | - echo " cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT) |
|---|
| 139 | | - echo "else" >> $(ALL_SCRIPT) |
|---|
| 140 | | - echo " OUTPUT=/dev/stdout" >> $(ALL_SCRIPT) |
|---|
| 141 | | - echo "fi" >> $(ALL_SCRIPT) |
|---|
| 142 | | - echo "export KSFT_TAP_LEVEL=1" >> $(ALL_SCRIPT) |
|---|
| 143 | | - echo "export skip=4" >> $(ALL_SCRIPT) |
|---|
| 144 | | - |
|---|
| 223 | + mkdir -p $(INSTALL_PATH)/kselftest |
|---|
| 224 | + install -m 744 kselftest/module.sh $(INSTALL_PATH)/kselftest/ |
|---|
| 225 | + install -m 744 kselftest/runner.sh $(INSTALL_PATH)/kselftest/ |
|---|
| 226 | + install -m 744 kselftest/prefix.pl $(INSTALL_PATH)/kselftest/ |
|---|
| 227 | + install -m 744 run_kselftest.sh $(INSTALL_PATH)/ |
|---|
| 228 | + rm -f $(TEST_LIST) |
|---|
| 229 | + @ret=1; \ |
|---|
| 145 | 230 | for TARGET in $(TARGETS); do \ |
|---|
| 146 | 231 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 147 | | - echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT); \ |
|---|
| 148 | | - echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \ |
|---|
| 149 | | - echo "echo ========================================" >> $(ALL_SCRIPT); \ |
|---|
| 150 | | - echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ |
|---|
| 151 | | - echo "cd $$TARGET" >> $(ALL_SCRIPT); \ |
|---|
| 152 | | - make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ |
|---|
| 153 | | - echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ |
|---|
| 154 | | - done; |
|---|
| 232 | + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install \ |
|---|
| 233 | + $(if $(FORCE_TARGETS),|| exit); \ |
|---|
| 234 | + ret=$$((ret * $$?)); \ |
|---|
| 235 | + done; exit $$ret; |
|---|
| 155 | 236 | |
|---|
| 156 | | - chmod u+x $(ALL_SCRIPT) |
|---|
| 237 | + |
|---|
| 238 | + @# Ask all targets to emit their test scripts |
|---|
| 239 | + @# While building kselftest-list.text skip also non-existent TARGET dirs: |
|---|
| 240 | + @# they could be the result of a build failure and should NOT be |
|---|
| 241 | + @# included in the generated runlist. |
|---|
| 242 | + for TARGET in $(TARGETS); do \ |
|---|
| 243 | + BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 244 | + [ ! -d $(INSTALL_PATH)/$$TARGET ] && echo "Skipping non-existent dir: $$TARGET" && continue; \ |
|---|
| 245 | + echo -n "Emit Tests for $$TARGET\n"; \ |
|---|
| 246 | + $(MAKE) -s --no-print-directory OUTPUT=$$BUILD_TARGET COLLECTION=$$TARGET \ |
|---|
| 247 | + -C $$TARGET emit_tests >> $(TEST_LIST); \ |
|---|
| 248 | + done; |
|---|
| 157 | 249 | else |
|---|
| 158 | 250 | $(error Error: set INSTALL_PATH to use install) |
|---|
| 159 | 251 | endif |
|---|
| 160 | 252 | |
|---|
| 253 | +FORMAT ?= .gz |
|---|
| 254 | +TAR_PATH = $(abspath ${INSTALL_PATH}/kselftest-packages/kselftest.tar${FORMAT}) |
|---|
| 255 | +gen_tar: install |
|---|
| 256 | + @mkdir -p ${INSTALL_PATH}/kselftest-packages/ |
|---|
| 257 | + @tar caf ${TAR_PATH} --exclude=kselftest-packages -C ${INSTALL_PATH} . |
|---|
| 258 | + @echo "Created ${TAR_PATH}" |
|---|
| 259 | + |
|---|
| 161 | 260 | clean: |
|---|
| 162 | 261 | @for TARGET in $(TARGETS); do \ |
|---|
| 163 | 262 | BUILD_TARGET=$$BUILD/$$TARGET; \ |
|---|
| 164 | | - make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ |
|---|
| 263 | + $(MAKE) OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ |
|---|
| 165 | 264 | done; |
|---|
| 166 | 265 | |
|---|
| 167 | | -.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean |
|---|
| 266 | +.PHONY: khdr all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean gen_tar |
|---|