blob: 9d762184b8052995706ed32dbfe2a25b23153d2e [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
Daniel Borkmann720f2282017-12-12 02:25:32 +010013CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -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
22 $(CC) -o $(TEST_CUSTOM_PROGS) -static $<
23
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 \
36 test_get_stack_rawtp.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 \
45 test_tunnel.sh
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020046
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010047# Compile but not part of 'make run_tests'
Yonghong Song6595c742018-04-24 14:45:04 -070048TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010049
Zi Shen Lime8f1f342017-03-19 23:03:14 -070050include ../lib.mk
Alexei Starovoitov1da8ac72017-03-10 22:05:55 -080051
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010052BPFOBJ := $(OUTPUT)/libbpf.a
Zi Shen Lime8f1f342017-03-19 23:03:14 -070053
54$(TEST_GEN_PROGS): $(BPFOBJ)
55
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010056$(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a
57
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010058$(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
Andrey Ignatov1d436882018-03-30 15:08:08 -070059$(OUTPUT)/test_sock: cgroup_helpers.c
Andrey Ignatove50b0a62018-03-30 15:08:03 -070060$(OUTPUT)/test_sock_addr: cgroup_helpers.c
John Fastabend16962b22018-04-23 14:30:38 -070061$(OUTPUT)/test_sockmap: cgroup_helpers.c
Yonghong Song173965f2018-04-28 22:28:15 -070062$(OUTPUT)/test_progs: trace_helpers.c
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010063
Zi Shen Lime8f1f342017-03-19 23:03:14 -070064.PHONY: force
Mickaël Salaünd498f872017-02-11 23:20:23 +010065
Mickaël Salaünd498f872017-02-11 23:20:23 +010066# force a rebuild of BPFOBJ when its dependencies are updated
67force:
68
69$(BPFOBJ): force
Zi Shen Lime8f1f342017-03-19 23:03:14 -070070 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
Alexei Starovoitov68828042017-03-30 21:45:41 -070071
72CLANG ?= clang
Daniel Borkmann22c88522017-09-25 02:25:53 +020073LLC ?= llc
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -070074LLVM_OBJCOPY ?= llvm-objcopy
75BTF_PAHOLE ?= pahole
Daniel Borkmann22c88522017-09-25 02:25:53 +020076
Quentin Monnetcd95a892017-12-21 08:52:50 -080077PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)
Daniel Borkmann22c88522017-09-25 02:25:53 +020078
79# Let newer LLVM versions transparently probe the kernel for availability
80# of full BPF instruction set.
81ifeq ($(PROBE),)
82 CPU ?= probe
83else
84 CPU ?= generic
85endif
Alexei Starovoitov68828042017-03-30 21:45:41 -070086
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080087CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \
88 -Wno-compare-distinct-pointer-types
89
90$(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitovb0b04fc2017-12-14 17:55:12 -080091$(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080092
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -070093BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help |& grep dwarfris)
94BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help |& grep BTF)
95BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --version |& grep LLVM)
96
97ifneq ($(BTF_LLC_PROBE),)
98ifneq ($(BTF_PAHOLE_PROBE),)
99ifneq ($(BTF_OBJCOPY_PROBE),)
100 CLANG_FLAGS += -g
101 LLC_FLAGS += -mattr=dwarfris
102 DWARF2BTF = y
103endif
104endif
105endif
106
Yonghong Song62a06992018-01-29 21:23:28 -0800107$(OUTPUT)/%.o: %.c
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -0800108 $(CLANG) $(CLANG_FLAGS) \
Daniel Borkmann22c88522017-09-25 02:25:53 +0200109 -O2 -target bpf -emit-llvm -c $< -o - | \
Martin KaFai Lauc0fa1b62018-04-18 15:56:06 -0700110 $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@
111ifeq ($(DWARF2BTF),y)
112 $(BTF_PAHOLE) -J $@
113endif
Song Liu81f77fd2018-03-14 10:23:22 -0700114
115EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)