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 += kvm 19TARGETS += lib 20TARGETS += membarrier 21TARGETS += memfd 22TARGETS += memory-hotplug 23TARGETS += mount 24TARGETS += mqueue 25TARGETS += net 26TARGETS += nsfs 27TARGETS += powerpc 28TARGETS += proc 29TARGETS += pstore 30TARGETS += ptrace 31TARGETS += seccomp 32TARGETS += sigaltstack 33TARGETS += size 34TARGETS += splice 35TARGETS += static_keys 36TARGETS += sync 37TARGETS += sysctl 38ifneq (1, $(quicktest)) 39TARGETS += timers 40endif 41TARGETS += user 42TARGETS += vm 43TARGETS += x86 44TARGETS += zram 45#Please keep the TARGETS list alphabetically sorted 46# Run "make quicktest=1 run_tests" or 47# "make quicktest=1 kselftest" from top level Makefile 48 49TARGETS_HOTPLUG = cpu-hotplug 50TARGETS_HOTPLUG += memory-hotplug 51 52# Clear LDFLAGS and MAKEFLAGS if called from main 53# Makefile to avoid test build failures when test 54# Makefile doesn't have explicit build rules. 55ifeq (1,$(MAKELEVEL)) 56override LDFLAGS = 57override MAKEFLAGS = 58endif 59 60ifneq ($(KBUILD_SRC),) 61override LDFLAGS = 62endif 63 64BUILD := $(O) 65ifndef BUILD 66 BUILD := $(KBUILD_OUTPUT) 67endif 68ifndef BUILD 69 BUILD := $(shell pwd) 70endif 71 72# KSFT_TAP_LEVEL is used from KSFT framework to prevent nested TAP header 73# printing from tests. Applicable to run_tests case where run_tests adds 74# TAP header prior running tests and when a test program invokes another 75# with system() call. Export it here to cover override RUN_TESTS defines. 76export KSFT_TAP_LEVEL=`echo 1` 77 78export BUILD 79all: 80 @for TARGET in $(TARGETS); do \ 81 BUILD_TARGET=$$BUILD/$$TARGET; \ 82 mkdir $$BUILD_TARGET -p; \ 83 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 84 done; 85 86run_tests: all 87 @for TARGET in $(TARGETS); do \ 88 BUILD_TARGET=$$BUILD/$$TARGET; \ 89 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\ 90 done; 91 92hotplug: 93 @for TARGET in $(TARGETS_HOTPLUG); do \ 94 BUILD_TARGET=$$BUILD/$$TARGET; \ 95 make OUTPUT=$$BUILD_TARGET -C $$TARGET;\ 96 done; 97 98run_hotplug: hotplug 99 @for TARGET in $(TARGETS_HOTPLUG); do \ 100 BUILD_TARGET=$$BUILD/$$TARGET; \ 101 make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\ 102 done; 103 104clean_hotplug: 105 @for TARGET in $(TARGETS_HOTPLUG); do \ 106 BUILD_TARGET=$$BUILD/$$TARGET; \ 107 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 108 done; 109 110run_pstore_crash: 111 make -C pstore run_crash 112 113INSTALL_PATH ?= install 114INSTALL_PATH := $(abspath $(INSTALL_PATH)) 115ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh 116 117install: 118ifdef INSTALL_PATH 119 @# Ask all targets to install their files 120 mkdir -p $(INSTALL_PATH) 121 @for TARGET in $(TARGETS); do \ 122 BUILD_TARGET=$$BUILD/$$TARGET; \ 123 make OUTPUT=$$BUILD_TARGET -C $$TARGET INSTALL_PATH=$(INSTALL_PATH)/$$TARGET install; \ 124 done; 125 126 @# Ask all targets to emit their test scripts 127 echo "#!/bin/sh" > $(ALL_SCRIPT) 128 echo "BASE_DIR=\$$(realpath \$$(dirname \$$0))" >> $(ALL_SCRIPT) 129 echo "cd \$$BASE_DIR" >> $(ALL_SCRIPT) 130 echo "ROOT=\$$PWD" >> $(ALL_SCRIPT) 131 echo "if [ \"\$$1\" = \"--summary\" ]; then" >> $(ALL_SCRIPT) 132 echo " OUTPUT=\$$BASE_DIR/output.log" >> $(ALL_SCRIPT) 133 echo " cat /dev/null > \$$OUTPUT" >> $(ALL_SCRIPT) 134 echo "else" >> $(ALL_SCRIPT) 135 echo " OUTPUT=/dev/stdout" >> $(ALL_SCRIPT) 136 echo "fi" >> $(ALL_SCRIPT) 137 echo "export KSFT_TAP_LEVEL=`echo 1`" >> $(ALL_SCRIPT) 138 139 for TARGET in $(TARGETS); do \ 140 BUILD_TARGET=$$BUILD/$$TARGET; \ 141 echo "echo ; echo TAP version 13" >> $(ALL_SCRIPT); \ 142 echo "echo Running tests in $$TARGET" >> $(ALL_SCRIPT); \ 143 echo "echo ========================================" >> $(ALL_SCRIPT); \ 144 echo "[ -w /dev/kmsg ] && echo \"kselftest: Running tests in $$TARGET\" >> /dev/kmsg" >> $(ALL_SCRIPT); \ 145 echo "cd $$TARGET" >> $(ALL_SCRIPT); \ 146 make -s --no-print-directory OUTPUT=$$BUILD_TARGET -C $$TARGET emit_tests >> $(ALL_SCRIPT); \ 147 echo "cd \$$ROOT" >> $(ALL_SCRIPT); \ 148 done; 149 150 chmod u+x $(ALL_SCRIPT) 151else 152 $(error Error: set INSTALL_PATH to use install) 153endif 154 155clean: 156 @for TARGET in $(TARGETS); do \ 157 BUILD_TARGET=$$BUILD/$$TARGET; \ 158 make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\ 159 done; 160 161.PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean 162