blob: e0fe01d9ec33b42be030487b8f930c534b023879 [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
Hendrik Brueckner618e1652017-12-04 10:56:48 +01004
Andrii Nakryiko74b5a592019-10-15 23:00:49 -07005CURDIR := $(abspath .)
6LIBDIR := $(abspath ../../../lib)
Zi Shen Lime8f1f342017-03-19 23:03:14 -07007BPFDIR := $(LIBDIR)/bpf
Andrii Nakryiko74b5a592019-10-15 23:00:49 -07008TOOLSDIR := $(abspath ../../../include)
9APIDIR := $(TOOLSDIR)/uapi
10GENDIR := $(abspath ../../../../include/generated)
Daniel Borkmann02ea80b2017-03-31 02:24:04 +020011GENHDR := $(GENDIR)/autoconf.h
Mickaël Salaünd498f872017-02-11 23:20:23 +010012
Daniel Borkmann02ea80b2017-03-31 02:24:04 +020013ifneq ($(wildcard $(GENHDR)),)
14 GENFLAGS := -DHAVE_GENHDR
15endif
16
Jiong Wang3ef84342019-01-26 12:26:14 -050017CLANG ?= clang
18LLC ?= llc
19LLVM_OBJCOPY ?= llvm-objcopy
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +020020BPF_GCC ?= $(shell command -v bpf-gcc;)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070021CFLAGS += -g -Wall -O2 $(GENFLAGS) -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) \
22 -I$(GENDIR) -I$(TOOLSDIR) -I$(CURDIR) \
23 -Dbpf_prog_load=bpf_prog_test_load \
Jiong Wang9d120b42019-05-24 23:25:21 +010024 -Dbpf_load_program=bpf_test_load_program
Yonghong Songaf32efe2018-01-26 15:06:08 -080025LDLIBS += -lcap -lelf -lrt -lpthread
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020026
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010027# Order correspond to 'make run_tests' order
David S. Miller18b3ad92017-05-10 11:43:51 -070028TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
Andrey Ignatov1d436882018-03-30 15:08:08 -070029 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
Hangbin Liu25a79912019-06-04 10:35:05 +080030 test_sock test_btf test_sockmap get_cgroup_id_user test_socket_cookie \
Andrii Nakryiko9bc63842019-10-22 23:09:13 -070031 test_cgroup_storage test_select_reuseport \
Andrii Nakryiko2d2a3ad2019-05-24 11:59:04 -070032 test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
Jiri Benc56bf8772019-11-18 21:25:26 +010033 test_cgroup_attach test_progs-no_alu32
Jiong Wang3ef84342019-01-26 12:26:14 -050034
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070035# Also test bpf-gcc, if present
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +020036ifneq ($(BPF_GCC),)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070037TEST_GEN_PROGS += test_progs-bpf_gcc
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +020038endif
39
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070040TEST_GEN_FILES =
Anders Roxelle47a1792019-11-11 17:17:28 +010041TEST_FILES = test_lwt_ip_encap.o \
42 test_tc_edt.o
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070043
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010044# Order correspond to 'make run_tests' order
45TEST_PROGS := test_kmod.sh \
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010046 test_xdp_redirect.sh \
47 test_xdp_meta.sh \
Toshiaki Makita88091ff2019-06-20 11:23:23 +090048 test_xdp_veth.sh \
Andrey Ignatov622adaf2018-03-30 15:08:06 -070049 test_offload.py \
William Tu933a7412018-04-26 14:01:39 -070050 test_sock_addr.sh \
Mathieu Xhonneuxc99a84e2018-05-20 14:58:17 +010051 test_tunnel.sh \
Sean Young6bdd5332018-05-27 12:24:10 +010052 test_lwt_seg6local.sh \
Andrey Ignatov5ecd8c22018-08-12 10:49:30 -070053 test_lirc_mode2.sh \
Petar Penkov50b3ed52018-09-14 07:46:22 -070054 test_skb_cgroup_id.sh \
Jesper Dangaard Brouer97396ff2018-10-09 12:04:53 +020055 test_flow_dissector.sh \
Jesper Dangaard Brouerd35661f2019-08-01 20:00:21 +020056 test_xdp_vlan_mode_generic.sh \
57 test_xdp_vlan_mode_native.sh \
Lorenz Bauerbafc0ba2019-03-22 09:54:06 +080058 test_lwt_ip_encap.sh \
Willem de Bruijn98cdabc2019-03-22 14:32:49 -040059 test_tcp_check_syncookie.sh \
Peter Oskolkov7df5e3d2019-03-22 16:40:19 -070060 test_tc_tunnel.sh \
Alan Maguirecd538502019-05-31 18:47:14 +010061 test_tc_edt.sh \
Quentin Monnet45c5589d2019-08-30 12:00:38 +010062 test_xdping.sh \
63 test_bpftool_build.sh
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020064
Anders Roxellf98937c2019-01-08 10:23:03 +010065TEST_PROGS_EXTENDED := with_addr.sh \
Stanislav Fomichev1be72f22019-01-14 09:41:41 -080066 with_tunnels.sh \
Anders Roxellf98937c2019-01-08 10:23:03 +010067 tcp_client.py \
Anders Roxell3035bb72019-08-20 15:41:21 +020068 tcp_server.py \
69 test_xdp_vlan.sh
Anders Roxellef4ab842018-10-10 16:27:04 +020070
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010071# Compile but not part of 'make run_tests'
Andrii Nakryikocb79a4e2019-10-15 23:00:51 -070072TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
Hangbin Liu25a79912019-06-04 10:35:05 +080073 flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
Stanislav Fomichev6bf6aff2019-12-02 13:59:31 -080074 test_lirc_mode2_user xdping test_cpp
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010075
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070076TEST_CUSTOM_PROGS = urandom_read
77
Zi Shen Lime8f1f342017-03-19 23:03:14 -070078include ../lib.mk
Alexei Starovoitov1da8ac72017-03-10 22:05:55 -080079
Andrii Nakryiko03dcb782019-10-15 23:00:48 -070080# Define simple and short `make test_progs`, `make test_sysctl`, etc targets
81# to build individual tests.
82# NOTE: Semicolon at the end is critical to override lib.mk's default static
83# rule for binaries.
84$(notdir $(TEST_GEN_PROGS) \
85 $(TEST_PROGS) \
86 $(TEST_PROGS_EXTENDED) \
87 $(TEST_GEN_PROGS_EXTENDED) \
88 $(TEST_CUSTOM_PROGS)): %: $(OUTPUT)/% ;
89
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070090$(OUTPUT)/urandom_read: urandom_read.c
Ivan Veceraf6827522019-03-15 21:04:14 +010091 $(CC) -o $@ $< -Wl,--build-id
Jiong Wang3ef84342019-01-26 12:26:14 -050092
Ilya Leoshkeviche93d9912019-10-28 11:21:10 +010093$(OUTPUT)/test_stub.o: test_stub.c
94 $(CC) -c $(CFLAGS) -o $@ $<
95
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010096BPFOBJ := $(OUTPUT)/libbpf.a
Zi Shen Lime8f1f342017-03-19 23:03:14 -070097
Andrii Nakryiko74b5a592019-10-15 23:00:49 -070098$(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/test_stub.o $(BPFOBJ)
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010099
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +0100100$(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
Andrey Ignatov5ecd8c22018-08-12 10:49:30 -0700101$(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c
Andrey Ignatov1d436882018-03-30 15:08:08 -0700102$(OUTPUT)/test_sock: cgroup_helpers.c
Andrey Ignatove50b0a62018-03-30 15:08:03 -0700103$(OUTPUT)/test_sock_addr: cgroup_helpers.c
Andrey Ignatov194db0d2018-07-30 17:42:31 -0700104$(OUTPUT)/test_socket_cookie: cgroup_helpers.c
John Fastabend16962b22018-04-23 14:30:38 -0700105$(OUTPUT)/test_sockmap: cgroup_helpers.c
Andrey Ignatovc65267e2018-07-11 17:33:35 -0700106$(OUTPUT)/test_tcpbpf_user: cgroup_helpers.c
Sowmini Varadhan435f90a2018-11-07 16:12:02 -0800107$(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c
Yonghong Songf2690992018-06-03 15:59:43 -0700108$(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
Roman Gushchin68cfa3a2018-08-02 14:27:29 -0700109$(OUTPUT)/test_cgroup_storage: cgroup_helpers.c
Roman Gushchin371e4fc2018-09-28 14:46:00 +0000110$(OUTPUT)/test_netcnt: cgroup_helpers.c
Martin KaFai Laue0b27b32019-02-09 23:22:28 -0800111$(OUTPUT)/test_sock_fields: cgroup_helpers.c
Andrey Ignatov1f5fa9a2019-03-08 15:08:21 -0800112$(OUTPUT)/test_sysctl: cgroup_helpers.c
Roman Gushchinba0c0cc2019-05-25 09:37:40 -0700113$(OUTPUT)/test_cgroup_attach: cgroup_helpers.c
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +0100114
Zi Shen Lime8f1f342017-03-19 23:03:14 -0700115.PHONY: force
Mickaël Salaünd498f872017-02-11 23:20:23 +0100116
Mickaël Salaünd498f872017-02-11 23:20:23 +0100117# force a rebuild of BPFOBJ when its dependencies are updated
118force:
119
Andrii Nakryikoe01a75c2019-10-08 10:59:40 -0700120$(BPFOBJ): force
Zi Shen Lime8f1f342017-03-19 23:03:14 -0700121 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
Alexei Starovoitov68828042017-03-30 21:45:41 -0700122
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700123BPF_HELPERS := $(BPFDIR)/bpf_helper_defs.h $(wildcard $(BPFDIR)/bpf_*.h)
124$(BPFDIR)/bpf_helper_defs.h:
125 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ bpf_helper_defs.h
126
Sirio Balmelli167381f2018-05-21 09:00:03 +0200127# Get Clang's default includes on this system, as opposed to those seen by
128# '-target bpf'. This fixes "missing" files on some architectures/distros,
129# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
130#
131# Use '-idirafter': Don't interfere with include mechanics except where the
132# build would have failed anyways.
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200133define get_sys_includes
134$(shell $(1) -v -E - </dev/null 2>&1 \
Sirio Balmelli167381f2018-05-21 09:00:03 +0200135 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200136endef
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700137
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100138# Determine target endianness.
139IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
140 grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
141MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
142
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200143CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100144BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700145 -I. -I./include/uapi -I$(APIDIR) \
146 -I$(BPFDIR) -I$(abspath $(OUTPUT)/../usr/include)
Sirio Balmelli167381f2018-05-21 09:00:03 +0200147
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200148CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
149 -Wno-compare-distinct-pointer-types
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800150
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200151$(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
152$(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800153
Stanislav Fomichevbf0f0fd2019-01-28 08:53:55 -0800154$(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
Stanislav Fomichevbf0f0fd2019-01-28 08:53:55 -0800155
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700156# Build BPF object using Clang
157# $1 - input .c file
158# $2 - output .o file
159# $3 - CFLAGS
160# $4 - LDFLAGS
161define CLANG_BPF_BUILD_RULE
162 ($(CLANG) $3 -O2 -target bpf -emit-llvm \
163 -c $1 -o - || echo "BPF obj compilation failed") | \
Andrii Nakryikoffc88172019-11-20 23:07:40 -0800164 $(LLC) -mattr=dwarfris -march=bpf -mcpu=probe $4 -filetype=obj -o $2
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700165endef
Andrii Nakryiko24f65052019-11-19 16:25:10 -0800166# Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
167define CLANG_NOALU32_BPF_BUILD_RULE
168 ($(CLANG) $3 -O2 -target bpf -emit-llvm \
169 -c $1 -o - || echo "BPF obj compilation failed") | \
170 $(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
171endef
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700172# Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
173define CLANG_NATIVE_BPF_BUILD_RULE
174 ($(CLANG) $3 -O2 -emit-llvm \
175 -c $1 -o - || echo "BPF obj compilation failed") | \
176 $(LLC) -march=bpf -mcpu=probe $4 -filetype=obj -o $2
177endef
178# Build BPF object using GCC
179define GCC_BPF_BUILD_RULE
180 $(BPF_GCC) $3 $4 -O2 -c $1 -o $2
181endef
Stanislav Fomicheve78e00b2019-03-06 11:59:26 -0800182
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700183# Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
184# $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
185# Parameters:
186# $1 - test runner base binary name (e.g., test_progs)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700187# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700188define DEFINE_TEST_RUNNER
Jiong Wang3ef84342019-01-26 12:26:14 -0500189
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700190TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
191TRUNNER_BINARY := $1$(if $2,-)$2
192TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
193 $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
194TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
195 $$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
196TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
197TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
198TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
199 $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)))
Jiong Wang3ef84342019-01-26 12:26:14 -0500200
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700201# Evaluate rules now with extra TRUNNER_XXX variables above already defined
202$$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2))
Stanislav Fomichev3f306582019-03-01 19:42:13 -0800203
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700204endef
Jiong Wang3ef84342019-01-26 12:26:14 -0500205
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700206# Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and
207# set up by DEFINE_TEST_RUNNER itself, create test runner build rules with:
208# $1 - test runner base binary name (e.g., test_progs)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700209# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700210define DEFINE_TEST_RUNNER_RULES
211
212ifeq ($($(TRUNNER_OUTPUT)-dir),)
213$(TRUNNER_OUTPUT)-dir := y
214$(TRUNNER_OUTPUT):
215 mkdir -p $$@
Jiong Wang3ef84342019-01-26 12:26:14 -0500216endif
217
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700218# ensure we set up BPF objects generation rule just once for a given
219# input/output directory combination
220ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),)
221$(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y
222$(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \
223 $(TRUNNER_BPF_PROGS_DIR)/%.c \
224 $(TRUNNER_BPF_PROGS_DIR)/*.h \
225 $$(BPF_HELPERS) | $(TRUNNER_OUTPUT)
226 $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \
227 $(TRUNNER_BPF_CFLAGS), \
228 $(TRUNNER_BPF_LDFLAGS))
229endif
230
231# ensure we set up tests.h header generation rule just once
232ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
233$(TRUNNER_TESTS_DIR)-tests-hdr := y
234$(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
235 $$(shell ( cd $(TRUNNER_TESTS_DIR); \
236 echo '/* Generated header, do not edit */'; \
237 ls *.c 2> /dev/null | \
238 sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \
239 ) > $$@)
240endif
241
242# compile individual test files
243# Note: we cd into output directory to ensure embedded BPF object is found
244$(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
245 $(TRUNNER_TESTS_DIR)/%.c \
246 $(TRUNNER_EXTRA_HDRS) \
247 $(TRUNNER_BPF_OBJS) \
248 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
Andrii Nakryiko45e587b2019-10-23 08:31:28 -0700249 cd $$(@D) && $$(CC) $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700250
251$(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
252 %.c \
253 $(TRUNNER_EXTRA_HDRS) \
254 $(TRUNNER_TESTS_HDR) \
255 $$(BPFOBJ) | $(TRUNNER_OUTPUT)
Andrii Nakryiko45e587b2019-10-23 08:31:28 -0700256 $$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700257
258$(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
259ifneq ($2,)
260 # only copy extra resources if in flavored build
261 cp -a $$^ $(TRUNNER_OUTPUT)/
262endif
263
264$(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
265 $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \
266 | $(TRUNNER_BINARY)-extras
Andrii Nakryiko45e587b2019-10-23 08:31:28 -0700267 $$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700268
269endef
270
271# Define test_progs test runner.
272TRUNNER_TESTS_DIR := prog_tests
273TRUNNER_BPF_PROGS_DIR := progs
274TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \
275 flow_dissector_load.h
276TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \
277 $(wildcard progs/btf_dump_test_case_*.c)
278TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
279TRUNNER_BPF_CFLAGS := -I. -I$(OUTPUT) $(BPF_CFLAGS) $(CLANG_CFLAGS)
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700280TRUNNER_BPF_LDFLAGS := -mattr=+alu32
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700281$(eval $(call DEFINE_TEST_RUNNER,test_progs))
282
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700283# Define test_progs-no_alu32 test runner.
Andrii Nakryiko24f65052019-11-19 16:25:10 -0800284TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700285TRUNNER_BPF_LDFLAGS :=
286$(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700287
288# Define test_progs BPF-GCC-flavored test runner.
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200289ifneq ($(BPF_GCC),)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700290TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
Ilya Leoshkevich313e7f62019-10-28 11:20:49 +0100291TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700292TRUNNER_BPF_LDFLAGS :=
293$(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
Ilya Leoshkevich4ce150b2019-09-12 18:05:43 +0200294endif
295
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700296# Define test_maps test runner.
297TRUNNER_TESTS_DIR := map_tests
298TRUNNER_BPF_PROGS_DIR := progs
299TRUNNER_EXTRA_SOURCES := test_maps.c
300TRUNNER_EXTRA_FILES :=
301TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
302TRUNNER_BPF_CFLAGS :=
303TRUNNER_BPF_LDFLAGS :=
304$(eval $(call DEFINE_TEST_RUNNER,test_maps))
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700305
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700306# Define test_verifier test runner.
307# It is much simpler than test_maps/test_progs and sufficiently different from
308# them (e.g., test.h is using completely pattern), that it's worth just
309# explicitly defining all the rules explicitly.
310verifier/tests.h: verifier/*.c
Stanislav Fomicheve78e00b2019-03-06 11:59:26 -0800311 $(shell ( cd verifier/; \
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800312 echo '/* Generated header, do not edit */'; \
313 echo '#ifdef FILL_ARRAY'; \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700314 ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800315 echo '#endif' \
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700316 ) > verifier/tests.h)
317$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
Andrii Nakryiko45e587b2019-10-23 08:31:28 -0700318 $(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
Jakub Kicinski2dfb4012019-01-25 15:24:42 -0800319
Stanislav Fomichev6bf6aff2019-12-02 13:59:31 -0800320# Make sure we are able to include and link libbpf against c++.
321$(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ)
322 $(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@
323
Andrii Nakryiko74b5a592019-10-15 23:00:49 -0700324EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) \
325 prog_tests/tests.h map_tests/tests.h verifier/tests.h \
Yonghong Songe13a2fe2019-10-21 21:31:19 -0700326 feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc