blob: 85044448bbc79548d019502926c7e09eac8b1e12 [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
19$(TEST_CUSTOM_PROGS): urandom_read
20
21urandom_read: urandom_read.c
Alexei Starovoitovf2467c22018-05-14 17:11:29 -070022 $(CC) -o $(TEST_CUSTOM_PROGS) -static $< -Wl,--build-id
Song Liu81f77fd2018-03-14 10:23:22 -070023
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010024# Order correspond to 'make run_tests' order
David S. Miller18b3ad92017-05-10 11:43:51 -070025TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
Andrey Ignatov1d436882018-03-30 15:08:08 -070026 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \
John Fastabend16962b22018-04-23 14:30:38 -070027 test_sock test_btf test_sockmap
Alexei Starovoitov68828042017-03-30 21:45:41 -070028
Yonghong Song18f3d6b2017-06-13 15:52:14 -070029TEST_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 +020030 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080031 sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \
Jakub Kicinski7fedbb7c2018-01-17 19:13:31 -080032 test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \
John Fastabend82a86162018-03-18 12:57:31 -070033 sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o \
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -070034 sockmap_tcp_msg_prog.o connect4_prog.o connect6_prog.o test_adjust_tail.o \
Yonghong Song173965f2018-04-28 22:28:15 -070035 test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \
Mathieu Xhonneuxc99a84e2018-05-20 14:58:17 +010036 test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \
37 test_lwt_seg6local.o
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020038
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010039# Order correspond to 'make run_tests' order
40TEST_PROGS := test_kmod.sh \
41 test_libbpf.sh \
42 test_xdp_redirect.sh \
43 test_xdp_meta.sh \
Andrey Ignatov622adaf2018-03-30 15:08:06 -070044 test_offload.py \
William Tu933a7412018-04-26 14:01:39 -070045 test_sock_addr.sh \
Mathieu Xhonneuxc99a84e2018-05-20 14:58:17 +010046 test_tunnel.sh \
47 test_lwt_seg6local.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
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010065
Zi Shen Lime8f1f342017-03-19 23:03:14 -070066.PHONY: force
Mickaël Salaünd498f872017-02-11 23:20:23 +010067
Mickaël Salaünd498f872017-02-11 23:20:23 +010068# force a rebuild of BPFOBJ when its dependencies are updated
69force:
70
71$(BPFOBJ): force
Zi Shen Lime8f1f342017-03-19 23:03:14 -070072 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
Alexei Starovoitov68828042017-03-30 21:45:41 -070073
74CLANG ?= clang
Daniel Borkmann22c88522017-09-25 02:25:53 +020075LLC ?= llc
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -070076LLVM_OBJCOPY ?= llvm-objcopy
77BTF_PAHOLE ?= pahole
Daniel Borkmann22c88522017-09-25 02:25:53 +020078
Quentin Monnetcd95a892017-12-21 08:52:50 -080079PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)
Daniel Borkmann22c88522017-09-25 02:25:53 +020080
81# Let newer LLVM versions transparently probe the kernel for availability
82# of full BPF instruction set.
83ifeq ($(PROBE),)
84 CPU ?= probe
85else
86 CPU ?= generic
87endif
Alexei Starovoitov68828042017-03-30 21:45:41 -070088
Sirio Balmelli167381f2018-05-21 09:00:03 +020089# Get Clang's default includes on this system, as opposed to those seen by
90# '-target bpf'. This fixes "missing" files on some architectures/distros,
91# such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
92#
93# Use '-idirafter': Don't interfere with include mechanics except where the
94# build would have failed anyways.
95CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \
96 | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }')
97
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080098CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \
Sirio Balmelli167381f2018-05-21 09:00:03 +020099 $(CLANG_SYS_INCLUDES) \
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800100 -Wno-compare-distinct-pointer-types
101
102$(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitovb0b04fc2017-12-14 17:55:12 -0800103$(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800104
Joe Stringer91bc07c2018-05-10 15:26:51 -0700105BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris)
106BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF)
107BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --version 2>&1 | grep LLVM)
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700108
109ifneq ($(BTF_LLC_PROBE),)
110ifneq ($(BTF_PAHOLE_PROBE),)
111ifneq ($(BTF_OBJCOPY_PROBE),)
112 CLANG_FLAGS += -g
113 LLC_FLAGS += -mattr=dwarfris
114 DWARF2BTF = y
115endif
116endif
117endif
118
Yonghong Song62a06992018-01-29 21:23:28 -0800119$(OUTPUT)/%.o: %.c
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800120 $(CLANG) $(CLANG_FLAGS) \
Daniel Borkmann22c88522017-09-25 02:25:53 +0200121 -O2 -target bpf -emit-llvm -c $< -o - | \
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700122 $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@
123ifeq ($(DWARF2BTF),y)
124 $(BTF_PAHOLE) -J $@
125endif
Song Liu81f77fd2018-03-14 10:23:22 -0700126
127EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)