Commit | Line | Data |
---|---|---|
b2441318 | 1 | # SPDX-License-Identifier: GPL-2.0 |
618e165b | 2 | |
d498f871 | 3 | LIBDIR := ../../../lib |
e8f1f34a | 4 | BPFDIR := $(LIBDIR)/bpf |
02ea80b1 DB |
5 | APIDIR := ../../../include/uapi |
6 | GENDIR := ../../../../include/generated | |
7 | GENHDR := $(GENDIR)/autoconf.h | |
d498f871 | 8 | |
02ea80b1 DB |
9 | ifneq ($(wildcard $(GENHDR)),) |
10 | GENFLAGS := -DHAVE_GENHDR | |
11 | endif | |
12 | ||
d0cabbb0 | 13 | CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include |
af32efee | 14 | LDLIBS += -lcap -lelf -lrt -lpthread |
5aa5bd14 | 15 | |
81f77fd0 SL |
16 | TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read |
17 | all: $(TEST_CUSTOM_PROGS) | |
18 | ||
1c9ca7e9 | 19 | $(TEST_CUSTOM_PROGS): $(OUTPUT)/%: %.c |
f2467c2d | 20 | $(CC) -o $(TEST_CUSTOM_PROGS) -static $< -Wl,--build-id |
81f77fd0 | 21 | |
f09b2e38 | 22 | # Order correspond to 'make run_tests' order |
18b3ad90 | 23 | TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ |
1d436885 | 24 | test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ |
194db0d9 | 25 | test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user \ |
371e4fcc | 26 | test_socket_cookie test_cgroup_storage test_select_reuseport test_section_names \ |
435f90a3 | 27 | test_netcnt test_tcpnotify_user |
6882804c | 28 | |
18f3d6be | 29 | TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \ |
22c88526 | 30 | test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ |
3bc35c63 | 31 | sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ |
7fedbb7c | 32 | test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \ |
435f90a3 | 33 | test_tcpnotify_kern.o \ |
82a86168 | 34 | sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o \ |
c0fa1b6c | 35 | sockmap_tcp_msg_prog.o connect4_prog.o connect6_prog.o test_adjust_tail.o \ |
173965fb | 36 | test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \ |
c99a84ea | 37 | test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \ |
f269099a | 38 | test_lwt_seg6local.o sendmsg4_prog.o sendmsg6_prog.o test_lirc_mode2_kern.o \ |
5ecd8c22 | 39 | get_cgroup_id_kern.o socket_cookie_prog.o test_select_reuseport_kern.o \ |
97396ff0 | 40 | test_skb_cgroup_id_kern.o bpf_flow.o netcnt_prog.o \ |
43b987d2 | 41 | test_sk_lookup_kern.o test_xdp_vlan.o test_queue_map.o test_stack_map.o |
5aa5bd14 | 42 | |
f09b2e38 JDB |
43 | # Order correspond to 'make run_tests' order |
44 | TEST_PROGS := test_kmod.sh \ | |
45 | test_libbpf.sh \ | |
46 | test_xdp_redirect.sh \ | |
47 | test_xdp_meta.sh \ | |
622adafb | 48 | test_offload.py \ |
933a741e | 49 | test_sock_addr.sh \ |
c99a84ea | 50 | test_tunnel.sh \ |
6bdd533c | 51 | test_lwt_seg6local.sh \ |
5ecd8c22 | 52 | test_lirc_mode2.sh \ |
50b3ed57 | 53 | test_skb_cgroup_id.sh \ |
97396ff0 JDB |
54 | test_flow_dissector.sh \ |
55 | test_xdp_vlan.sh | |
5aa5bd14 | 56 | |
ef4ab844 AR |
57 | TEST_PROGS_EXTENDED := with_addr.sh |
58 | ||
f09b2e38 | 59 | # Compile but not part of 'make run_tests' |
50b3ed57 PP |
60 | TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr test_skb_cgroup_id_user \ |
61 | flow_dissector_load test_flow_dissector | |
f09b2e38 | 62 | |
e8f1f34a ZSL |
63 | include ../lib.mk |
64 | ||
41757dcb | 65 | BPFOBJ := $(OUTPUT)/libbpf.a |
e8f1f34a ZSL |
66 | |
67 | $(TEST_GEN_PROGS): $(BPFOBJ) | |
1da8ac7c | 68 | |
f09b2e38 JDB |
69 | $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a |
70 | ||
41757dcb | 71 | $(OUTPUT)/test_dev_cgroup: cgroup_helpers.c |
5ecd8c22 | 72 | $(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c |
1d436885 | 73 | $(OUTPUT)/test_sock: cgroup_helpers.c |
e50b0a6f | 74 | $(OUTPUT)/test_sock_addr: cgroup_helpers.c |
194db0d9 | 75 | $(OUTPUT)/test_socket_cookie: cgroup_helpers.c |
16962b24 | 76 | $(OUTPUT)/test_sockmap: cgroup_helpers.c |
c65267e5 | 77 | $(OUTPUT)/test_tcpbpf_user: cgroup_helpers.c |
435f90a3 | 78 | $(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c |
173965fb | 79 | $(OUTPUT)/test_progs: trace_helpers.c |
f269099a | 80 | $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c |
68cfa3ac | 81 | $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c |
371e4fcc | 82 | $(OUTPUT)/test_netcnt: cgroup_helpers.c |
41757dcb | 83 | |
e8f1f34a | 84 | .PHONY: force |
d498f871 | 85 | |
d498f871 MS |
86 | # force a rebuild of BPFOBJ when its dependencies are updated |
87 | force: | |
88 | ||
89 | $(BPFOBJ): force | |
e8f1f34a | 90 | $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ |
6882804c AS |
91 | |
92 | CLANG ?= clang | |
22c88526 | 93 | LLC ?= llc |
c0fa1b6c MKL |
94 | LLVM_OBJCOPY ?= llvm-objcopy |
95 | BTF_PAHOLE ?= pahole | |
22c88526 | 96 | |
cd95a892 | 97 | PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1) |
22c88526 DB |
98 | |
99 | # Let newer LLVM versions transparently probe the kernel for availability | |
100 | # of full BPF instruction set. | |
101 | ifeq ($(PROBE),) | |
102 | CPU ?= probe | |
103 | else | |
104 | CPU ?= generic | |
105 | endif | |
6882804c | 106 | |
167381f3 SB |
107 | # Get Clang's default includes on this system, as opposed to those seen by |
108 | # '-target bpf'. This fixes "missing" files on some architectures/distros, | |
109 | # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. | |
110 | # | |
111 | # Use '-idirafter': Don't interfere with include mechanics except where the | |
112 | # build would have failed anyways. | |
113 | CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \ | |
114 | | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') | |
115 | ||
3bc35c63 | 116 | CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \ |
167381f3 | 117 | $(CLANG_SYS_INCLUDES) \ |
3bc35c63 AS |
118 | -Wno-compare-distinct-pointer-types |
119 | ||
120 | $(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline | |
b0b04fc4 | 121 | $(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline |
3bc35c63 | 122 | |
43b987d2 MV |
123 | $(OUTPUT)/test_queue_map.o: test_queue_stack_map.h |
124 | $(OUTPUT)/test_stack_map.o: test_queue_stack_map.h | |
125 | ||
91bc07c9 JS |
126 | BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris) |
127 | BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) | |
7c3e8b64 | 128 | BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --help 2>&1 | grep -i 'usage.*llvm') |
c0fa1b6c MKL |
129 | |
130 | ifneq ($(BTF_LLC_PROBE),) | |
131 | ifneq ($(BTF_PAHOLE_PROBE),) | |
132 | ifneq ($(BTF_OBJCOPY_PROBE),) | |
133 | CLANG_FLAGS += -g | |
134 | LLC_FLAGS += -mattr=dwarfris | |
135 | DWARF2BTF = y | |
136 | endif | |
137 | endif | |
138 | endif | |
139 | ||
f96afa76 QM |
140 | # Have one program compiled without "-target bpf" to test whether libbpf loads |
141 | # it successfully | |
142 | $(OUTPUT)/test_xdp.o: test_xdp.c | |
143 | $(CLANG) $(CLANG_FLAGS) \ | |
144 | -O2 -emit-llvm -c $< -o - | \ | |
145 | $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ | |
146 | ifeq ($(DWARF2BTF),y) | |
147 | $(BTF_PAHOLE) -J $@ | |
148 | endif | |
149 | ||
62a06994 | 150 | $(OUTPUT)/%.o: %.c |
3bc35c63 | 151 | $(CLANG) $(CLANG_FLAGS) \ |
22c88526 | 152 | -O2 -target bpf -emit-llvm -c $< -o - | \ |
c0fa1b6c MKL |
153 | $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ |
154 | ifeq ($(DWARF2BTF),y) | |
155 | $(BTF_PAHOLE) -J $@ | |
156 | endif | |
81f77fd0 SL |
157 | |
158 | EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) |