1# SPDX-License-Identifier: GPL-2.0 2TARGETS = android 3TARGETS += bpf 4TARGETS += breakpoints 5TARGETS += capabilities 6TARGETS += cpufreq 7TARGETS += cpu-hotplug 8TARGETS += efivarfs 9TARGETS += exec 10TARGETS += filesystems 11TARGETS += firmware 12TARGETS += ftrace 13TARGETS += futex 14TARGETS += gpio 15TARGETS += intel_pstate 16TARGETS += ipc 17TARGETS += kcmp 18TARGETS += lib 19TARGETS += membarrier 20TARGETS += memfd 21TARGETS += memory-hotplug 22TARGETS += mount 23TARGETS += mqueue 24TARGETS += net 25TARGETS += nsfs 26TARGETS += powerpc 27TARGETS += pstore 28TARGETS += ptrace 29TARGETS += seccomp 30TARGETS += sigaltstack 31TARGETS += size 32TARGETS += splice 33TARGETS += static_keys 34TARGETS += sync 35TARGETS += sysctl 36ifneq (1, $(quicktest)) 37TARGETS += timers 38endif 39TARGETS += user 40TARGETS += vm 41TARGETS += x86 42TARGETS += zram 43#Please keep the TARGETS list alphabetically sorted 44# Run "make quicktest=1 run_tests" or 45# "make quicktest=1 kselftest" from top level Makefile 46 47TARGETS_HOTPLUG = cpu-hotplug 48TARGETS_HOTPLUG += memory-hotplug 49 50# Clear LDFLAGS and MAKEFLAGS if called from main 51# Makefile to avoid test build failures when test 52# Makefile doesn't have explicit build rules. 53ifeq (1,$(MAKELEVEL)) 54override LDFLAGS = 55override MAKEFLAGS = 56endif 57 58ifneq ($(KBUILD_SRC),) 59override LDFLAGS = 60endif 61 62BUILD := $(O) 63ifndef BUILD 64 BUILD := $(KBUILD_OUTPUT) 65endif 66ifndef BUILD 67 BUILD := $(shell pwd) 68endif 69 70export BUILD 71all: 72 @for TARGET in $(TARGETS); do \ 73 BUILD_TARGET=$$BUILD/$$TARGET; \ 74 mkdir $$BUILD_TARGET -p; \ 75 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 76 done; 77 78run_tests: all 79 @for TARGET in $(TARGETS); do \ 80 BUILD_TARGET=$$BUILD/$$TARGET; \ 81 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ 82 done; 83 84hotplug: 85 @for TARGET in $(TARGETS_HOTPLUG); do \ 86 BUILD_TARGET=$$BUILD/$$TARGET; \ 87 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 88 done; 89 90run_hotplug: hotplug 91 @for TARGET in $(TARGETS_HOTPLUG); do \ 92 BUILD_TARGET=$$BUILD/$$TARGET; \ 93 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 94 done; 95 96clean_hotplug: 97 @for TARGET in $(TARGETS_HOTPLUG); do \ 98 BUILD_TARGET=$$BUILD/$$TARGET; \ 99 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 100 done; 101 102run_pstore_crash: 103 make -C pstore run_crash 104 105INSTALL_PATH ?= install 106INSTALL_PATH := $(abspath $(INSTALL_PATH)) 107ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 108 109install: 110ifdef INSTALL_PATH 111 @# Ask all targets to install their files 112 mkdir -p $(INSTALL_PATH) 113 @for TARGET in $(TARGETS); do \ 114 BUILD_TARGET=$$BUILD/$$TARGET; \ 115 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ 116 done; 117 118 @# Ask all targets to emit their test scripts 119 echo "#!/bin/sh" > $(ALL_SCRIPT) 120 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT) 121 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT) 122 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT) 123 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT) 124 echo " OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT) 125 echo " cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT) 126 echo "else" >> $(ALL_SCRIPT) 127 echo " OUTPUT=/dev/stdout" >> $(ALL_SCRIPT) 128 echo "fi" >> $(ALL_SCRIPT) 129 130 for TARGET in $(TARGETS); do \ 131 BUILD_TARGET=$$BUILD/$$TARGET; \ 132 echo "echo ; echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \ 133 echo "echo ========================================" >> $(ALL_SCRIPT); \ 134 echo "cd $$TARGET" >> $(ALL_SCRIPT); \ 135 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ 136 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ 137 done; 138 139 chmod u+x $(ALL_SCRIPT) 140else 141 $(error Error: set INSTALL_PATH to use install) 142endif 143 144clean: 145 @for TARGET in $(TARGETS); do \ 146 BUILD_TARGET=$$BUILD/$$TARGET; \ 147 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 148 done; 149 150.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean 151