blob: c5bcdb3d4b121287c6967e862146bf52cf40ac23 [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)
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +0100190
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +0100191$(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
Andrey Ignatov5ecd8c22018-08-12 10:49:30 -0700192$(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c
Andrey Ignatov1d436882018-03-30 15:08:08 -0700193$(OUTPUT)/test_sock: cgroup_helpers.c
Andrey Ignatove50b0a62018-03-30 15:08:03 -0700194$(OUTPUT)/test_sock_addr: cgroup_helpers.c
John Fastabend16962b22018-04-23 14:30:38 -0700195$(OUTPUT)/test_sockmap: cgroup_helpers.c
Sowmini Varadhan435f90a2018-11-07 16:12:02 -0800196$(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c
Yonghong Songf2690992018-06-03 15:59:43 -0700197$(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
Roman Gushchin68cfa3a2018-08-02 14:27:29 -0700198$(OUTPUT)/test_cgroup_storage: cgroup_helpers.c
Roman Gushchin371e4fc2018-09-28 14:46:00 +0000199$(OUTPUT)/test_netcnt: cgroup_helpers.c
Martin KaFai Laue0b27b32019-02-09 23:22:28 -0800200$(OUTPUT)/test_sock_fields: cgroup_helpers.c
Andrey Ignatov1f5fa9a2019-03-08 15:08:21 -0800201$(OUTPUT)/test_sysctl: cgroup_helpers.c
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +0100202
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800203BPFTOOL ?= $(DEFAULT_BPFTOOL)
Andrii Nakryiko03506292020-01-23 21:41:48 -0800204$(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100205 $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool
Andrii Nakryiko03506292020-01-23 21:41:48 -0800206 $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100207 CC=$(HOSTCC) LD=$(HOSTLD) \
Andrii Nakryiko252e3cb2021-03-13 13:09:20 -0800208 EXTRA_CFLAGS='-g -Og' \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100209 OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \
210 prefix= DESTDIR=$(HOST_SCRATCH_DIR)/ install
Joe Stringera01d9352021-03-02 09:19:43 -0800211
Jiri Olsad044d9f2021-04-20 15:24:28 +0200212all: docs
213
Joe Stringera01d9352021-03-02 09:19:43 -0800214docs:
215 $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \
216 -f Makefile.docs \
217 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@
218
219docs-clean:
220 $(Q)$(MAKE) $(submake_extras) \
221 -f Makefile.docs \
222 prefix= OUTPUT=$(OUTPUT)/ DESTDIR=$(OUTPUT)/ $@
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800223
Andrii Nakryiko03506292020-01-23 21:41:48 -0800224$(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
Toke Høiland-Jørgensena2c96522020-01-20 14:06:52 +0100225 ../../../include/uapi/linux/bpf.h \
226 | $(INCLUDE_DIR) $(BUILD_DIR)/libbpf
227 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
Andrii Nakryiko252e3cb2021-03-13 13:09:20 -0800228 EXTRA_CFLAGS='-g -Og' \
Andrii Nakryiko03506292020-01-23 21:41:48 -0800229 DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800230
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100231ifneq ($(BPFOBJ),$(HOST_BPFOBJ))
232$(HOST_BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
233 ../../../include/uapi/linux/bpf.h \
234 | $(INCLUDE_DIR) $(HOST_BUILD_DIR)/libbpf
235 $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) \
Andrii Nakryiko252e3cb2021-03-13 13:09:20 -0800236 EXTRA_CFLAGS='-g -Og' \
237 OUTPUT=$(HOST_BUILD_DIR)/libbpf/ CC=$(HOSTCC) LD=$(HOSTLD) \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100238 DESTDIR=$(HOST_SCRATCH_DIR)/ prefix= all install_headers
239endif
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700240
Andrii Nakryikocab62c32021-03-18 12:40:34 -0700241$(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR)
Andrii Nakryikoca4db632020-06-29 17:47:59 -0700242ifeq ($(VMLINUX_H),)
Andrii Nakryikoacbd0622020-03-13 10:23:36 -0700243 $(call msg,GEN,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700244 $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
Andrii Nakryikoca4db632020-06-29 17:47:59 -0700245else
246 $(call msg,CP,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700247 $(Q)cp "$(VMLINUX_H)" $@
Andrii Nakryikoca4db632020-06-29 17:47:59 -0700248endif
Andrii Nakryikoacbd0622020-03-13 10:23:36 -0700249
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100250$(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \
Jiri Olsacc15a202020-07-11 23:53:29 +0200251 $(TOOLSDIR)/bpf/resolve_btfids/main.c \
252 $(TOOLSDIR)/lib/rbtree.c \
253 $(TOOLSDIR)/lib/zalloc.c \
254 $(TOOLSDIR)/lib/string.c \
255 $(TOOLSDIR)/lib/ctype.c \
256 $(TOOLSDIR)/lib/str_error_r.c
257 $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100258 CC=$(HOSTCC) LD=$(HOSTLD) AR=$(HOSTAR) \
259 OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ)
Jiri Olsacc15a202020-07-11 23:53:29 +0200260
Sirio Balmelli167381f2018-05-21 09:00:03 +0200261# Get Clang's default includes on this system, as opposed to those seen by
262# '-target bpf'. This fixes "missing" files on some architectures/distros,
263# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
264#
265# Use '-idirafter': Don't interfere with include mechanics except where the
266# build would have failed anyways.
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200267define get_sys_includes
268$(shell $(1) -v -E - </dev/null 2>&1 \
Björn Töpel6016df82020-11-18 08:16:38 +0100269 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
270$(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/')
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200271endef
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700272
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100273# Determine target endianness.
274IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
275 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
276MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
277
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200278CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100279BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
Tobias Klauserbcd66b12020-03-13 12:31:05 +0100280 -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
281 -I$(abspath $(OUTPUT)/../usr/include)
Sirio Balmelli167381f2018-05-21 09:00:03 +0200282
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200283CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
284 -Wno-compare-distinct-pointer-types
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800285
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200286$(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
287$(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800288
Stanislav Fomichevbf0f0fd2019-01-28 08:53:55 -0800289$(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
Stanislav Fomichevbf0f0fd2019-01-28 08:53:55 -0800290
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700291# Build BPF object using Clang
292# $1 - input .c file
293# $2 - output .o file
294# $3 - CFLAGS
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700295define CLANG_BPF_BUILD_RULE
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000296 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
297 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v3
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700298endef
Andrii Nakryiko24f65052019-11-19 16:25:10 -0800299# Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
300define CLANG_NOALU32_BPF_BUILD_RULE
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800301 $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000302 $(Q)$(CLANG) $3 -O2 -target bpf -c $1 -o $2 -mcpu=v2
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700303endef
304# Build BPF object using GCC
305define GCC_BPF_BUILD_RULE
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800306 $(call msg,GCC-BPF,$(TRUNNER_BINARY),$2)
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000307 $(Q)$(BPF_GCC) $3 -O2 -c $1 -o $2
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700308endef
Stanislav Fomicheve78e00b2019-03-06 11:59:26 -0800309
Jakub Sitnicki0b9ad562020-04-29 20:11:54 +0200310SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800311
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700312LINKED_SKELS := test_static_linked.skel.h
313
314test_static_linked.skel.h-deps := test_static_linked1.o test_static_linked2.o
315
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700316# Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
317# $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
318# Parameters:
319# $1 - test runner base binary name (e.g., test_progs)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700320# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700321define DEFINE_TEST_RUNNER
Jiong Wang3ef84342019-01-26 12:26:14 -0500322
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700323TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
324TRUNNER_BINARY := $1$(if $2,-)$2
325TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
326 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
327TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
328 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
329TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
330TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800331TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
332TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS))
333TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
334 $$(filter-out $(SKEL_BLACKLIST), \
335 $$(TRUNNER_BPF_SRCS)))
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700336TRUNNER_BPF_SKELS_LINKED := $$(addprefix $$(TRUNNER_OUTPUT)/,$(LINKED_SKELS))
Yauheni Kaliuta309b81f2020-05-13 05:17:22 +0300337TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS)
Jiong Wang3ef84342019-01-26 12:26:14 -0500338
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700339# Evaluate rules now with extra TRUNNER_XXX variables above already defined
340$$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2))
Stanislav Fomichev3f306582019-03-01 19:42:13 -0800341
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700342endef
Jiong Wang3ef84342019-01-26 12:26:14 -0500343
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700344# Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and
345# set up by DEFINE_TEST_RUNNER itself, create test runner build rules with:
346# $1 - test runner base binary name (e.g., test_progs)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700347# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700348define DEFINE_TEST_RUNNER_RULES
349
350ifeq ($($(TRUNNER_OUTPUT)-dir),)
351$(TRUNNER_OUTPUT)-dir := y
352$(TRUNNER_OUTPUT):
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800353 $$(call msg,MKDIR,,$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700354 $(Q)mkdir -p $$@
Jiong Wang3ef84342019-01-26 12:26:14 -0500355endif
356
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700357# ensure we set up BPF objects generation rule just once for a given
358# input/output directory combination
359ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),)
360$(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y
361$(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \
362 $(TRUNNER_BPF_PROGS_DIR)/%.c \
363 $(TRUNNER_BPF_PROGS_DIR)/*.h \
Andrii Nakryikoacbd0622020-03-13 10:23:36 -0700364 $$(INCLUDE_DIR)/vmlinux.h \
Andrii Nakryiko3ac2e202020-08-20 16:12:35 -0700365 $(wildcard $(BPFDIR)/bpf_*.h) | $(TRUNNER_OUTPUT)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700366 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \
Andrew Delgadillo89ad7422020-12-11 00:43:44 +0000367 $(TRUNNER_BPF_CFLAGS))
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800368
Andrii Nakryiko14137f32021-03-18 12:40:35 -0700369$(TRUNNER_BPF_SKELS): %.skel.h: %.o $(BPFTOOL) | $(TRUNNER_OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800370 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700371 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked1.o) $$<
372 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked2.o) $$(<:.o=.linked1.o)
Andrii Nakryiko14137f32021-03-18 12:40:35 -0700373 $(Q)$$(BPFTOOL) gen object $$(<:.o=.linked3.o) $$(<:.o=.linked2.o)
374 $(Q)diff $$(<:.o=.linked2.o) $$(<:.o=.linked3.o)
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700375 $(Q)$$(BPFTOOL) gen skeleton $$(<:.o=.linked3.o) name $$(notdir $$(<:.o=)) > $$@
376
377$(TRUNNER_BPF_SKELS_LINKED): $(TRUNNER_BPF_OBJS) $(BPFTOOL) | $(TRUNNER_OUTPUT)
378 $$(call msg,LINK-BPF,$(TRUNNER_BINARY),$$(@:.skel.h=.o))
379 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked1.o) $$(addprefix $(TRUNNER_OUTPUT)/,$$($$(@F)-deps))
380 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked1.o)
381 $(Q)$$(BPFTOOL) gen object $$(@:.skel.h=.linked3.o) $$(@:.skel.h=.linked2.o)
382 $(Q)diff $$(@:.skel.h=.linked2.o) $$(@:.skel.h=.linked3.o)
383 $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
384 $(Q)$$(BPFTOOL) gen skeleton $$(@:.skel.h=.linked3.o) name $$(notdir $$(@:.skel.h=)) > $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700385endif
386
387# ensure we set up tests.h header generation rule just once
388ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
389$(TRUNNER_TESTS_DIR)-tests-hdr := y
390$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800391 $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700392 $$(shell ( cd $(TRUNNER_TESTS_DIR); \
393 echo '/* Generated header, do not edit */'; \
394 ls *.c 2> /dev/null | \
395 sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \
396 ) > $$@)
397endif
398
399# compile individual test files
400# Note: we cd into output directory to ensure embedded BPF object is found
401$(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
402 $(TRUNNER_TESTS_DIR)/%.c \
403 $(TRUNNER_EXTRA_HDRS) \
404 $(TRUNNER_BPF_OBJS) \
Andrii Nakryikof3c926a2019-12-13 17:43:38 -0800405 $(TRUNNER_BPF_SKELS) \
Andrii Nakryikoa0964f52021-03-18 12:40:36 -0700406 $(TRUNNER_BPF_SKELS_LINKED) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700407 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800408 $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700409 $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700410
411$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
412 %.c \
413 $(TRUNNER_EXTRA_HDRS) \
414 $(TRUNNER_TESTS_HDR) \
415 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800416 $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700417 $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700418
Ilya Leoshkevich86fd1662021-02-24 12:14:45 +0100419# non-flavored in-srctree builds receive special treatment, in particular, we
420# do not need to copy extra resources (see e.g. test_btf_dump_case())
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700421$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
Ilya Leoshkevich86fd1662021-02-24 12:14:45 +0100422ifneq ($2:$(OUTPUT),:$(shell pwd))
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800423 $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES))
Ilya Leoshkevich86fd1662021-02-24 12:14:45 +0100424 $(Q)rsync -aq $$^ $(TRUNNER_OUTPUT)/
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700425endif
426
427$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
428 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \
Jiri Olsacc15a202020-07-11 23:53:29 +0200429 $(RESOLVE_BTFIDS) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700430 | $(TRUNNER_BINARY)-extras
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800431 $$(call msg,BINARY,,$$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700432 $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
Brendan Jackman58c185b2020-12-03 12:08:50 +0000433 $(Q)$(RESOLVE_BTFIDS) --no-fail --btf $(TRUNNER_OUTPUT)/btf_data.o $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700434
435endef
436
437# Define test_progs test runner.
438TRUNNER_TESTS_DIR := prog_tests
439TRUNNER_BPF_PROGS_DIR := progs
440TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \
Andrii Nakryikocd492912020-05-12 12:24:42 -0700441 network_helpers.c testing_helpers.c \
Andrii Nakryiko1306c982020-11-04 20:33:56 -0800442 btf_helpers.c flow_dissector_load.h
Andrii Nakryiko9f7fa222020-12-03 12:46:26 -0800443TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read $(OUTPUT)/bpf_testmod.ko \
KP Singh854055c2020-11-26 18:49:46 +0000444 ima_setup.sh \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700445 $(wildcard progs/btf_dump_test_case_*.c)
446TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
Andrii Nakryiko6910d7d2020-01-09 21:17:15 -0800447TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
Brendan Jackman98d666d2021-01-14 18:17:50 +0000448TRUNNER_BPF_CFLAGS += -DENABLE_ATOMICS_TESTS
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700449$(eval $(call DEFINE_TEST_RUNNER,test_progs))
450
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700451# Define test_progs-no_alu32 test runner.
Andrii Nakryiko24f65052019-11-19 16:25:10 -0800452TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
Brendan Jackman98d666d2021-01-14 18:17:50 +0000453TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700454$(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700455
456# Define test_progs BPF-GCC-flavored test runner.
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200457ifneq ($(BPF_GCC),)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700458TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100459TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700460$(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200461endif
462
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700463# Define test_maps test runner.
464TRUNNER_TESTS_DIR := map_tests
465TRUNNER_BPF_PROGS_DIR := progs
466TRUNNER_EXTRA_SOURCES := test_maps.c
467TRUNNER_EXTRA_FILES :=
468TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
469TRUNNER_BPF_CFLAGS :=
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700470$(eval $(call DEFINE_TEST_RUNNER,test_maps))
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700471
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700472# Define test_verifier test runner.
473# It is much simpler than test_maps/test_progs and sufficiently different from
474# them (e.g., test.h is using completely pattern), that it's worth just
475# explicitly defining all the rules explicitly.
476verifier/tests.h: verifier/*.c
Stanislav Fomicheve78e00b2019-03-06 11:59:26 -0800477 $(shell ( cd verifier/; \
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800478 echo '/* Generated header, do not edit */'; \
479 echo '#ifdef FILL_ARRAY'; \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700480 ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800481 echo '#endif' \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700482 ) > verifier/tests.h)
483$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800484 $(call msg,BINARY,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700485 $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800486
Stanislav Fomichev6bf6aff2019-12-02 13:59:31 -0800487# Make sure we are able to include and link libbpf against c++.
Andrii Nakryiko7c8dce42019-12-26 13:02:53 -0800488$(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
Andrii Nakryiko2cc51d32020-01-12 23:31:40 -0800489 $(call msg,CXX,,$@)
Yonghong Songa22c0c82021-04-13 08:34:24 -0700490 $(Q)$(CXX) $(CFLAGS) $(filter %.a %.o %.cpp,$^) $(LDLIBS) -o $@
Stanislav Fomichev6bf6aff2019-12-02 13:59:31 -0800491
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700492# Benchmark runner
493$(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
494 $(call msg,CC,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700495 $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
Andrii Nakryiko4eaf0b52020-05-12 12:24:44 -0700496$(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
Andrii Nakryikoc5d420c2020-05-12 12:24:45 -0700497$(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
Andrii Nakryikoc97099b2020-05-29 00:54:23 -0700498$(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \
499 $(OUTPUT)/perfbuf_bench.skel.h
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700500$(OUTPUT)/bench.o: bench.h testing_helpers.h
501$(OUTPUT)/bench: LDLIBS += -lm
502$(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
Andrii Nakryiko4eaf0b52020-05-12 12:24:44 -0700503 $(OUTPUT)/bench_count.o \
Andrii Nakryikoc5d420c2020-05-12 12:24:45 -0700504 $(OUTPUT)/bench_rename.o \
Andrii Nakryikoc97099b2020-05-29 00:54:23 -0700505 $(OUTPUT)/bench_trigger.o \
506 $(OUTPUT)/bench_ringbufs.o
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700507 $(call msg,BINARY,,$@)
Andrii Nakryikod5ca5902020-08-06 20:30:57 -0700508 $(Q)$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
Andrii Nakryiko8e7c2a02020-05-12 12:24:43 -0700509
Jean-Philippe Bruckerde11ae42021-01-13 17:33:16 +0100510EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) $(HOST_SCRATCH_DIR) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700511 prog_tests/tests.h map_tests/tests.h verifier/tests.h \
Andrii Nakryiko2031af22020-01-09 21:17:14 -0800512 feature \
Andrii Nakryiko9f7fa222020-12-03 12:46:26 -0800513 $(addprefix $(OUTPUT)/,*.o *.skel.h no_alu32 bpf_gcc bpf_testmod.ko)
Joe Stringera01d9352021-03-02 09:19:43 -0800514
515.PHONY: docs docs-clean