Linux Audio

Check our new training course

Embedded Linux training

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