Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / sched_ext / Makefile
blob0117622246007fda57f7fcec8ff71b4c6a351f95
1 # SPDX-License-Identifier: GPL-2.0
2 # Copyright (c) 2022 Meta Platforms, Inc. and affiliates.
3 include ../../../build/Build.include
4 include ../../../scripts/Makefile.arch
5 include ../../../scripts/Makefile.include
7 TEST_GEN_PROGS := runner
9 # override lib.mk's default rules
10 OVERRIDE_TARGETS := 1
11 include ../lib.mk
13 CURDIR := $(abspath .)
14 REPOROOT := $(abspath ../../../..)
15 TOOLSDIR := $(REPOROOT)/tools
16 LIBDIR := $(TOOLSDIR)/lib
17 BPFDIR := $(LIBDIR)/bpf
18 TOOLSINCDIR := $(TOOLSDIR)/include
19 BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
20 APIDIR := $(TOOLSINCDIR)/uapi
21 GENDIR := $(REPOROOT)/include/generated
22 GENHDR := $(GENDIR)/autoconf.h
23 SCXTOOLSDIR := $(TOOLSDIR)/sched_ext
24 SCXTOOLSINCDIR := $(TOOLSDIR)/sched_ext/include
26 OUTPUT_DIR := $(OUTPUT)/build
27 OBJ_DIR := $(OUTPUT_DIR)/obj
28 INCLUDE_DIR := $(OUTPUT_DIR)/include
29 BPFOBJ_DIR := $(OBJ_DIR)/libbpf
30 SCXOBJ_DIR := $(OBJ_DIR)/sched_ext
31 BPFOBJ := $(BPFOBJ_DIR)/libbpf.a
32 LIBBPF_OUTPUT := $(OBJ_DIR)/libbpf/libbpf.a
34 DEFAULT_BPFTOOL := $(OUTPUT_DIR)/host/sbin/bpftool
35 HOST_OBJ_DIR := $(OBJ_DIR)/host/bpftool
36 HOST_LIBBPF_OUTPUT := $(OBJ_DIR)/host/libbpf/
37 HOST_LIBBPF_DESTDIR := $(OUTPUT_DIR)/host/
38 HOST_DESTDIR := $(OUTPUT_DIR)/host/
40 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
41 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
42 ../../../../vmlinux \
43 /sys/kernel/btf/vmlinux \
44 /boot/vmlinux-$(shell uname -r)
45 VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
46 ifeq ($(VMLINUX_BTF),)
47 $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
48 endif
50 BPFTOOL ?= $(DEFAULT_BPFTOOL)
52 ifneq ($(wildcard $(GENHDR)),)
53 GENFLAGS := -DHAVE_GENHDR
54 endif
56 CFLAGS += -g -O2 -rdynamic -pthread -Wall -Werror $(GENFLAGS) \
57 -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
58 -I$(TOOLSINCDIR) -I$(APIDIR) -I$(CURDIR)/include -I$(SCXTOOLSINCDIR)
60 # Silence some warnings when compiled with clang
61 ifneq ($(LLVM),)
62 CFLAGS += -Wno-unused-command-line-argument
63 endif
65 LDFLAGS = -lelf -lz -lpthread -lzstd
67 IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
68 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
70 # Get Clang's default includes on this system, as opposed to those seen by
71 # '-target bpf'. This fixes "missing" files on some architectures/distros,
72 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
74 # Use '-idirafter': Don't interfere with include mechanics except where the
75 # build would have failed anyways.
76 define get_sys_includes
77 $(shell $(1) $(2) -v -E - </dev/null 2>&1 \
78 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
79 $(shell $(1) $(2) -dM -E - </dev/null | grep '__riscv_xlen ' | awk '{printf("-D__riscv_xlen=%d -D__BITS_PER_LONG=%d", $$3, $$3)}')
80 endef
82 ifneq ($(CROSS_COMPILE),)
83 CLANG_TARGET_ARCH = --target=$(notdir $(CROSS_COMPILE:%-=%))
84 endif
86 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG),$(CLANG_TARGET_ARCH))
88 BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) \
89 $(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) \
90 -I$(CURDIR)/include -I$(CURDIR)/include/bpf-compat \
91 -I$(INCLUDE_DIR) -I$(APIDIR) -I$(SCXTOOLSINCDIR) \
92 -I$(REPOROOT)/include \
93 $(CLANG_SYS_INCLUDES) \
94 -Wall -Wno-compare-distinct-pointer-types \
95 -Wno-incompatible-function-pointer-types \
96 -O2 -mcpu=v3
98 # sort removes libbpf duplicates when not cross-building
99 MAKE_DIRS := $(sort $(OBJ_DIR)/libbpf $(OBJ_DIR)/libbpf \
100 $(OBJ_DIR)/bpftool $(OBJ_DIR)/resolve_btfids \
101 $(HOST_OBJ_DIR) $(INCLUDE_DIR) $(SCXOBJ_DIR))
103 $(MAKE_DIRS):
104 $(call msg,MKDIR,,$@)
105 $(Q)mkdir -p $@
107 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
108 $(APIDIR)/linux/bpf.h \
109 | $(OBJ_DIR)/libbpf
110 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(OBJ_DIR)/libbpf/ \
111 ARCH=$(ARCH) CC="$(CC)" CROSS_COMPILE=$(CROSS_COMPILE) \
112 EXTRA_CFLAGS='-g -O0 -fPIC' \
113 DESTDIR=$(OUTPUT_DIR) prefix= all install_headers
115 $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
116 $(LIBBPF_OUTPUT) | $(HOST_OBJ_DIR)
117 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
118 ARCH= CROSS_COMPILE= CC=$(HOSTCC) LD=$(HOSTLD) \
119 EXTRA_CFLAGS='-g -O0' \
120 OUTPUT=$(HOST_OBJ_DIR)/ \
121 LIBBPF_OUTPUT=$(HOST_LIBBPF_OUTPUT) \
122 LIBBPF_DESTDIR=$(HOST_LIBBPF_DESTDIR) \
123 prefix= DESTDIR=$(HOST_DESTDIR) install-bin
125 $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR)
126 ifeq ($(VMLINUX_H),)
127 $(call msg,GEN,,$@)
128 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
129 else
130 $(call msg,CP,,$@)
131 $(Q)cp "$(VMLINUX_H)" $@
132 endif
134 $(SCXOBJ_DIR)/%.bpf.o: %.bpf.c $(INCLUDE_DIR)/vmlinux.h | $(BPFOBJ) $(SCXOBJ_DIR)
135 $(call msg,CLNG-BPF,,$(notdir $@))
136 $(Q)$(CLANG) $(BPF_CFLAGS) -target bpf -c $< -o $@
138 $(INCLUDE_DIR)/%.bpf.skel.h: $(SCXOBJ_DIR)/%.bpf.o $(INCLUDE_DIR)/vmlinux.h $(BPFTOOL) | $(INCLUDE_DIR)
139 $(eval sched=$(notdir $@))
140 $(call msg,GEN-SKEL,,$(sched))
141 $(Q)$(BPFTOOL) gen object $(<:.o=.linked1.o) $<
142 $(Q)$(BPFTOOL) gen object $(<:.o=.linked2.o) $(<:.o=.linked1.o)
143 $(Q)$(BPFTOOL) gen object $(<:.o=.linked3.o) $(<:.o=.linked2.o)
144 $(Q)diff $(<:.o=.linked2.o) $(<:.o=.linked3.o)
145 $(Q)$(BPFTOOL) gen skeleton $(<:.o=.linked3.o) name $(subst .bpf.skel.h,,$(sched)) > $@
146 $(Q)$(BPFTOOL) gen subskeleton $(<:.o=.linked3.o) name $(subst .bpf.skel.h,,$(sched)) > $(@:.skel.h=.subskel.h)
148 ################
149 # C schedulers #
150 ################
152 override define CLEAN
153 rm -rf $(OUTPUT_DIR)
154 rm -f $(TEST_GEN_PROGS)
155 endef
157 # Every testcase takes all of the BPF progs are dependencies by default. This
158 # allows testcases to load any BPF scheduler, which is useful for testcases
159 # that don't need their own prog to run their test.
160 all_test_bpfprogs := $(foreach prog,$(wildcard *.bpf.c),$(INCLUDE_DIR)/$(patsubst %.c,%.skel.h,$(prog)))
162 auto-test-targets := \
163 create_dsq \
164 enq_last_no_enq_fails \
165 enq_select_cpu_fails \
166 ddsp_bogus_dsq_fail \
167 ddsp_vtimelocal_fail \
168 dsp_local_on \
169 exit \
170 hotplug \
171 init_enable_count \
172 maximal \
173 maybe_null \
174 minimal \
175 prog_run \
176 reload_loop \
177 select_cpu_dfl \
178 select_cpu_dfl_nodispatch \
179 select_cpu_dispatch \
180 select_cpu_dispatch_bad_dsq \
181 select_cpu_dispatch_dbl_dsp \
182 select_cpu_vtime \
183 test_example \
185 testcase-targets := $(addsuffix .o,$(addprefix $(SCXOBJ_DIR)/,$(auto-test-targets)))
187 $(SCXOBJ_DIR)/runner.o: runner.c | $(SCXOBJ_DIR) $(BPFOBJ)
188 $(CC) $(CFLAGS) -c $< -o $@
190 # Create all of the test targets object files, whose testcase objects will be
191 # registered into the runner in ELF constructors.
193 # Note that we must do double expansion here in order to support conditionally
194 # compiling BPF object files only if one is present, as the wildcard Make
195 # function doesn't support using implicit rules otherwise.
196 $(testcase-targets): $(SCXOBJ_DIR)/%.o: %.c $(SCXOBJ_DIR)/runner.o $(all_test_bpfprogs) | $(SCXOBJ_DIR)
197 $(eval test=$(patsubst %.o,%.c,$(notdir $@)))
198 $(CC) $(CFLAGS) -c $< -o $@
200 $(SCXOBJ_DIR)/util.o: util.c | $(SCXOBJ_DIR)
201 $(CC) $(CFLAGS) -c $< -o $@
203 $(OUTPUT)/runner: $(SCXOBJ_DIR)/runner.o $(SCXOBJ_DIR)/util.o $(BPFOBJ) $(testcase-targets)
204 @echo "$(testcase-targets)"
205 $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
207 .DEFAULT_GOAL := all
209 .DELETE_ON_ERROR:
211 .SECONDARY: