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