blob: 7a6214e9ae58d4432668394bf4762a0e2cb5c669 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Hendrik Brueckner618e1652017-12-04 10:56:48 +01002
Mickaël Salaünd498f872017-02-11 23:20:23 +01003LIBDIR := ../../../lib
Zi Shen Lime8f1f342017-03-19 23:03:14 -07004BPFDIR := $(LIBDIR)/bpf
Daniel Borkmann02ea80b2017-03-31 02:24:04 +02005APIDIR := ../../../include/uapi
6GENDIR := ../../../../include/generated
7GENHDR := $(GENDIR)/autoconf.h
Mickaël Salaünd498f872017-02-11 23:20:23 +01008
Daniel Borkmann02ea80b2017-03-31 02:24:04 +02009ifneq ($(wildcard $(GENHDR)),)
10 GENFLAGS := -DHAVE_GENHDR
11endif
12
Jakub Kicinskid0cabbb2018-05-10 10:24:40 -070013CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include
Yonghong Songaf32efe2018-01-26 15:06:08 -080014LDLIBS += -lcap -lelf -lrt -lpthread
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020015
Song Liu81f77fd2018-03-14 10:23:22 -070016TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read
17all: $(TEST_CUSTOM_PROGS)
18
Anders Roxell1c9ca7e2018-06-08 08:51:27 +020019$(TEST_CUSTOM_PROGS): $(OUTPUT)/%: %.c
Alexei Starovoitovf2467c22018-05-14 17:11:29 -070020 $(CC) -o $(TEST_CUSTOM_PROGS) -static $< -Wl,--build-id
Song Liu81f77fd2018-03-14 10:23:22 -070021
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010022# Order correspond to 'make run_tests' order
David S. Miller18b3ad92017-05-10 11:43:51 -070023TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
Andrey Ignatov1d436882018-03-30 15:08:08 -070024 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
Yonghong Songf2690992018-06-03 15:59:43 -070025 test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user
Alexei Starovoitov68828042017-03-30 21:45:41 -070026
Yonghong Song18f3d6b2017-06-13 15:52:14 -070027TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
Daniel Borkmann22c88522017-09-25 02:25:53 +020028 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080029 sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \
Jakub Kicinski7fedbb7c2018-01-17 19:13:31 -080030 test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \
John Fastabend82a86162018-03-18 12:57:31 -070031 sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o \
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -070032 sockmap_tcp_msg_prog.o connect4_prog.o connect6_prog.o test_adjust_tail.o \
Yonghong Song173965f2018-04-28 22:28:15 -070033 test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \
Mathieu Xhonneuxc99a84e2018-05-20 14:58:17 +010034 test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \
Yonghong Songf2690992018-06-03 15:59:43 -070035 test_lwt_seg6local.o sendmsg4_prog.o sendmsg6_prog.o test_lirc_mode2_kern.o \
36 get_cgroup_id_kern.o
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020037
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010038# Order correspond to 'make run_tests' order
39TEST_PROGS := test_kmod.sh \
40 test_libbpf.sh \
41 test_xdp_redirect.sh \
42 test_xdp_meta.sh \
Andrey Ignatov622adaf2018-03-30 15:08:06 -070043 test_offload.py \
William Tu933a7412018-04-26 14:01:39 -070044 test_sock_addr.sh \
Mathieu Xhonneuxc99a84e2018-05-20 14:58:17 +010045 test_tunnel.sh \
Sean Young6bdd5332018-05-27 12:24:10 +010046 test_lwt_seg6local.sh \
47 test_lirc_mode2.sh
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020048
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010049# Compile but not part of 'make run_tests'
Yonghong Song6595c742018-04-24 14:45:04 -070050TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010051
Zi Shen Lime8f1f342017-03-19 23:03:14 -070052include ../lib.mk
Alexei Starovoitov1da8ac72017-03-10 22:05:55 -080053
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010054BPFOBJ := $(OUTPUT)/libbpf.a
Zi Shen Lime8f1f342017-03-19 23:03:14 -070055
56$(TEST_GEN_PROGS): $(BPFOBJ)
57
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010058$(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a
59
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010060$(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
Andrey Ignatov1d436882018-03-30 15:08:08 -070061$(OUTPUT)/test_sock: cgroup_helpers.c
Andrey Ignatove50b0a62018-03-30 15:08:03 -070062$(OUTPUT)/test_sock_addr: cgroup_helpers.c
John Fastabend16962b22018-04-23 14:30:38 -070063$(OUTPUT)/test_sockmap: cgroup_helpers.c
Yonghong Song173965f2018-04-28 22:28:15 -070064$(OUTPUT)/test_progs: trace_helpers.c
Yonghong Songf2690992018-06-03 15:59:43 -070065$(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010066
Zi Shen Lime8f1f342017-03-19 23:03:14 -070067.PHONY: force
Mickaël Salaünd498f872017-02-11 23:20:23 +010068
Mickaël Salaünd498f872017-02-11 23:20:23 +010069# force a rebuild of BPFOBJ when its dependencies are updated
70force:
71
72$(BPFOBJ): force
Zi Shen Lime8f1f342017-03-19 23:03:14 -070073 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
Alexei Starovoitov68828042017-03-30 21:45:41 -070074
75CLANG ?= clang
Daniel Borkmann22c88522017-09-25 02:25:53 +020076LLC ?= llc
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -070077LLVM_OBJCOPY ?= llvm-objcopy
78BTF_PAHOLE ?= pahole
Daniel Borkmann22c88522017-09-25 02:25:53 +020079
Quentin Monnetcd95a892017-12-21 08:52:50 -080080PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)
Daniel Borkmann22c88522017-09-25 02:25:53 +020081
82# Let newer LLVM versions transparently probe the kernel for availability
83# of full BPF instruction set.
84ifeq ($(PROBE),)
85 CPU ?= probe
86else
87 CPU ?= generic
88endif
Alexei Starovoitov68828042017-03-30 21:45:41 -070089
Sirio Balmelli167381f2018-05-21 09:00:03 +020090# Get Clang's default includes on this system, as opposed to those seen by
91# '-target bpf'. This fixes "missing" files on some architectures/distros,
92# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
93#
94# Use '-idirafter': Don't interfere with include mechanics except where the
95# build would have failed anyways.
96CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \
97 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
98
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080099CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \
Sirio Balmelli167381f2018-05-21 09:00:03 +0200100 $(CLANG_SYS_INCLUDES) \
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800101 -Wno-compare-distinct-pointer-types
102
103$(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitovb0b04fc2017-12-14 17:55:12 -0800104$(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800105
Joe Stringer91bc07c2018-05-10 15:26:51 -0700106BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
107BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
108BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --version 2>&1 | grep LLVM)
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700109
110ifneq ($(BTF_LLC_PROBE),)
111ifneq ($(BTF_PAHOLE_PROBE),)
112ifneq ($(BTF_OBJCOPY_PROBE),)
113 CLANG_FLAGS += -g
114 LLC_FLAGS += -mattr=dwarfris
115 DWARF2BTF = y
116endif
117endif
118endif
119
Yonghong Song62a06992018-01-29 21:23:28 -0800120$(OUTPUT)/%.o: %.c
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800121 $(CLANG) $(CLANG_FLAGS) \
Daniel Borkmann22c88522017-09-25 02:25:53 +0200122 -O2 -target bpf -emit-llvm -c $< -o - | \
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700123 $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@
124ifeq ($(DWARF2BTF),y)
125 $(BTF_PAHOLE) -J $@
126endif
Song Liu81f77fd2018-03-14 10:23:22 -0700127
128EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)