Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Ilya Leoshkevich | 9cae4ac | 2019-07-11 11:12:49 +0200 | [diff] [blame] | 2 | include ../../../../scripts/Kbuild.include |
Ilya Leoshkevich | 748e50c | 2019-07-11 16:29:27 +0200 | [diff] [blame] | 3 | include ../../../scripts/Makefile.arch |
Hendrik Brueckner | 618e165 | 2017-12-04 10:56:48 +0100 | [diff] [blame] | 4 | |
Ilya Leoshkevich | e7ad28e | 2020-06-02 19:56:49 +0200 | [diff] [blame] | 5 | CXX ?= $(CROSS_COMPILE)g++ |
| 6 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 7 | CURDIR := $(abspath .) |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 8 | TOOLSDIR := $(abspath ../../..) |
| 9 | LIBDIR := $(TOOLSDIR)/lib |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 10 | BPFDIR := $(LIBDIR)/bpf |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 11 | TOOLSINCDIR := $(TOOLSDIR)/include |
| 12 | BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool |
| 13 | APIDIR := $(TOOLSINCDIR)/uapi |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 14 | GENDIR := $(abspath ../../../../include/generated) |
Daniel Borkmann | 02ea80b | 2017-03-31 02:24:04 +0200 | [diff] [blame] | 15 | GENHDR := $(GENDIR)/autoconf.h |
Mickaël Salaün | d498f87 | 2017-02-11 23:20:23 +0100 | [diff] [blame] | 16 | |
Daniel Borkmann | 02ea80b | 2017-03-31 02:24:04 +0200 | [diff] [blame] | 17 | ifneq ($(wildcard $(GENHDR)),) |
| 18 | GENFLAGS := -DHAVE_GENHDR |
| 19 | endif |
| 20 | |
Jiong Wang | 3ef8434 | 2019-01-26 12:26:14 -0500 | [diff] [blame] | 21 | CLANG ?= clang |
| 22 | LLC ?= llc |
| 23 | LLVM_OBJCOPY ?= llvm-objcopy |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 24 | BPF_GCC ?= $(shell command -v bpf-gcc;) |
Andrii Nakryiko | 02995dd | 2020-04-28 18:21:02 -0700 | [diff] [blame] | 25 | SAN_CFLAGS ?= |
| 26 | CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) $(SAN_CFLAGS) \ |
| 27 | -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \ |
| 28 | -I$(TOOLSINCDIR) -I$(APIDIR) \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 29 | -Dbpf_prog_load=bpf_prog_test_load \ |
Jiong Wang | 9d120b4 | 2019-05-24 23:25:21 +0100 | [diff] [blame] | 30 | -Dbpf_load_program=bpf_test_load_program |
Andrii Nakryiko | 166750b | 2019-12-13 17:47:08 -0800 | [diff] [blame] | 31 | LDLIBS += -lcap -lelf -lz -lrt -lpthread |
Daniel Borkmann | 5aa5bd1 | 2016-10-17 14:28:36 +0200 | [diff] [blame] | 32 | |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 33 | # Order correspond to 'make run_tests' order |
David S. Miller | 18b3ad9 | 2017-05-10 11:43:51 -0700 | [diff] [blame] | 34 | TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ |
Alexander Duyck | aaf376b | 2020-11-03 13:34:48 -0800 | [diff] [blame] | 35 | test_verifier_log test_dev_cgroup \ |
Andrii Nakryiko | c64779e | 2020-09-15 17:48:19 -0700 | [diff] [blame] | 36 | test_sock test_sockmap get_cgroup_id_user test_socket_cookie \ |
Jakub Sitnicki | 415bb4e | 2019-12-12 11:22:58 +0100 | [diff] [blame] | 37 | test_cgroup_storage \ |
Martin KaFai Lau | 6f521a2 | 2020-09-24 17:04:27 -0700 | [diff] [blame] | 38 | test_netcnt test_tcpnotify_user test_sysctl \ |
Carlos Neira | 1c1052e | 2020-03-04 17:41:57 -0300 | [diff] [blame] | 39 | test_progs-no_alu32 \ |
| 40 | test_current_pid_tgid_new_ns |
Jiong Wang | 3ef8434 | 2019-01-26 12:26:14 -0500 | [diff] [blame] | 41 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 42 | # Also test bpf-gcc, if present |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 43 | ifneq ($(BPF_GCC),) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 44 | TEST_GEN_PROGS += test_progs-bpf_gcc |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 45 | endif |
| 46 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 47 | TEST_GEN_FILES = |
Anders Roxell | e47a179 | 2019-11-11 17:17:28 +0100 | [diff] [blame] | 48 | TEST_FILES = test_lwt_ip_encap.o \ |
| 49 | test_tc_edt.o |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 50 | |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 51 | # Order correspond to 'make run_tests' order |
| 52 | TEST_PROGS := test_kmod.sh \ |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 53 | test_xdp_redirect.sh \ |
| 54 | test_xdp_meta.sh \ |
Toshiaki Makita | 88091ff | 2019-06-20 11:23:23 +0900 | [diff] [blame] | 55 | test_xdp_veth.sh \ |
Andrey Ignatov | 622adaf | 2018-03-30 15:08:06 -0700 | [diff] [blame] | 56 | test_offload.py \ |
William Tu | 933a741 | 2018-04-26 14:01:39 -0700 | [diff] [blame] | 57 | test_sock_addr.sh \ |
Mathieu Xhonneux | c99a84e | 2018-05-20 14:58:17 +0100 | [diff] [blame] | 58 | test_tunnel.sh \ |
Sean Young | 6bdd533 | 2018-05-27 12:24:10 +0100 | [diff] [blame] | 59 | test_lwt_seg6local.sh \ |
Andrey Ignatov | 5ecd8c2 | 2018-08-12 10:49:30 -0700 | [diff] [blame] | 60 | test_lirc_mode2.sh \ |
Petar Penkov | 50b3ed5 | 2018-09-14 07:46:22 -0700 | [diff] [blame] | 61 | test_skb_cgroup_id.sh \ |
Jesper Dangaard Brouer | 97396ff | 2018-10-09 12:04:53 +0200 | [diff] [blame] | 62 | test_flow_dissector.sh \ |
Jesper Dangaard Brouer | d35661f | 2019-08-01 20:00:21 +0200 | [diff] [blame] | 63 | test_xdp_vlan_mode_generic.sh \ |
| 64 | test_xdp_vlan_mode_native.sh \ |
Lorenz Bauer | bafc0ba | 2019-03-22 09:54:06 +0800 | [diff] [blame] | 65 | test_lwt_ip_encap.sh \ |
Willem de Bruijn | 98cdabc | 2019-03-22 14:32:49 -0400 | [diff] [blame] | 66 | test_tcp_check_syncookie.sh \ |
Peter Oskolkov | 7df5e3d | 2019-03-22 16:40:19 -0700 | [diff] [blame] | 67 | test_tc_tunnel.sh \ |
Alan Maguire | cd53850 | 2019-05-31 18:47:14 +0100 | [diff] [blame] | 68 | test_tc_edt.sh \ |
Quentin Monnet | 45c5589d | 2019-08-30 12:00:38 +0100 | [diff] [blame] | 69 | test_xdping.sh \ |
Michal Rostecki | 73633274 | 2020-02-26 17:59:39 +0100 | [diff] [blame] | 70 | test_bpftool_build.sh \ |
YiFei Zhu | d42d1cc | 2020-09-15 16:45:43 -0700 | [diff] [blame] | 71 | test_bpftool.sh \ |
| 72 | test_bpftool_metadata.sh \ |
Daniel Borkmann | 5aa5bd1 | 2016-10-17 14:28:36 +0200 | [diff] [blame] | 73 | |
Anders Roxell | f98937c | 2019-01-08 10:23:03 +0100 | [diff] [blame] | 74 | TEST_PROGS_EXTENDED := with_addr.sh \ |
Stanislav Fomichev | 1be72f2 | 2019-01-14 09:41:41 -0800 | [diff] [blame] | 75 | with_tunnels.sh \ |
Anders Roxell | f98937c | 2019-01-08 10:23:03 +0100 | [diff] [blame] | 76 | tcp_client.py \ |
Anders Roxell | 3035bb7 | 2019-08-20 15:41:21 +0200 | [diff] [blame] | 77 | tcp_server.py \ |
| 78 | test_xdp_vlan.sh |
Anders Roxell | ef4ab84 | 2018-10-10 16:27:04 +0200 | [diff] [blame] | 79 | |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 80 | # Compile but not part of 'make run_tests' |
Andrii Nakryiko | cb79a4e | 2019-10-15 23:00:51 -0700 | [diff] [blame] | 81 | TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \ |
Hangbin Liu | 25a7991 | 2019-06-04 10:35:05 +0800 | [diff] [blame] | 82 | flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ |
Andrii Nakryiko | 8e7c2a0 | 2020-05-12 12:24:43 -0700 | [diff] [blame] | 83 | test_lirc_mode2_user xdping test_cpp runqslower bench |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 84 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 85 | TEST_CUSTOM_PROGS = urandom_read |
| 86 | |
Andrii Nakryiko | 92f7440 | 2019-12-16 22:14:25 -0800 | [diff] [blame] | 87 | # Emit succinct information message describing current building step |
| 88 | # $1 - generic step name (e.g., CC, LINK, etc); |
| 89 | # $2 - optional "flavor" specifier; if provided, will be emitted as [flavor]; |
| 90 | # $3 - target (assumed to be file); only file name will be emitted; |
| 91 | # $4 - optional extra arg, emitted as-is, if provided. |
| 92 | ifeq ($(V),1) |
Andrii Nakryiko | 965b9fe | 2020-01-09 21:17:16 -0800 | [diff] [blame] | 93 | Q = |
Andrii Nakryiko | 92f7440 | 2019-12-16 22:14:25 -0800 | [diff] [blame] | 94 | msg = |
| 95 | else |
Andrii Nakryiko | 965b9fe | 2020-01-09 21:17:16 -0800 | [diff] [blame] | 96 | Q = @ |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 97 | msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $(2), [$(2)])" "$(notdir $(3))" "$(if $(4), $(4))"; |
Andrii Nakryiko | 965b9fe | 2020-01-09 21:17:16 -0800 | [diff] [blame] | 98 | MAKEFLAGS += --no-print-directory |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 99 | submake_extras := feature_display=0 |
Andrii Nakryiko | 92f7440 | 2019-12-16 22:14:25 -0800 | [diff] [blame] | 100 | endif |
| 101 | |
| 102 | # override lib.mk's default rules |
| 103 | OVERRIDE_TARGETS := 1 |
| 104 | override define CLEAN |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 105 | $(call msg,CLEAN) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 106 | $(Q)$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN) |
Andrii Nakryiko | 92f7440 | 2019-12-16 22:14:25 -0800 | [diff] [blame] | 107 | endef |
| 108 | |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 109 | include ../lib.mk |
Alexei Starovoitov | 1da8ac7 | 2017-03-10 22:05:55 -0800 | [diff] [blame] | 110 | |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 111 | SCRATCH_DIR := $(OUTPUT)/tools |
| 112 | BUILD_DIR := $(SCRATCH_DIR)/build |
| 113 | INCLUDE_DIR := $(SCRATCH_DIR)/include |
| 114 | BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a |
Jiri Olsa | cc15a20 | 2020-07-11 23:53:29 +0200 | [diff] [blame] | 115 | RESOLVE_BTFIDS := $(BUILD_DIR)/resolve_btfids/resolve_btfids |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 116 | |
Andrii Nakryiko | 03dcb78 | 2019-10-15 23:00:48 -0700 | [diff] [blame] | 117 | # Define simple and short `make test_progs`, `make test_sysctl`, etc targets |
| 118 | # to build individual tests. |
| 119 | # NOTE: Semicolon at the end is critical to override lib.mk's default static |
| 120 | # rule for binaries. |
| 121 | $(notdir $(TEST_GEN_PROGS) \ |
| 122 | $(TEST_PROGS) \ |
| 123 | $(TEST_PROGS_EXTENDED) \ |
| 124 | $(TEST_GEN_PROGS_EXTENDED) \ |
| 125 | $(TEST_CUSTOM_PROGS)): %: $(OUTPUT)/% ; |
| 126 | |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 127 | $(OUTPUT)/%.o: %.c |
| 128 | $(call msg,CC,,$@) |
| 129 | $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@ |
| 130 | |
Andrii Nakryiko | 92f7440 | 2019-12-16 22:14:25 -0800 | [diff] [blame] | 131 | $(OUTPUT)/%:%.c |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 132 | $(call msg,BINARY,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 133 | $(Q)$(LINK.c) $^ $(LDLIBS) -o $@ |
Andrii Nakryiko | 92f7440 | 2019-12-16 22:14:25 -0800 | [diff] [blame] | 134 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 135 | $(OUTPUT)/urandom_read: urandom_read.c |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 136 | $(call msg,BINARY,,$@) |
Bill Wendling | a968433 | 2020-09-22 16:21:40 -0700 | [diff] [blame] | 137 | $(Q)$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS) -Wl,--build-id=sha1 |
Jiong Wang | 3ef8434 | 2019-01-26 12:26:14 -0500 | [diff] [blame] | 138 | |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 139 | $(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ) |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 140 | $(call msg,CC,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 141 | $(Q)$(CC) -c $(CFLAGS) -o $@ $< |
Ilya Leoshkevich | e93d991 | 2019-10-28 11:21:10 +0100 | [diff] [blame] | 142 | |
Andrii Nakryiko | ca4db63 | 2020-06-29 17:47:59 -0700 | [diff] [blame] | 143 | VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \ |
Andrii Nakryiko | cc6fa77 | 2020-03-04 10:43:36 -0800 | [diff] [blame] | 144 | $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \ |
| 145 | ../../../../vmlinux \ |
| 146 | /sys/kernel/btf/vmlinux \ |
| 147 | /boot/vmlinux-$(shell uname -r) |
Andrii Nakryiko | ca4db63 | 2020-06-29 17:47:59 -0700 | [diff] [blame] | 148 | VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS)))) |
Andrii Nakryiko | cc6fa77 | 2020-03-04 10:43:36 -0800 | [diff] [blame] | 149 | |
Andrii Nakryiko | 6bcaf41 | 2020-08-04 17:47:57 -0700 | [diff] [blame] | 150 | DEFAULT_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool |
| 151 | |
| 152 | $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL) |
Toke Høiland-Jørgensen | bfe4279 | 2020-01-20 14:06:43 +0100 | [diff] [blame] | 153 | $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \ |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 154 | OUTPUT=$(SCRATCH_DIR)/ VMLINUX_BTF=$(VMLINUX_BTF) \ |
Veronika Kabatova | b26d1e2 | 2020-04-28 19:37:42 +0200 | [diff] [blame] | 155 | BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) && \ |
| 156 | cp $(SCRATCH_DIR)/runqslower $@ |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 157 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 158 | $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/test_stub.o $(BPFOBJ) |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 159 | |
Jesper Dangaard Brouer | 41757dc | 2018-02-13 14:19:15 +0100 | [diff] [blame] | 160 | $(OUTPUT)/test_dev_cgroup: cgroup_helpers.c |
Andrey Ignatov | 5ecd8c2 | 2018-08-12 10:49:30 -0700 | [diff] [blame] | 161 | $(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c |
Andrey Ignatov | 1d43688 | 2018-03-30 15:08:08 -0700 | [diff] [blame] | 162 | $(OUTPUT)/test_sock: cgroup_helpers.c |
Andrey Ignatov | e50b0a6 | 2018-03-30 15:08:03 -0700 | [diff] [blame] | 163 | $(OUTPUT)/test_sock_addr: cgroup_helpers.c |
Andrey Ignatov | 194db0d | 2018-07-30 17:42:31 -0700 | [diff] [blame] | 164 | $(OUTPUT)/test_socket_cookie: cgroup_helpers.c |
John Fastabend | 16962b2 | 2018-04-23 14:30:38 -0700 | [diff] [blame] | 165 | $(OUTPUT)/test_sockmap: cgroup_helpers.c |
Sowmini Varadhan | 435f90a | 2018-11-07 16:12:02 -0800 | [diff] [blame] | 166 | $(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c |
Yonghong Song | f269099 | 2018-06-03 15:59:43 -0700 | [diff] [blame] | 167 | $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c |
Roman Gushchin | 68cfa3a | 2018-08-02 14:27:29 -0700 | [diff] [blame] | 168 | $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c |
Roman Gushchin | 371e4fc | 2018-09-28 14:46:00 +0000 | [diff] [blame] | 169 | $(OUTPUT)/test_netcnt: cgroup_helpers.c |
Martin KaFai Lau | e0b27b3 | 2019-02-09 23:22:28 -0800 | [diff] [blame] | 170 | $(OUTPUT)/test_sock_fields: cgroup_helpers.c |
Andrey Ignatov | 1f5fa9a | 2019-03-08 15:08:21 -0800 | [diff] [blame] | 171 | $(OUTPUT)/test_sysctl: cgroup_helpers.c |
Jesper Dangaard Brouer | 41757dc | 2018-02-13 14:19:15 +0100 | [diff] [blame] | 172 | |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 173 | BPFTOOL ?= $(DEFAULT_BPFTOOL) |
Andrii Nakryiko | 0350629 | 2020-01-23 21:41:48 -0800 | [diff] [blame] | 174 | $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \ |
| 175 | $(BPFOBJ) | $(BUILD_DIR)/bpftool |
| 176 | $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \ |
| 177 | OUTPUT=$(BUILD_DIR)/bpftool/ \ |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 178 | prefix= DESTDIR=$(SCRATCH_DIR)/ install |
Quentin Monnet | 41d5c37 | 2020-09-09 17:22:51 +0100 | [diff] [blame] | 179 | $(Q)mkdir -p $(BUILD_DIR)/bpftool/Documentation |
| 180 | $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \ |
| 181 | -C $(BPFTOOLDIR)/Documentation \ |
| 182 | OUTPUT=$(BUILD_DIR)/bpftool/Documentation/ \ |
| 183 | prefix= DESTDIR=$(SCRATCH_DIR)/ install |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 184 | |
Andrii Nakryiko | 0350629 | 2020-01-23 21:41:48 -0800 | [diff] [blame] | 185 | $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \ |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 186 | ../../../include/uapi/linux/bpf.h \ |
| 187 | | $(INCLUDE_DIR) $(BUILD_DIR)/libbpf |
| 188 | $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \ |
Andrii Nakryiko | 0350629 | 2020-01-23 21:41:48 -0800 | [diff] [blame] | 189 | DESTDIR=$(SCRATCH_DIR) prefix= all install_headers |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 190 | |
Jiri Olsa | cc15a20 | 2020-07-11 23:53:29 +0200 | [diff] [blame] | 191 | $(BUILD_DIR)/libbpf $(BUILD_DIR)/bpftool $(BUILD_DIR)/resolve_btfids $(INCLUDE_DIR): |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 192 | $(call msg,MKDIR,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 193 | $(Q)mkdir -p $@ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 194 | |
Andrii Nakryiko | acbd062 | 2020-03-13 10:23:36 -0700 | [diff] [blame] | 195 | $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) | $(BPFTOOL) $(INCLUDE_DIR) |
Andrii Nakryiko | ca4db63 | 2020-06-29 17:47:59 -0700 | [diff] [blame] | 196 | ifeq ($(VMLINUX_H),) |
Andrii Nakryiko | acbd062 | 2020-03-13 10:23:36 -0700 | [diff] [blame] | 197 | $(call msg,GEN,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 198 | $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@ |
Andrii Nakryiko | ca4db63 | 2020-06-29 17:47:59 -0700 | [diff] [blame] | 199 | else |
| 200 | $(call msg,CP,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 201 | $(Q)cp "$(VMLINUX_H)" $@ |
Andrii Nakryiko | ca4db63 | 2020-06-29 17:47:59 -0700 | [diff] [blame] | 202 | endif |
Andrii Nakryiko | acbd062 | 2020-03-13 10:23:36 -0700 | [diff] [blame] | 203 | |
Jiri Olsa | cc15a20 | 2020-07-11 23:53:29 +0200 | [diff] [blame] | 204 | $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids \ |
| 205 | $(TOOLSDIR)/bpf/resolve_btfids/main.c \ |
| 206 | $(TOOLSDIR)/lib/rbtree.c \ |
| 207 | $(TOOLSDIR)/lib/zalloc.c \ |
| 208 | $(TOOLSDIR)/lib/string.c \ |
| 209 | $(TOOLSDIR)/lib/ctype.c \ |
| 210 | $(TOOLSDIR)/lib/str_error_r.c |
| 211 | $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \ |
| 212 | OUTPUT=$(BUILD_DIR)/resolve_btfids/ BPFOBJ=$(BPFOBJ) |
| 213 | |
Sirio Balmelli | 167381f | 2018-05-21 09:00:03 +0200 | [diff] [blame] | 214 | # Get Clang's default includes on this system, as opposed to those seen by |
| 215 | # '-target bpf'. This fixes "missing" files on some architectures/distros, |
| 216 | # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. |
| 217 | # |
| 218 | # Use '-idirafter': Don't interfere with include mechanics except where the |
| 219 | # build would have failed anyways. |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 220 | define get_sys_includes |
| 221 | $(shell $(1) -v -E - </dev/null 2>&1 \ |
Björn Töpel | 6016df8 | 2020-11-18 08:16:38 +0100 | [diff] [blame] | 222 | | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \ |
| 223 | $(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/') |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 224 | endef |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 225 | |
Ilya Leoshkevich | 313e7f6 | 2019-10-28 11:20:49 +0100 | [diff] [blame] | 226 | # Determine target endianness. |
| 227 | IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \ |
| 228 | grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__') |
| 229 | MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) |
| 230 | |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 231 | CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) |
Ilya Leoshkevich | 313e7f6 | 2019-10-28 11:20:49 +0100 | [diff] [blame] | 232 | BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ |
Tobias Klauser | bcd66b1 | 2020-03-13 12:31:05 +0100 | [diff] [blame] | 233 | -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ |
| 234 | -I$(abspath $(OUTPUT)/../usr/include) |
Sirio Balmelli | 167381f | 2018-05-21 09:00:03 +0200 | [diff] [blame] | 235 | |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 236 | CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ |
| 237 | -Wno-compare-distinct-pointer-types |
Alexei Starovoitov | 3bc35c6 | 2017-12-14 17:55:11 -0800 | [diff] [blame] | 238 | |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 239 | $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline |
| 240 | $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline |
Alexei Starovoitov | 3bc35c6 | 2017-12-14 17:55:11 -0800 | [diff] [blame] | 241 | |
Stanislav Fomichev | bf0f0fd | 2019-01-28 08:53:55 -0800 | [diff] [blame] | 242 | $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h |
Stanislav Fomichev | bf0f0fd | 2019-01-28 08:53:55 -0800 | [diff] [blame] | 243 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 244 | # Build BPF object using Clang |
| 245 | # $1 - input .c file |
| 246 | # $2 - output .o file |
| 247 | # $3 - CFLAGS |
| 248 | # $4 - LDFLAGS |
| 249 | define CLANG_BPF_BUILD_RULE |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 250 | $(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 251 | $(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 252 | -c $1 -o - || echo "BPF obj compilation failed") | \ |
Yonghong Song | 83250f2 | 2020-02-18 16:42:36 -0800 | [diff] [blame] | 253 | $(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2 |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 254 | endef |
Andrii Nakryiko | 24f6505 | 2019-11-19 16:25:10 -0800 | [diff] [blame] | 255 | # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32 |
| 256 | define CLANG_NOALU32_BPF_BUILD_RULE |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 257 | $(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 258 | $(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \ |
Andrii Nakryiko | 24f6505 | 2019-11-19 16:25:10 -0800 | [diff] [blame] | 259 | -c $1 -o - || echo "BPF obj compilation failed") | \ |
| 260 | $(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2 |
| 261 | endef |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 262 | # Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC |
| 263 | define CLANG_NATIVE_BPF_BUILD_RULE |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 264 | $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 265 | $(Q)($(CLANG) $3 -O2 -emit-llvm \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 266 | -c $1 -o - || echo "BPF obj compilation failed") | \ |
Yonghong Song | 83250f2 | 2020-02-18 16:42:36 -0800 | [diff] [blame] | 267 | $(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2 |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 268 | endef |
| 269 | # Build BPF object using GCC |
| 270 | define GCC_BPF_BUILD_RULE |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 271 | $(call msg,GCC-BPF,$(TRUNNER_BINARY),$2) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 272 | $(Q)$(BPF_GCC) $3 $4 -O2 -c $1 -o $2 |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 273 | endef |
Stanislav Fomichev | e78e00b | 2019-03-06 11:59:26 -0800 | [diff] [blame] | 274 | |
Jakub Sitnicki | 0b9ad56 | 2020-04-29 20:11:54 +0200 | [diff] [blame] | 275 | SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 276 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 277 | # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on |
| 278 | # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES. |
| 279 | # Parameters: |
| 280 | # $1 - test runner base binary name (e.g., test_progs) |
Yonghong Song | e13a2fe | 2019-10-21 21:31:19 -0700 | [diff] [blame] | 281 | # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 282 | define DEFINE_TEST_RUNNER |
Jiong Wang | 3ef8434 | 2019-01-26 12:26:14 -0500 | [diff] [blame] | 283 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 284 | TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2 |
| 285 | TRUNNER_BINARY := $1$(if $2,-)$2 |
| 286 | TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \ |
| 287 | $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c))) |
| 288 | TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \ |
| 289 | $$(filter %.c,$(TRUNNER_EXTRA_SOURCES))) |
| 290 | TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES)) |
| 291 | TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 292 | TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c)) |
| 293 | TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS)) |
| 294 | TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \ |
| 295 | $$(filter-out $(SKEL_BLACKLIST), \ |
| 296 | $$(TRUNNER_BPF_SRCS))) |
Yauheni Kaliuta | 309b81f | 2020-05-13 05:17:22 +0300 | [diff] [blame] | 297 | TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS) |
Jiong Wang | 3ef8434 | 2019-01-26 12:26:14 -0500 | [diff] [blame] | 298 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 299 | # Evaluate rules now with extra TRUNNER_XXX variables above already defined |
| 300 | $$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2)) |
Stanislav Fomichev | 3f30658 | 2019-03-01 19:42:13 -0800 | [diff] [blame] | 301 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 302 | endef |
Jiong Wang | 3ef8434 | 2019-01-26 12:26:14 -0500 | [diff] [blame] | 303 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 304 | # Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and |
| 305 | # set up by DEFINE_TEST_RUNNER itself, create test runner build rules with: |
| 306 | # $1 - test runner base binary name (e.g., test_progs) |
Yonghong Song | e13a2fe | 2019-10-21 21:31:19 -0700 | [diff] [blame] | 307 | # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 308 | define DEFINE_TEST_RUNNER_RULES |
| 309 | |
| 310 | ifeq ($($(TRUNNER_OUTPUT)-dir),) |
| 311 | $(TRUNNER_OUTPUT)-dir := y |
| 312 | $(TRUNNER_OUTPUT): |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 313 | $$(call msg,MKDIR,,$$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 314 | $(Q)mkdir -p $$@ |
Jiong Wang | 3ef8434 | 2019-01-26 12:26:14 -0500 | [diff] [blame] | 315 | endif |
| 316 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 317 | # ensure we set up BPF objects generation rule just once for a given |
| 318 | # input/output directory combination |
| 319 | ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),) |
| 320 | $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y |
| 321 | $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \ |
| 322 | $(TRUNNER_BPF_PROGS_DIR)/%.c \ |
| 323 | $(TRUNNER_BPF_PROGS_DIR)/*.h \ |
Andrii Nakryiko | acbd062 | 2020-03-13 10:23:36 -0700 | [diff] [blame] | 324 | $$(INCLUDE_DIR)/vmlinux.h \ |
Andrii Nakryiko | 3ac2e20 | 2020-08-20 16:12:35 -0700 | [diff] [blame] | 325 | $(wildcard $(BPFDIR)/bpf_*.h) | $(TRUNNER_OUTPUT) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 326 | $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \ |
| 327 | $(TRUNNER_BPF_CFLAGS), \ |
| 328 | $(TRUNNER_BPF_LDFLAGS)) |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 329 | |
| 330 | $(TRUNNER_BPF_SKELS): $(TRUNNER_OUTPUT)/%.skel.h: \ |
| 331 | $(TRUNNER_OUTPUT)/%.o \ |
| 332 | | $(BPFTOOL) $(TRUNNER_OUTPUT) |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 333 | $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 334 | $(Q)$$(BPFTOOL) gen skeleton $$< > $$@ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 335 | endif |
| 336 | |
| 337 | # ensure we set up tests.h header generation rule just once |
| 338 | ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),) |
| 339 | $(TRUNNER_TESTS_DIR)-tests-hdr := y |
| 340 | $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 341 | $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 342 | $$(shell ( cd $(TRUNNER_TESTS_DIR); \ |
| 343 | echo '/* Generated header, do not edit */'; \ |
| 344 | ls *.c 2> /dev/null | \ |
| 345 | sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \ |
| 346 | ) > $$@) |
| 347 | endif |
| 348 | |
| 349 | # compile individual test files |
| 350 | # Note: we cd into output directory to ensure embedded BPF object is found |
| 351 | $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \ |
| 352 | $(TRUNNER_TESTS_DIR)/%.c \ |
| 353 | $(TRUNNER_EXTRA_HDRS) \ |
| 354 | $(TRUNNER_BPF_OBJS) \ |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 355 | $(TRUNNER_BPF_SKELS) \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 356 | $$(BPFOBJ) | $(TRUNNER_OUTPUT) |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 357 | $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 358 | $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 359 | |
| 360 | $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \ |
| 361 | %.c \ |
| 362 | $(TRUNNER_EXTRA_HDRS) \ |
| 363 | $(TRUNNER_TESTS_HDR) \ |
| 364 | $$(BPFOBJ) | $(TRUNNER_OUTPUT) |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 365 | $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 366 | $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 367 | |
Andrii Nakryiko | f3c926a | 2019-12-13 17:43:38 -0800 | [diff] [blame] | 368 | # only copy extra resources if in flavored build |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 369 | $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT) |
| 370 | ifneq ($2,) |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 371 | $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES)) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 372 | $(Q)cp -a $$^ $(TRUNNER_OUTPUT)/ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 373 | endif |
| 374 | |
| 375 | $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \ |
| 376 | $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \ |
Jiri Olsa | cc15a20 | 2020-07-11 23:53:29 +0200 | [diff] [blame] | 377 | $(RESOLVE_BTFIDS) \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 378 | | $(TRUNNER_BINARY)-extras |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 379 | $$(call msg,BINARY,,$$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 380 | $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@ |
| 381 | $(Q)$(RESOLVE_BTFIDS) --no-fail --btf btf_data.o $$@ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 382 | |
| 383 | endef |
| 384 | |
| 385 | # Define test_progs test runner. |
| 386 | TRUNNER_TESTS_DIR := prog_tests |
| 387 | TRUNNER_BPF_PROGS_DIR := progs |
| 388 | TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \ |
Andrii Nakryiko | cd49291 | 2020-05-12 12:24:42 -0700 | [diff] [blame] | 389 | network_helpers.c testing_helpers.c \ |
Andrii Nakryiko | 1306c98 | 2020-11-04 20:33:56 -0800 | [diff] [blame] | 390 | btf_helpers.c flow_dissector_load.h |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 391 | TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \ |
KP Singh | 854055c | 2020-11-26 18:49:46 +0000 | [diff] [blame^] | 392 | ima_setup.sh \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 393 | $(wildcard progs/btf_dump_test_case_*.c) |
| 394 | TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE |
Andrii Nakryiko | 6910d7d | 2020-01-09 21:17:15 -0800 | [diff] [blame] | 395 | TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) |
Yonghong Song | e13a2fe | 2019-10-21 21:31:19 -0700 | [diff] [blame] | 396 | TRUNNER_BPF_LDFLAGS := -mattr=+alu32 |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 397 | $(eval $(call DEFINE_TEST_RUNNER,test_progs)) |
| 398 | |
Yonghong Song | e13a2fe | 2019-10-21 21:31:19 -0700 | [diff] [blame] | 399 | # Define test_progs-no_alu32 test runner. |
Andrii Nakryiko | 24f6505 | 2019-11-19 16:25:10 -0800 | [diff] [blame] | 400 | TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE |
Yonghong Song | e13a2fe | 2019-10-21 21:31:19 -0700 | [diff] [blame] | 401 | TRUNNER_BPF_LDFLAGS := |
| 402 | $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32)) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 403 | |
| 404 | # Define test_progs BPF-GCC-flavored test runner. |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 405 | ifneq ($(BPF_GCC),) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 406 | TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE |
Ilya Leoshkevich | 313e7f6 | 2019-10-28 11:20:49 +0100 | [diff] [blame] | 407 | TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc) |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 408 | TRUNNER_BPF_LDFLAGS := |
| 409 | $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc)) |
Ilya Leoshkevich | 4ce150b | 2019-09-12 18:05:43 +0200 | [diff] [blame] | 410 | endif |
| 411 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 412 | # Define test_maps test runner. |
| 413 | TRUNNER_TESTS_DIR := map_tests |
| 414 | TRUNNER_BPF_PROGS_DIR := progs |
| 415 | TRUNNER_EXTRA_SOURCES := test_maps.c |
| 416 | TRUNNER_EXTRA_FILES := |
| 417 | TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built) |
| 418 | TRUNNER_BPF_CFLAGS := |
| 419 | TRUNNER_BPF_LDFLAGS := |
| 420 | $(eval $(call DEFINE_TEST_RUNNER,test_maps)) |
Martin KaFai Lau | c0fa1b6 | 2018-04-18 15:56:06 -0700 | [diff] [blame] | 421 | |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 422 | # Define test_verifier test runner. |
| 423 | # It is much simpler than test_maps/test_progs and sufficiently different from |
| 424 | # them (e.g., test.h is using completely pattern), that it's worth just |
| 425 | # explicitly defining all the rules explicitly. |
| 426 | verifier/tests.h: verifier/*.c |
Stanislav Fomichev | e78e00b | 2019-03-06 11:59:26 -0800 | [diff] [blame] | 427 | $(shell ( cd verifier/; \ |
Jakub Kicinski | 2dfb401 | 2019-01-25 15:24:42 -0800 | [diff] [blame] | 428 | echo '/* Generated header, do not edit */'; \ |
| 429 | echo '#ifdef FILL_ARRAY'; \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 430 | ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \ |
Jakub Kicinski | 2dfb401 | 2019-01-25 15:24:42 -0800 | [diff] [blame] | 431 | echo '#endif' \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 432 | ) > verifier/tests.h) |
| 433 | $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT) |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 434 | $(call msg,BINARY,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 435 | $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ |
Jakub Kicinski | 2dfb401 | 2019-01-25 15:24:42 -0800 | [diff] [blame] | 436 | |
Stanislav Fomichev | 6bf6aff | 2019-12-02 13:59:31 -0800 | [diff] [blame] | 437 | # Make sure we are able to include and link libbpf against c++. |
Andrii Nakryiko | 7c8dce4 | 2019-12-26 13:02:53 -0800 | [diff] [blame] | 438 | $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ) |
Andrii Nakryiko | 2cc51d3 | 2020-01-12 23:31:40 -0800 | [diff] [blame] | 439 | $(call msg,CXX,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 440 | $(Q)$(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@ |
Stanislav Fomichev | 6bf6aff | 2019-12-02 13:59:31 -0800 | [diff] [blame] | 441 | |
Andrii Nakryiko | 8e7c2a0 | 2020-05-12 12:24:43 -0700 | [diff] [blame] | 442 | # Benchmark runner |
| 443 | $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h |
| 444 | $(call msg,CC,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 445 | $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@ |
Andrii Nakryiko | 4eaf0b5 | 2020-05-12 12:24:44 -0700 | [diff] [blame] | 446 | $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h |
Andrii Nakryiko | c5d420c | 2020-05-12 12:24:45 -0700 | [diff] [blame] | 447 | $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h |
Andrii Nakryiko | c97099b | 2020-05-29 00:54:23 -0700 | [diff] [blame] | 448 | $(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \ |
| 449 | $(OUTPUT)/perfbuf_bench.skel.h |
Andrii Nakryiko | 8e7c2a0 | 2020-05-12 12:24:43 -0700 | [diff] [blame] | 450 | $(OUTPUT)/bench.o: bench.h testing_helpers.h |
| 451 | $(OUTPUT)/bench: LDLIBS += -lm |
| 452 | $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \ |
Andrii Nakryiko | 4eaf0b5 | 2020-05-12 12:24:44 -0700 | [diff] [blame] | 453 | $(OUTPUT)/bench_count.o \ |
Andrii Nakryiko | c5d420c | 2020-05-12 12:24:45 -0700 | [diff] [blame] | 454 | $(OUTPUT)/bench_rename.o \ |
Andrii Nakryiko | c97099b | 2020-05-29 00:54:23 -0700 | [diff] [blame] | 455 | $(OUTPUT)/bench_trigger.o \ |
| 456 | $(OUTPUT)/bench_ringbufs.o |
Andrii Nakryiko | 8e7c2a0 | 2020-05-12 12:24:43 -0700 | [diff] [blame] | 457 | $(call msg,BINARY,,$@) |
Andrii Nakryiko | d5ca590 | 2020-08-06 20:30:57 -0700 | [diff] [blame] | 458 | $(Q)$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS) |
Andrii Nakryiko | 8e7c2a0 | 2020-05-12 12:24:43 -0700 | [diff] [blame] | 459 | |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 460 | EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) \ |
Andrii Nakryiko | 74b5a59 | 2019-10-15 23:00:49 -0700 | [diff] [blame] | 461 | prog_tests/tests.h map_tests/tests.h verifier/tests.h \ |
Andrii Nakryiko | 2031af2 | 2020-01-09 21:17:14 -0800 | [diff] [blame] | 462 | feature \ |
Toke Høiland-Jørgensen | a2c9652 | 2020-01-20 14:06:52 +0100 | [diff] [blame] | 463 | $(addprefix $(OUTPUT)/,*.o *.skel.h no_alu32 bpf_gcc) |