WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / Makefile
blobc51df6b91befe50b6740e6f25c05d503885b7c1f
1 # SPDX-License-Identifier: GPL-2.0
2 include ../../../../scripts/Kbuild.include
3 include ../../../scripts/Makefile.arch
5 CXX ?= $(CROSS_COMPILE)g++
7 CURDIR := $(abspath .)
8 TOOLSDIR := $(abspath ../../..)
9 LIBDIR := $(TOOLSDIR)/lib
10 BPFDIR := $(LIBDIR)/bpf
11 TOOLSINCDIR := $(TOOLSDIR)/include
12 BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
13 APIDIR := $(TOOLSINCDIR)/uapi
14 GENDIR := $(abspath ../../../../include/generated)
15 GENHDR := $(GENDIR)/autoconf.h
17 ifneq ($(wildcard $(GENHDR)),)
18 GENFLAGS := -DHAVE_GENHDR
19 endif
21 CLANG ?= clang
22 LLVM_OBJCOPY ?= llvm-objcopy
23 BPF_GCC ?= $(shell command -v bpf-gcc;)
24 SAN_CFLAGS ?=
25 CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) $(SAN_CFLAGS) \
26 -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
27 -I$(TOOLSINCDIR) -I$(APIDIR) \
28 -Dbpf_prog_load=bpf_prog_test_load \
29 -Dbpf_load_program=bpf_test_load_program
30 LDLIBS += -lcap -lelf -lz -lrt -lpthread
32 # Order correspond to 'make run_tests' order
33 TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
34 test_verifier_log test_dev_cgroup \
35 test_sock test_sockmap get_cgroup_id_user test_socket_cookie \
36 test_cgroup_storage \
37 test_netcnt test_tcpnotify_user test_sysctl \
38 test_progs-no_alu32 \
39 test_current_pid_tgid_new_ns
41 # Also test bpf-gcc, if present
42 ifneq ($(BPF_GCC),)
43 TEST_GEN_PROGS += test_progs-bpf_gcc
44 endif
46 TEST_GEN_FILES =
47 TEST_FILES = test_lwt_ip_encap.o \
48 test_tc_edt.o \
49 xsk_prereqs.sh
51 # Order correspond to 'make run_tests' order
52 TEST_PROGS := test_kmod.sh \
53 test_xdp_redirect.sh \
54 test_xdp_meta.sh \
55 test_xdp_veth.sh \
56 test_offload.py \
57 test_sock_addr.sh \
58 test_tunnel.sh \
59 test_lwt_seg6local.sh \
60 test_lirc_mode2.sh \
61 test_skb_cgroup_id.sh \
62 test_flow_dissector.sh \
63 test_xdp_vlan_mode_generic.sh \
64 test_xdp_vlan_mode_native.sh \
65 test_lwt_ip_encap.sh \
66 test_tcp_check_syncookie.sh \
67 test_tc_tunnel.sh \
68 test_tc_edt.sh \
69 test_xdping.sh \
70 test_bpftool_build.sh \
71 test_bpftool.sh \
72 test_bpftool_metadata.sh \
73 test_xsk.sh
75 TEST_PROGS_EXTENDED := with_addr.sh \
76 with_tunnels.sh \
77 test_xdp_vlan.sh
79 # Compile but not part of 'make run_tests'
80 TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
81 flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
82 test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \
83 xdpxceiver
85 TEST_CUSTOM_PROGS = urandom_read
87 # Emit succinct information message describing current building step
88 # $1 - generic step name (e.g., CC, LINK, etc);
89 # $2 - optional "flavor" specifier; if provided, will be emitted as [flavor];
90 # $3 - target (assumed to be file); only file name will be emitted;
91 # $4 - optional extra arg, emitted as-is, if provided.
92 ifeq ($(V),1)
93 Q =
94 msg =
95 else
96 Q = @
97 msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $(2), [$(2)])" "$(notdir $(3))" "$(if $(4), $(4))";
98 MAKEFLAGS += --no-print-directory
99 submake_extras := feature_display=0
100 endif
102 # override lib.mk's default rules
103 OVERRIDE_TARGETS := 1
104 override define CLEAN
105 $(call msg,CLEAN)
106 $(Q)$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
107 $(Q)$(MAKE) -C bpf_testmod clean
108 endef
110 include ../lib.mk
112 SCRATCH_DIR := $(OUTPUT)/tools
113 BUILD_DIR := $(SCRATCH_DIR)/build
114 INCLUDE_DIR := $(SCRATCH_DIR)/include
115 BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
116 RESOLVE_BTFIDS := $(BUILD_DIR)/resolve_btfids/resolve_btfids
118 VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
119 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
120 ../../../../vmlinux \
121 /sys/kernel/btf/vmlinux \
122 /boot/vmlinux-$(shell uname -r)
123 VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
124 ifeq ($(VMLINUX_BTF),)
125 $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
126 endif
128 # Define simple and short `make test_progs`, `make test_sysctl`, etc targets
129 # to build individual tests.
130 # NOTE: Semicolon at the end is critical to override lib.mk's default static
131 # rule for binaries.
132 $(notdir $(TEST_GEN_PROGS) \
133 $(TEST_PROGS) \
134 $(TEST_PROGS_EXTENDED) \
135 $(TEST_GEN_PROGS_EXTENDED) \
136 $(TEST_CUSTOM_PROGS)): %: $(OUTPUT)/% ;
138 $(OUTPUT)/%.o: %.c
139 $(call msg,CC,,$@)
140 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
142 $(OUTPUT)/%:%.c
143 $(call msg,BINARY,,$@)
144 $(Q)$(LINK.c) $^ $(LDLIBS) -o $@
146 $(OUTPUT)/urandom_read: urandom_read.c
147 $(call msg,BINARY,,$@)
148 $(Q)$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS) -Wl,--build-id=sha1
150 $(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
151 $(call msg,MOD,,$@)
152 $(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation
153 $(Q)$(MAKE) $(submake_extras) -C bpf_testmod
154 $(Q)cp bpf_testmod/bpf_testmod.ko $@
156 $(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ)
157 $(call msg,CC,,$@)
158 $(Q)$(CC) -c $(CFLAGS) -o $@ $<
160 DEFAULT_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool
162 $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
163 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \
164 OUTPUT=$(SCRATCH_DIR)/ VMLINUX_BTF=$(VMLINUX_BTF) \
165 BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) && \
166 cp $(SCRATCH_DIR)/runqslower $@
168 $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/test_stub.o $(BPFOBJ)
170 $(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
171 $(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c
172 $(OUTPUT)/test_sock: cgroup_helpers.c
173 $(OUTPUT)/test_sock_addr: cgroup_helpers.c
174 $(OUTPUT)/test_socket_cookie: cgroup_helpers.c
175 $(OUTPUT)/test_sockmap: cgroup_helpers.c
176 $(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c
177 $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
178 $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c
179 $(OUTPUT)/test_netcnt: cgroup_helpers.c
180 $(OUTPUT)/test_sock_fields: cgroup_helpers.c
181 $(OUTPUT)/test_sysctl: cgroup_helpers.c
183 BPFTOOL ?= $(DEFAULT_BPFTOOL)
184 $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
185 $(BPFOBJ) | $(BUILD_DIR)/bpftool
186 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
187 OUTPUT=$(BUILD_DIR)/bpftool/ \
188 prefix= DESTDIR=$(SCRATCH_DIR)/ install
189 $(Q)mkdir -p $(BUILD_DIR)/bpftool/Documentation
190 $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \
191 -C $(BPFTOOLDIR)/Documentation \
192 OUTPUT=$(BUILD_DIR)/bpftool/Documentation/ \
193 prefix= DESTDIR=$(SCRATCH_DIR)/ install
195 $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
196 ../../../include/uapi/linux/bpf.h \
197 | $(INCLUDE_DIR) $(BUILD_DIR)/libbpf
198 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
199 DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
201 $(BUILD_DIR)/libbpf $(BUILD_DIR)/bpftool $(BUILD_DIR)/resolve_btfids $(INCLUDE_DIR):
202 $(call msg,MKDIR,,$@)
203 $(Q)mkdir -p $@
205 $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) | $(BPFTOOL) $(INCLUDE_DIR)
206 ifeq ($(VMLINUX_H),)
207 $(call msg,GEN,,$@)
208 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
209 else
210 $(call msg,CP,,$@)
211 $(Q)cp "$(VMLINUX_H)" $@
212 endif
214 $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids \
215 $(TOOLSDIR)/bpf/resolve_btfids/main.c \
216 $(TOOLSDIR)/lib/rbtree.c \
217 $(TOOLSDIR)/lib/zalloc.c \
218 $(TOOLSDIR)/lib/string.c \
219 $(TOOLSDIR)/lib/ctype.c \
220 $(TOOLSDIR)/lib/str_error_r.c
221 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \
222 OUTPUT=$(BUILD_DIR)/resolve_btfids/ BPFOBJ=$(BPFOBJ)
224 # Get Clang's default includes on this system, as opposed to those seen by
225 # '-target bpf'. This fixes "missing" files on some architectures/distros,
226 # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
228 # Use '-idirafter': Don't interfere with include mechanics except where the
229 # build would have failed anyways.
230 define get_sys_includes
231 $(shell $(1) -v -E - </dev/null 2>&1 \
232 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
233 $(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/')
234 endef
236 # Determine target endianness.
237 IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
238 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
239 MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
241 CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
242 BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
243 -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
244 -I$(abspath $(OUTPUT)/../usr/include)
246 CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
247 -Wno-compare-distinct-pointer-types
249 $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
250 $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
252 $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
254 # Build BPF object using Clang
255 # $1 - input .c file
256 # $2 - output .o file
257 # $3 - CFLAGS
258 define CLANG_BPF_BUILD_RULE
259 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
260 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3
261 endef
262 # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
263 define CLANG_NOALU32_BPF_BUILD_RULE
264 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
265 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2
266 endef
267 # Build BPF object using GCC
268 define GCC_BPF_BUILD_RULE
269 $(call msg,GCC-BPF,$(TRUNNER_BINARY),$2)
270 $(Q)$(BPF_GCC) $3 -O2 -c $1 -o $2
271 endef
273 SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
275 # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
276 # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
277 # Parameters:
278 # $1 - test runner base binary name (e.g., test_progs)
279 # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
280 define DEFINE_TEST_RUNNER
282 TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
283 TRUNNER_BINARY := $1$(if $2,-)$2
284 TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
285 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
286 TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
287 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
288 TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
289 TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
290 TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
291 TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS))
292 TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
293 $$(filter-out $(SKEL_BLACKLIST), \
294 $$(TRUNNER_BPF_SRCS)))
295 TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS)
297 # Evaluate rules now with extra TRUNNER_XXX variables above already defined
298 $$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2))
300 endef
302 # Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and
303 # set up by DEFINE_TEST_RUNNER itself, create test runner build rules with:
304 # $1 - test runner base binary name (e.g., test_progs)
305 # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
306 define DEFINE_TEST_RUNNER_RULES
308 ifeq ($($(TRUNNER_OUTPUT)-dir),)
309 $(TRUNNER_OUTPUT)-dir := y
310 $(TRUNNER_OUTPUT):
311 $$(call msg,MKDIR,,$$@)
312 $(Q)mkdir -p $$@
313 endif
315 # ensure we set up BPF objects generation rule just once for a given
316 # input/output directory combination
317 ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),)
318 $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y
319 $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \
320 $(TRUNNER_BPF_PROGS_DIR)/%.c \
321 $(TRUNNER_BPF_PROGS_DIR)/*.h \
322 $$(INCLUDE_DIR)/vmlinux.h \
323 $(wildcard $(BPFDIR)/bpf_*.h) | $(TRUNNER_OUTPUT)
324 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \
325 $(TRUNNER_BPF_CFLAGS))
327 $(TRUNNER_BPF_SKELS): $(TRUNNER_OUTPUT)/%.skel.h: \
328 $(TRUNNER_OUTPUT)/%.o \
329 | $(BPFTOOL) $(TRUNNER_OUTPUT)
330 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
331 $(Q)$$(BPFTOOL) gen skeleton $$< > $$@
332 endif
334 # ensure we set up tests.h header generation rule just once
335 ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
336 $(TRUNNER_TESTS_DIR)-tests-hdr := y
337 $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
338 $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
339 $$(shell ( cd $(TRUNNER_TESTS_DIR); \
340 echo '/* Generated header, do not edit */'; \
341 ls *.c 2> /dev/null | \
342 sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \
343 ) > $$@)
344 endif
346 # compile individual test files
347 # Note: we cd into output directory to ensure embedded BPF object is found
348 $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
349 $(TRUNNER_TESTS_DIR)/%.c \
350 $(TRUNNER_EXTRA_HDRS) \
351 $(TRUNNER_BPF_OBJS) \
352 $(TRUNNER_BPF_SKELS) \
353 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
354 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
355 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
357 $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
358 %.c \
359 $(TRUNNER_EXTRA_HDRS) \
360 $(TRUNNER_TESTS_HDR) \
361 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
362 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
363 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
365 # only copy extra resources if in flavored build
366 $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
367 ifneq ($2,)
368 $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES))
369 $(Q)cp -a $$^ $(TRUNNER_OUTPUT)/
370 endif
372 $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
373 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \
374 $(RESOLVE_BTFIDS) \
375 | $(TRUNNER_BINARY)-extras
376 $$(call msg,BINARY,,$$@)
377 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
378 $(Q)$(RESOLVE_BTFIDS) --no-fail --btf $(TRUNNER_OUTPUT)/btf_data.o $$@
380 endef
382 # Define test_progs test runner.
383 TRUNNER_TESTS_DIR := prog_tests
384 TRUNNER_BPF_PROGS_DIR := progs
385 TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \
386 network_helpers.c testing_helpers.c \
387 btf_helpers.c flow_dissector_load.h
388 TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \
389 ima_setup.sh \
390 $(wildcard progs/btf_dump_test_case_*.c)
391 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
392 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
393 $(eval $(call DEFINE_TEST_RUNNER,test_progs))
395 # Define test_progs-no_alu32 test runner.
396 TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
397 $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
399 # Define test_progs BPF-GCC-flavored test runner.
400 ifneq ($(BPF_GCC),)
401 TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
402 TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
403 $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
404 endif
406 # Define test_maps test runner.
407 TRUNNER_TESTS_DIR := map_tests
408 TRUNNER_BPF_PROGS_DIR := progs
409 TRUNNER_EXTRA_SOURCES := test_maps.c
410 TRUNNER_EXTRA_FILES :=
411 TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
412 TRUNNER_BPF_CFLAGS :=
413 $(eval $(call DEFINE_TEST_RUNNER,test_maps))
415 # Define test_verifier test runner.
416 # It is much simpler than test_maps/test_progs and sufficiently different from
417 # them (e.g., test.h is using completely pattern), that it's worth just
418 # explicitly defining all the rules explicitly.
419 verifier/tests.h: verifier/*.c
420 $(shell ( cd verifier/; \
421 echo '/* Generated header, do not edit */'; \
422 echo '#ifdef FILL_ARRAY'; \
423 ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
424 echo '#endif' \
425 ) > verifier/tests.h)
426 $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
427 $(call msg,BINARY,,$@)
428 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
430 # Make sure we are able to include and link libbpf against c++.
431 $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
432 $(call msg,CXX,,$@)
433 $(Q)$(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@
435 # Benchmark runner
436 $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
437 $(call msg,CC,,$@)
438 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
439 $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
440 $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
441 $(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \
442 $(OUTPUT)/perfbuf_bench.skel.h
443 $(OUTPUT)/bench.o: bench.h testing_helpers.h
444 $(OUTPUT)/bench: LDLIBS += -lm
445 $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
446 $(OUTPUT)/bench_count.o \
447 $(OUTPUT)/bench_rename.o \
448 $(OUTPUT)/bench_trigger.o \
449 $(OUTPUT)/bench_ringbufs.o
450 $(call msg,BINARY,,$@)
451 $(Q)$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
453 EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) \
454 prog_tests/tests.h map_tests/tests.h verifier/tests.h \
455 feature \
456 $(addprefix $(OUTPUT)/,*.o *.skel.h no_alu32 bpf_gcc bpf_testmod.ko)