Home | History | Annotate | Download | only in selftests
      1 # SPDX-License-Identifier: GPL-2.0
      2 TARGETS = android
      3 TARGETS += bpf
      4 TARGETS += breakpoints
      5 TARGETS += capabilities
      6 TARGETS += cgroup
      7 TARGETS += cpufreq
      8 TARGETS += cpu-hotplug
      9 TARGETS += efivarfs
     10 TARGETS += exec
     11 TARGETS += filesystems
     12 TARGETS += firmware
     13 TARGETS += ftrace
     14 TARGETS += futex
     15 TARGETS += gpio
     16 TARGETS += intel_pstate
     17 TARGETS += ipc
     18 TARGETS += kcmp
     19 TARGETS += kvm
     20 TARGETS += lib
     21 TARGETS += membarrier
     22 TARGETS += memfd
     23 TARGETS += memory-hotplug
     24 TARGETS += mount
     25 TARGETS += mqueue
     26 TARGETS += net
     27 TARGETS += netfilter
     28 TARGETS += nsfs
     29 TARGETS += powerpc
     30 TARGETS += proc
     31 TARGETS += pstore
     32 TARGETS += ptrace
     33 TARGETS += rseq
     34 TARGETS += rtc
     35 TARGETS += seccomp
     36 TARGETS += sigaltstack
     37 TARGETS += size
     38 TARGETS += sparc64
     39 TARGETS += splice
     40 TARGETS += static_keys
     41 TARGETS += sync
     42 TARGETS += sysctl
     43 ifneq (1, $(quicktest))
     44 TARGETS += timers
     45 endif
     46 TARGETS += user
     47 TARGETS += vm
     48 TARGETS += x86
     49 TARGETS += zram
     50 #Please keep the TARGETS list alphabetically sorted
     51 # Run "make quicktest=1 run_tests" or
     52 # "make quicktest=1 kselftest" from top level Makefile
     53 
     54 TARGETS_HOTPLUG = cpu-hotplug
     55 TARGETS_HOTPLUG += memory-hotplug
     56 
     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))
     61 override LDFLAGS =
     62 override MAKEFLAGS =
     63 endif
     64 
     65 ifneq ($(KBUILD_SRC),)
     66 override LDFLAGS =
     67 endif
     68 
     69 BUILD := $(O)
     70 ifndef BUILD
     71   BUILD := $(KBUILD_OUTPUT)
     72 endif
     73 ifndef BUILD
     74   BUILD := $(shell pwd)
     75 endif
     76 
     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`
     82 
     83 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;
     90 
     91 run_tests: all
     92 	@for TARGET in $(TARGETS); do \
     93 		BUILD_TARGET=$$BUILD/$$TARGET;	\
     94 		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_tests;\
     95 	done;
     96 
     97 hotplug:
     98 	@for TARGET in $(TARGETS_HOTPLUG); do \
     99 		BUILD_TARGET=$$BUILD/$$TARGET;	\
    100 		make OUTPUT=$$BUILD_TARGET -C $$TARGET;\
    101 	done;
    102 
    103 run_hotplug: hotplug
    104 	@for TARGET in $(TARGETS_HOTPLUG); do \
    105 		BUILD_TARGET=$$BUILD/$$TARGET;	\
    106 		make OUTPUT=$$BUILD_TARGET -C $$TARGET run_full_test;\
    107 	done;
    108 
    109 clean_hotplug:
    110 	@for TARGET in $(TARGETS_HOTPLUG); do \
    111 		BUILD_TARGET=$$BUILD/$$TARGET;	\
    112 		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
    113 	done;
    114 
    115 run_pstore_crash:
    116 	make -C pstore run_crash
    117 
    118 INSTALL_PATH ?= install
    119 INSTALL_PATH := $(abspath $(INSTALL_PATH))
    120 ALL_SCRIPT := $(INSTALL_PATH)/run_kselftest.sh
    121 
    122 install:
    123 ifdef INSTALL_PATH
    124 	@# 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 
    145 	for TARGET in $(TARGETS); do \
    146 		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;
    155 
    156 	chmod u+x $(ALL_SCRIPT)
    157 else
    158 	$(error Error: set INSTALL_PATH to use install)
    159 endif
    160 
    161 clean:
    162 	@for TARGET in $(TARGETS); do \
    163 		BUILD_TARGET=$$BUILD/$$TARGET;	\
    164 		make OUTPUT=$$BUILD_TARGET -C $$TARGET clean;\
    165 	done;
    166 
    167 .PHONY: all run_tests hotplug run_hotplug clean_hotplug run_pstore_crash install clean
    168