blob: c45ae13b88a0a5bb7b6c8b431d433cf40e2b0d5b [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Ilya Leoshkevich9cae4ac2019-07-11 11:12:49 +02002include ../../../../scripts/Kbuild.include
Ilya Leoshkevich748e50c2019-07-11 16:29:27 +02003include ../../../scripts/Makefile.arch
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +01004include ../../../scripts/Makefile.include
Hendrik Brueckner618e1652017-12-04 10:56:48 +01005
Ilya Leoshkeviche7ad28e2020-06-02 19:56:49 +02006CXX ?= $(CROSS_COMPILE)g++
7
Andrii Nakryiko74b5a592019-10-15 23:00:49 -07008CURDIR := $(abspath .)
Andrii Nakryikof3c926a2019-12-13 17:43:38 -08009TOOLSDIR := $(abspath ../../..)
10LIBDIR := $(TOOLSDIR)/lib
Zi Shen Lime8f1f342017-03-19 23:03:14 -070011BPFDIR := $(LIBDIR)/bpf
Andrii Nakryikof3c926a2019-12-13 17:43:38 -080012TOOLSINCDIR := $(TOOLSDIR)/include
13BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
14APIDIR := $(TOOLSINCDIR)/uapi
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070015GENDIR := $(abspath ../../../../include/generated)
Daniel Borkmann02ea80b2017-03-31 02:24:04 +020016GENHDR := $(GENDIR)/autoconf.h
Mickaël Salaünd498f872017-02-11 23:20:23 +010017
Daniel Borkmann02ea80b2017-03-31 02:24:04 +020018ifneq ($(wildcard $(GENHDR)),)
19 GENFLAGS := -DHAVE_GENHDR
20endif
21
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +020022BPF_GCC ?= $(shell command -v bpf-gcc;)
Andrii Nakryiko02995dd2020-04-28 18:21:02 -070023SAN_CFLAGS ?=
Andrii Nakryiko252e3cb2021-03-13 13:09:20 -080024CFLAGS += -g -Og -rdynamic -Wall $(GENFLAGS) $(SAN_CFLAGS) \
Andrii Nakryiko02995dd2020-04-28 18:21:02 -070025 -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
Jean-Philippe Brucker5837ced2021-01-13 17:33:17 +010026 -I$(TOOLSINCDIR) -I$(APIDIR) -I$(OUTPUT) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070027 -Dbpf_prog_load=bpf_prog_test_load \
Jiong Wang9d120b42019-05-24 23:25:21 +010028 -Dbpf_load_program=bpf_test_load_program
Andrii Nakryiko166750b2019-12-13 17:47:08 -080029LDLIBS += -lcap -lelf -lz -lrt -lpthread
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020030
Yonghong Songef998582021-04-13 08:34:29 -070031# Silence some warnings when compiled with clang
32ifneq ($(LLVM),)
33CFLAGS += -Wno-unused-command-line-argument
34endif
35
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010036# Order correspond to 'make run_tests' order
David S. Miller18b3ad92017-05-10 11:43:51 -070037TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
Alexander Duyckaaf376b2020-11-03 13:34:48 -080038 test_verifier_log test_dev_cgroup \
Florent Revest61f8c9c2021-02-10 12:14:04 +010039 test_sock test_sockmap get_cgroup_id_user \
Jakub Sitnicki415bb4e2019-12-12 11:22:58 +010040 test_cgroup_storage \
Martin KaFai Lau6f521a22020-09-24 17:04:27 -070041 test_netcnt test_tcpnotify_user test_sysctl \
Carlos Neira09c02d52021-01-14 11:10:36 -030042 test_progs-no_alu32
Jiong Wang3ef84342019-01-26 12:26:14 -050043
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070044# Also test bpf-gcc, if present
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +020045ifneq ($(BPF_GCC),)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070046TEST_GEN_PROGS += test_progs-bpf_gcc
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +020047endif
48
Jean-Philippe Bruckerd6ac8ca2021-01-13 17:33:18 +010049TEST_GEN_FILES = test_lwt_ip_encap.o \
50 test_tc_edt.o
Jean-Philippe Bruckerb8d1cbe2021-01-13 17:33:20 +010051TEST_FILES = xsk_prereqs.sh \
52 $(wildcard progs/btf_dump_test_case_*.c)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070053
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010054# Order correspond to 'make run_tests' order
55TEST_PROGS := test_kmod.sh \
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010056 test_xdp_redirect.sh \
57 test_xdp_meta.sh \
Toshiaki Makita88091ff2019-06-20 11:23:23 +090058 test_xdp_veth.sh \
Andrey Ignatov622adaf2018-03-30 15:08:06 -070059 test_offload.py \
William Tu933a7412018-04-26 14:01:39 -070060 test_sock_addr.sh \
Mathieu Xhonneuxc99a84e2018-05-20 14:58:17 +010061 test_tunnel.sh \
Sean Young6bdd5332018-05-27 12:24:10 +010062 test_lwt_seg6local.sh \
Andrey Ignatov5ecd8c22018-08-12 10:49:30 -070063 test_lirc_mode2.sh \
Petar Penkov50b3ed52018-09-14 07:46:22 -070064 test_skb_cgroup_id.sh \
Jesper Dangaard Brouer97396ff2018-10-09 12:04:53 +020065 test_flow_dissector.sh \
Jesper Dangaard Brouerd35661f2019-08-01 20:00:21 +020066 test_xdp_vlan_mode_generic.sh \
67 test_xdp_vlan_mode_native.sh \
Lorenz Bauerbafc0ba2019-03-22 09:54:06 +080068 test_lwt_ip_encap.sh \
Willem de Bruijn98cdabc2019-03-22 14:32:49 -040069 test_tcp_check_syncookie.sh \
Peter Oskolkov7df5e3d2019-03-22 16:40:19 -070070 test_tc_tunnel.sh \
Alan Maguirecd538502019-05-31 18:47:14 +010071 test_tc_edt.sh \
Quentin Monnet45c5589d2019-08-30 12:00:38 +010072 test_xdping.sh \
Michal Rostecki736332742020-02-26 17:59:39 +010073 test_bpftool_build.sh \
YiFei Zhud42d1cc2020-09-15 16:45:43 -070074 test_bpftool.sh \
75 test_bpftool_metadata.sh \
Jean-Philippe Bruckera0d73ac2021-03-08 19:28:31 +010076 test_doc_build.sh \
Weqaar Janjuaa8905252020-12-07 21:53:29 +000077 test_xsk.sh
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020078
Anders Roxellf98937c2019-01-08 10:23:03 +010079TEST_PROGS_EXTENDED := with_addr.sh \
Stanislav Fomichev1be72f22019-01-14 09:41:41 -080080 with_tunnels.sh \
Anders Roxell3035bb72019-08-20 15:41:21 +020081 test_xdp_vlan.sh
Anders Roxellef4ab842018-10-10 16:27:04 +020082
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010083# Compile but not part of 'make run_tests'
Andrii Nakryikocb79a4e2019-10-15 23:00:51 -070084TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
Hangbin Liu25a79912019-06-04 10:35:05 +080085 flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
Weqaar Janjuafacb7cb2020-12-07 21:53:30 +000086 test_lirc_mode2_user xdping test_cpp runqslower bench bpf_testmod.ko \
87 xdpxceiver
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010088
Jean-Philippe Bruckerca1e8462021-01-13 17:33:19 +010089TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070090
Andrii Nakryiko92f74402019-12-16 22:14:25 -080091# Emit succinct information message describing current building step
92# $1 - generic step name (e.g., CC, LINK, etc);
93# $2 - optional "flavor" specifier; if provided, will be emitted as [flavor];
94# $3 - target (assumed to be file); only file name will be emitted;
95# $4 - optional extra arg, emitted as-is, if provided.
96ifeq ($(V),1)
Andrii Nakryiko965b9fe2020-01-09 21:17:16 -080097Q =
Andrii Nakryiko92f74402019-12-16 22:14:25 -080098msg =
99else
Andrii Nakryiko965b9fe2020-01-09 21:17:16 -0800100Q = @
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800101msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $(2), [$(2)])" "$(notdir $(3))" "$(if $(4), $(4))";
Andrii Nakryiko965b9fe2020-01-09 21:17:16 -0800102MAKEFLAGS += --no-print-directory
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800103submake_extras := feature_display=0
Andrii Nakryiko92f74402019-12-16 22:14:25 -0800104endif
105
106# override lib.mk's default rules
107OVERRIDE_TARGETS := 1
108override define CLEAN
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800109 $(call msg,CLEAN)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700110 $(Q)$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
Andrii Nakryiko9f7fa222020-12-03 12:46:26 -0800111 $(Q)$(MAKE) -C bpf_testmod clean
Joe Stringera01d9352021-03-02 09:19:43 -0800112 $(Q)$(MAKE) docs-clean
Andrii Nakryiko92f74402019-12-16 22:14:25 -0800113endef
114
Zi Shen Lime8f1f342017-03-19 23:03:14 -0700115include ../lib.mk
Alexei Starovoitov1da8ac72017-03-10 22:05:55 -0800116
Toke Høiland-Jørgensena2c96522020-01-20 14:06:52 +0100117SCRATCH_DIR := $(OUTPUT)/tools
118BUILD_DIR := $(SCRATCH_DIR)/build
119INCLUDE_DIR := $(SCRATCH_DIR)/include
120BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100121ifneq ($(CROSS_COMPILE),)
122HOST_BUILD_DIR := $(BUILD_DIR)/host
123HOST_SCRATCH_DIR := $(OUTPUT)/host-tools
124else
125HOST_BUILD_DIR := $(BUILD_DIR)
126HOST_SCRATCH_DIR := $(SCRATCH_DIR)
127endif
128HOST_BPFOBJ := $(HOST_BUILD_DIR)/libbpf/libbpf.a
129RESOLVE_BTFIDS := $(HOST_BUILD_DIR)/resolve_btfids/resolve_btfids
Toke Høiland-Jørgensena2c96522020-01-20 14:06:52 +0100130
Andrii Nakryikoa67079b2020-12-10 17:59:46 -0800131VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
132 $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
133 ../../../../vmlinux \
134 /sys/kernel/btf/vmlinux \
135 /boot/vmlinux-$(shell uname -r)
136VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
Kamal Mostafa1a3449c2020-12-15 10:20:10 -0800137ifeq ($(VMLINUX_BTF),)
138$(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
139endif
Andrii Nakryikoa67079b2020-12-10 17:59:46 -0800140
Andrii Nakryiko03dcb782019-10-15 23:00:48 -0700141# Define simple and short `make test_progs`, `make test_sysctl`, etc targets
142# to build individual tests.
143# NOTE: Semicolon at the end is critical to override lib.mk's default static
144# rule for binaries.
145$(notdir $(TEST_GEN_PROGS) \
146 $(TEST_PROGS) \
147 $(TEST_PROGS_EXTENDED) \
148 $(TEST_GEN_PROGS_EXTENDED) \
149 $(TEST_CUSTOM_PROGS)): %: $(OUTPUT)/% ;
150
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100151# sort removes libbpf duplicates when not cross-building
152MAKE_DIRS := $(sort $(BUILD_DIR)/libbpf $(HOST_BUILD_DIR)/libbpf \
153 $(HOST_BUILD_DIR)/bpftool $(HOST_BUILD_DIR)/resolve_btfids \
154 $(INCLUDE_DIR))
155$(MAKE_DIRS):
156 $(call msg,MKDIR,,$@)
157 $(Q)mkdir -p $@
158
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700159$(OUTPUT)/%.o: %.c
160 $(call msg,CC,,$@)
161 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
162
Andrii Nakryiko92f74402019-12-16 22:14:25 -0800163$(OUTPUT)/%:%.c
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800164 $(call msg,BINARY,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700165 $(Q)$(LINK.c) $^ $(LDLIBS) -o $@
Andrii Nakryiko92f74402019-12-16 22:14:25 -0800166
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700167$(OUTPUT)/urandom_read: urandom_read.c
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800168 $(call msg,BINARY,,$@)
Bill Wendlinga9684332020-09-22 16:21:40 -0700169 $(Q)$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS) -Wl,--build-id=sha1
Jiong Wang3ef84342019-01-26 12:26:14 -0500170
Andrii Nakryiko9f7fa222020-12-03 12:46:26 -0800171$(OUTPUT)/bpf_testmod.ko: $(VMLINUX_BTF) $(wildcard bpf_testmod/Makefile bpf_testmod/*.[ch])
172 $(call msg,MOD,,$@)
Andrii Nakryikoa67079b2020-12-10 17:59:46 -0800173 $(Q)$(RM) bpf_testmod/bpf_testmod.ko # force re-compilation
Andrii Nakryiko9f7fa222020-12-03 12:46:26 -0800174 $(Q)$(MAKE) $(submake_extras) -C bpf_testmod
175 $(Q)cp bpf_testmod/bpf_testmod.ko $@
176
Toke Høiland-Jørgensena2c96522020-01-20 14:06:52 +0100177$(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800178 $(call msg,CC,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700179 $(Q)$(CC) -c $(CFLAGS) -o $@ $<
Ilya Leoshkeviche93d9912019-10-28 11:21:10 +0100180
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100181DEFAULT_BPFTOOL := $(HOST_SCRATCH_DIR)/sbin/bpftool
Andrii Nakryiko6bcaf412020-08-04 17:47:57 -0700182
183$(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
Toke Høiland-Jørgensenbfe42792020-01-20 14:06:43 +0100184 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \
Toke Høiland-Jørgensena2c96522020-01-20 14:06:52 +0100185 OUTPUT=$(SCRATCH_DIR)/ VMLINUX_BTF=$(VMLINUX_BTF) \
Veronika Kabatovab26d1e22020-04-28 19:37:42 +0200186 BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) && \
187 cp $(SCRATCH_DIR)/runqslower $@
Zi Shen Lime8f1f342017-03-19 23:03:14 -0700188
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700189$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/test_stub.o $(BPFOBJ)
Joe Stringera01d9352021-03-02 09:19:43 -0800190$(TEST_GEN_FILES): docs
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +0100191
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +0100192$(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
Andrey Ignatov5ecd8c22018-08-12 10:49:30 -0700193$(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c
Andrey Ignatov1d436882018-03-30 15:08:08 -0700194$(OUTPUT)/test_sock: cgroup_helpers.c
Andrey Ignatove50b0a62018-03-30 15:08:03 -0700195$(OUTPUT)/test_sock_addr: cgroup_helpers.c
John Fastabend16962b22018-04-23 14:30:38 -0700196$(OUTPUT)/test_sockmap: cgroup_helpers.c
Sowmini Varadhan435f90a2018-11-07 16:12:02 -0800197$(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c
Yonghong Songf2690992018-06-03 15:59:43 -0700198$(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
Roman Gushchin68cfa3a2018-08-02 14:27:29 -0700199$(OUTPUT)/test_cgroup_storage: cgroup_helpers.c
Roman Gushchin371e4fc2018-09-28 14:46:00 +0000200$(OUTPUT)/test_netcnt: cgroup_helpers.c
Martin KaFai Laue0b27b32019-02-09 23:22:28 -0800201$(OUTPUT)/test_sock_fields: cgroup_helpers.c
Andrey Ignatov1f5fa9a2019-03-08 15:08:21 -0800202$(OUTPUT)/test_sysctl: cgroup_helpers.c
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +0100203
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800204BPFTOOL ?= $(DEFAULT_BPFTOOL)
Andrii Nakryiko03506292020-01-23 21:41:48 -0800205$(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100206 $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool
Andrii Nakryiko03506292020-01-23 21:41:48 -0800207 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100208 CC=$(HOSTCC) LD=$(HOSTLD) \
Andrii Nakryiko252e3cb2021-03-13 13:09:20 -0800209 EXTRA_CFLAGS='-g -Og' \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100210 OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \
211 prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install
Joe Stringera01d9352021-03-02 09:19:43 -0800212
213docs:
214 $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \
215 -f Makefile.docs \
216 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@
217
218docs-clean:
219 $(Q)$(MAKE) $(submake_extras) \
220 -f Makefile.docs \
221 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800222
Andrii Nakryiko03506292020-01-23 21:41:48 -0800223$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
Toke Høiland-Jørgensena2c96522020-01-20 14:06:52 +0100224 ../../../include/uapi/linux/bpf.h \
225 | $(INCLUDE_DIR) $(BUILD_DIR)/libbpf
226 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
Andrii Nakryiko252e3cb2021-03-13 13:09:20 -0800227 EXTRA_CFLAGS='-g -Og' \
Andrii Nakryiko03506292020-01-23 21:41:48 -0800228 DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800229
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100230ifneq ($(BPFOBJ),$(HOST_BPFOBJ))
231$(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
232 ../../../include/uapi/linux/bpf.h \
233 | $(INCLUDE_DIR) $(HOST_BUILD_DIR)/libbpf
234 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) \
Andrii Nakryiko252e3cb2021-03-13 13:09:20 -0800235 EXTRA_CFLAGS='-g -Og' \
236 OUTPUT=$(HOST_BUILD_DIR)/libbpf/ CC=$(HOSTCC) LD=$(HOSTLD) \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100237 DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers
238endif
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700239
Andrii Nakryikocab62c32021-03-18 12:40:34 -0700240$(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR)
Andrii Nakryikoca4db632020-06-29 17:47:59 -0700241ifeq ($(VMLINUX_H),)
Andrii Nakryikoacbd0622020-03-13 10:23:36 -0700242 $(call msg,GEN,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700243 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
Andrii Nakryikoca4db632020-06-29 17:47:59 -0700244else
245 $(call msg,CP,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700246 $(Q)cp "$(VMLINUX_H)" $@
Andrii Nakryikoca4db632020-06-29 17:47:59 -0700247endif
Andrii Nakryikoacbd0622020-03-13 10:23:36 -0700248
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100249$(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \
Jiri Olsacc15a202020-07-11 23:53:29 +0200250 $(TOOLSDIR)/bpf/resolve_btfids/main.c \
251 $(TOOLSDIR)/lib/rbtree.c \
252 $(TOOLSDIR)/lib/zalloc.c \
253 $(TOOLSDIR)/lib/string.c \
254 $(TOOLSDIR)/lib/ctype.c \
255 $(TOOLSDIR)/lib/str_error_r.c
256 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100257 CC=$(HOSTCC) LD=$(HOSTLD) AR=$(HOSTAR) \
258 OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ)
Jiri Olsacc15a202020-07-11 23:53:29 +0200259
Sirio Balmelli167381f2018-05-21 09:00:03 +0200260# Get Clang's default includes on this system, as opposed to those seen by
261# '-target bpf'. This fixes "missing" files on some architectures/distros,
262# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
263#
264# Use '-idirafter': Don't interfere with include mechanics except where the
265# build would have failed anyways.
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200266define get_sys_includes
267$(shell $(1) -v -E - </dev/null 2>&1 \
Björn Töpel6016df82020-11-18 08:16:38 +0100268 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
269$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/')
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200270endef
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700271
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100272# Determine target endianness.
273IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
274 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
275MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
276
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200277CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100278BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
Tobias Klauserbcd66b12020-03-13 12:31:05 +0100279 -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
280 -I$(abspath $(OUTPUT)/../usr/include)
Sirio Balmelli167381f2018-05-21 09:00:03 +0200281
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200282CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
283 -Wno-compare-distinct-pointer-types
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800284
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200285$(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
286$(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800287
Stanislav Fomichevbf0f0fd2019-01-28 08:53:55 -0800288$(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
Stanislav Fomichevbf0f0fd2019-01-28 08:53:55 -0800289
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700290# Build BPF object using Clang
291# $1 - input .c file
292# $2 - output .o file
293# $3 - CFLAGS
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700294define CLANG_BPF_BUILD_RULE
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000295 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
296 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700297endef
Andrii Nakryiko24f65052019-11-19 16:25:10 -0800298# Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
299define CLANG_NOALU32_BPF_BUILD_RULE
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800300 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000301 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700302endef
303# Build BPF object using GCC
304define GCC_BPF_BUILD_RULE
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800305 $(call msg,GCC-BPF,$(TRUNNER_BINARY),$2)
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000306 $(Q)$(BPF_GCC) $3 -O2 -c $1 -o $2
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700307endef
Stanislav Fomicheve78e00b2019-03-06 11:59:26 -0800308
Jakub Sitnicki0b9ad562020-04-29 20:11:54 +0200309SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800310
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700311LINKED_SKELS := test_static_linked.skel.h
312
313test_static_linked.skel.h-deps := test_static_linked1.o test_static_linked2.o
314
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700315# Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
316# $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
317# Parameters:
318# $1 - test runner base binary name (e.g., test_progs)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700319# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700320define DEFINE_TEST_RUNNER
Jiong Wang3ef84342019-01-26 12:26:14 -0500321
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700322TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
323TRUNNER_BINARY := $1$(if $2,-)$2
324TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
325 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
326TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
327 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
328TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
329TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800330TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
331TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS))
332TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
333 $$(filter-out $(SKEL_BLACKLIST), \
334 $$(TRUNNER_BPF_SRCS)))
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700335TRUNNER_BPF_SKELS_LINKED := $$(addprefix $$(TRUNNER_OUTPUT)/,$(LINKED_SKELS))
Yauheni Kaliuta309b81f2020-05-13 05:17:22 +0300336TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS)
Jiong Wang3ef84342019-01-26 12:26:14 -0500337
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700338# Evaluate rules now with extra TRUNNER_XXX variables above already defined
339$$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2))
Stanislav Fomichev3f306582019-03-01 19:42:13 -0800340
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700341endef
Jiong Wang3ef84342019-01-26 12:26:14 -0500342
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700343# Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and
344# set up by DEFINE_TEST_RUNNER itself, create test runner build rules with:
345# $1 - test runner base binary name (e.g., test_progs)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700346# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700347define DEFINE_TEST_RUNNER_RULES
348
349ifeq ($($(TRUNNER_OUTPUT)-dir),)
350$(TRUNNER_OUTPUT)-dir := y
351$(TRUNNER_OUTPUT):
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800352 $$(call msg,MKDIR,,$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700353 $(Q)mkdir -p $$@
Jiong Wang3ef84342019-01-26 12:26:14 -0500354endif
355
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700356# ensure we set up BPF objects generation rule just once for a given
357# input/output directory combination
358ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),)
359$(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y
360$(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \
361 $(TRUNNER_BPF_PROGS_DIR)/%.c \
362 $(TRUNNER_BPF_PROGS_DIR)/*.h \
Andrii Nakryikoacbd0622020-03-13 10:23:36 -0700363 $$(INCLUDE_DIR)/vmlinux.h \
Andrii Nakryiko3ac2e202020-08-20 16:12:35 -0700364 $(wildcard $(BPFDIR)/bpf_*.h) | $(TRUNNER_OUTPUT)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700365 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000366 $(TRUNNER_BPF_CFLAGS))
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800367
Andrii Nakryiko14137f32021-03-18 12:40:35 -0700368$(TRUNNER_BPF_SKELS): %.skel.h: %.o $(BPFTOOL) | $(TRUNNER_OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800369 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700370 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked1.o) $$<
371 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked2.o) $$(<:.o=.linked1.o)
Andrii Nakryiko14137f32021-03-18 12:40:35 -0700372 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked3.o) $$(<:.o=.linked2.o)
373 $(Q)diff $$(<:.o=.linked2.o) $$(<:.o=.linked3.o)
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700374 $(Q)$$(BPFTOOL) gen skeleton $$(<:.o=.linked3.o) name $$(notdir $$(<:.o=)) > $$@
375
376$(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_BPF_OBJS) $(BPFTOOL) | $(TRUNNER_OUTPUT)
377 $$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.o))
378 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked1.o) $$(addprefix $(TRUNNER_OUTPUT)/,$$($$(@F)-deps))
379 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked1.o)
380 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked3.o) $$(@:.skel.h=.linked2.o)
381 $(Q)diff $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked3.o)
382 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
383 $(Q)$$(BPFTOOL) gen skeleton $$(@:.skel.h=.linked3.o) name $$(notdir $$(@:.skel.h=)) > $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700384endif
385
386# ensure we set up tests.h header generation rule just once
387ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
388$(TRUNNER_TESTS_DIR)-tests-hdr := y
389$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800390 $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700391 $$(shell ( cd $(TRUNNER_TESTS_DIR); \
392 echo '/* Generated header, do not edit */'; \
393 ls *.c 2> /dev/null | \
394 sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \
395 ) > $$@)
396endif
397
398# compile individual test files
399# Note: we cd into output directory to ensure embedded BPF object is found
400$(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
401 $(TRUNNER_TESTS_DIR)/%.c \
402 $(TRUNNER_EXTRA_HDRS) \
403 $(TRUNNER_BPF_OBJS) \
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800404 $(TRUNNER_BPF_SKELS) \
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700405 $(TRUNNER_BPF_SKELS_LINKED) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700406 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800407 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700408 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700409
410$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
411 %.c \
412 $(TRUNNER_EXTRA_HDRS) \
413 $(TRUNNER_TESTS_HDR) \
414 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800415 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700416 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700417
Ilya Leoshkevich86fd1662021-02-24 12:14:45 +0100418# non-flavored in-srctree builds receive special treatment, in particular, we
419# do not need to copy extra resources (see e.g. test_btf_dump_case())
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700420$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
Ilya Leoshkevich86fd1662021-02-24 12:14:45 +0100421ifneq ($2:$(OUTPUT),:$(shell pwd))
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800422 $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES))
Ilya Leoshkevich86fd1662021-02-24 12:14:45 +0100423 $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700424endif
425
426$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
427 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \
Jiri Olsacc15a202020-07-11 23:53:29 +0200428 $(RESOLVE_BTFIDS) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700429 | $(TRUNNER_BINARY)-extras
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800430 $$(call msg,BINARY,,$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700431 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
Brendan Jackman58c185b2020-12-03 12:08:50 +0000432 $(Q)$(RESOLVE_BTFIDS) --no-fail --btf $(TRUNNER_OUTPUT)/btf_data.o $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700433
434endef
435
436# Define test_progs test runner.
437TRUNNER_TESTS_DIR := prog_tests
438TRUNNER_BPF_PROGS_DIR := progs
439TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \
Andrii Nakryikocd492912020-05-12 12:24:42 -0700440 network_helpers.c testing_helpers.c \
Andrii Nakryiko1306c982020-11-04 20:33:56 -0800441 btf_helpers.c flow_dissector_load.h
Andrii Nakryiko9f7fa222020-12-03 12:46:26 -0800442TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \
KP Singh854055c2020-11-26 18:49:46 +0000443 ima_setup.sh \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700444 $(wildcard progs/btf_dump_test_case_*.c)
445TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
Andrii Nakryiko6910d7d2020-01-09 21:17:15 -0800446TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
Brendan Jackman98d666d2021-01-14 18:17:50 +0000447TRUNNER_BPF_CFLAGS += -DENABLE_ATOMICS_TESTS
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700448$(eval $(call DEFINE_TEST_RUNNER,test_progs))
449
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700450# Define test_progs-no_alu32 test runner.
Andrii Nakryiko24f65052019-11-19 16:25:10 -0800451TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
Brendan Jackman98d666d2021-01-14 18:17:50 +0000452TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700453$(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700454
455# Define test_progs BPF-GCC-flavored test runner.
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200456ifneq ($(BPF_GCC),)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700457TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100458TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700459$(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200460endif
461
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700462# Define test_maps test runner.
463TRUNNER_TESTS_DIR := map_tests
464TRUNNER_BPF_PROGS_DIR := progs
465TRUNNER_EXTRA_SOURCES := test_maps.c
466TRUNNER_EXTRA_FILES :=
467TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
468TRUNNER_BPF_CFLAGS :=
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700469$(eval $(call DEFINE_TEST_RUNNER,test_maps))
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700470
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700471# Define test_verifier test runner.
472# It is much simpler than test_maps/test_progs and sufficiently different from
473# them (e.g., test.h is using completely pattern), that it's worth just
474# explicitly defining all the rules explicitly.
475verifier/tests.h: verifier/*.c
Stanislav Fomicheve78e00b2019-03-06 11:59:26 -0800476 $(shell ( cd verifier/; \
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800477 echo '/* Generated header, do not edit */'; \
478 echo '#ifdef FILL_ARRAY'; \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700479 ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800480 echo '#endif' \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700481 ) > verifier/tests.h)
482$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800483 $(call msg,BINARY,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700484 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800485
Stanislav Fomichev6bf6aff2019-12-02 13:59:31 -0800486# Make sure we are able to include and link libbpf against c++.
Andrii Nakryiko7c8dce42019-12-26 13:02:53 -0800487$(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800488 $(call msg,CXX,,$@)
Yonghong Songa22c0c82021-04-13 08:34:24 -0700489 $(Q)$(CXX) $(CFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
Stanislav Fomichev6bf6aff2019-12-02 13:59:31 -0800490
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700491# Benchmark runner
492$(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
493 $(call msg,CC,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700494 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
Andrii Nakryiko4eaf0b52020-05-12 12:24:44 -0700495$(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
Andrii Nakryikoc5d420c2020-05-12 12:24:45 -0700496$(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
Andrii Nakryikoc97099b2020-05-29 00:54:23 -0700497$(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \
498 $(OUTPUT)/perfbuf_bench.skel.h
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700499$(OUTPUT)/bench.o: bench.h testing_helpers.h
500$(OUTPUT)/bench: LDLIBS += -lm
501$(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
Andrii Nakryiko4eaf0b52020-05-12 12:24:44 -0700502 $(OUTPUT)/bench_count.o \
Andrii Nakryikoc5d420c2020-05-12 12:24:45 -0700503 $(OUTPUT)/bench_rename.o \
Andrii Nakryikoc97099b2020-05-29 00:54:23 -0700504 $(OUTPUT)/bench_trigger.o \
505 $(OUTPUT)/bench_ringbufs.o
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700506 $(call msg,BINARY,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700507 $(Q)$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700508
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100509EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700510 prog_tests/tests.h map_tests/tests.h verifier/tests.h \
Andrii Nakryiko2031af22020-01-09 21:17:14 -0800511 feature \
Andrii Nakryiko9f7fa222020-12-03 12:46:26 -0800512 $(addprefix $(OUTPUT)/,*.o *.skel.h no_alu32 bpf_gcc bpf_testmod.ko)
Joe Stringera01d9352021-03-02 09:19:43 -0800513
514.PHONY: docs docs-clean