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