^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) include ../../../../scripts/Kbuild.include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) include ../../../scripts/Makefile.arch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) CXX ?= $(CROSS_COMPILE)g++
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) CURDIR := $(abspath .)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) TOOLSDIR := $(abspath ../../..)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) LIBDIR := $(TOOLSDIR)/lib
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) BPFDIR := $(LIBDIR)/bpf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) TOOLSINCDIR := $(TOOLSDIR)/include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) BPFTOOLDIR := $(TOOLSDIR)/bpf/bpftool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) APIDIR := $(TOOLSINCDIR)/uapi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) GENDIR := $(abspath ../../../../include/generated)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) GENHDR := $(GENDIR)/autoconf.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) ifneq ($(wildcard $(GENHDR)),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) GENFLAGS := -DHAVE_GENHDR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) CLANG ?= clang
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) LLC ?= llc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) LLVM_OBJCOPY ?= llvm-objcopy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) BPF_GCC ?= $(shell command -v bpf-gcc;)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) SAN_CFLAGS ?=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) CFLAGS += -g -rdynamic -Wall -O2 $(GENFLAGS) $(SAN_CFLAGS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) -I$(CURDIR) -I$(INCLUDE_DIR) -I$(GENDIR) -I$(LIBDIR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) -I$(TOOLSINCDIR) -I$(APIDIR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) -Dbpf_prog_load=bpf_prog_test_load \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) -Dbpf_load_program=bpf_test_load_program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) LDLIBS += -lcap -lelf -lz -lrt -lpthread
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) # Order correspond to 'make run_tests' order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) test_verifier_log test_dev_cgroup test_tcpbpf_user \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) test_sock test_sockmap get_cgroup_id_user test_socket_cookie \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) test_cgroup_storage \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) test_netcnt test_tcpnotify_user test_sysctl \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) test_progs-no_alu32 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) test_current_pid_tgid_new_ns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) # Also test bpf-gcc, if present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) ifneq ($(BPF_GCC),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) TEST_GEN_PROGS += test_progs-bpf_gcc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) TEST_GEN_FILES =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) TEST_FILES = test_lwt_ip_encap.o \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) test_tc_edt.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) # Order correspond to 'make run_tests' order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) TEST_PROGS := test_kmod.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) test_xdp_redirect.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) test_xdp_meta.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) test_xdp_veth.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) test_offload.py \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) test_sock_addr.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) test_tunnel.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) test_lwt_seg6local.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) test_lirc_mode2.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) test_skb_cgroup_id.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) test_flow_dissector.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) test_xdp_vlan_mode_generic.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) test_xdp_vlan_mode_native.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) test_lwt_ip_encap.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) test_tcp_check_syncookie.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) test_tc_tunnel.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) test_tc_edt.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) test_xdping.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) test_bpftool_build.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) test_bpftool.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) test_bpftool_metadata.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) TEST_PROGS_EXTENDED := with_addr.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) with_tunnels.sh \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) tcp_client.py \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) tcp_server.py \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) test_xdp_vlan.sh
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) # Compile but not part of 'make run_tests'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) test_lirc_mode2_user xdping test_cpp runqslower bench
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) TEST_CUSTOM_PROGS = urandom_read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) # Emit succinct information message describing current building step
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) # $1 - generic step name (e.g., CC, LINK, etc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) # $2 - optional "flavor" specifier; if provided, will be emitted as [flavor];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) # $3 - target (assumed to be file); only file name will be emitted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) # $4 - optional extra arg, emitted as-is, if provided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) ifeq ($(V),1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) Q =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) msg =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) Q = @
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) msg = @printf ' %-8s%s %s%s\n' "$(1)" "$(if $(2), [$(2)])" "$(notdir $(3))" "$(if $(4), $(4))";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) MAKEFLAGS += --no-print-directory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) submake_extras := feature_display=0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) # override lib.mk's default rules
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) OVERRIDE_TARGETS := 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) override define CLEAN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) $(call msg,CLEAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) $(Q)$(RM) -r $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES) $(EXTRA_CLEAN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) include ../lib.mk
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) SCRATCH_DIR := $(OUTPUT)/tools
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) BUILD_DIR := $(SCRATCH_DIR)/build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) INCLUDE_DIR := $(SCRATCH_DIR)/include
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) BPFOBJ := $(BUILD_DIR)/libbpf/libbpf.a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) RESOLVE_BTFIDS := $(BUILD_DIR)/resolve_btfids/resolve_btfids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) # Define simple and short `make test_progs`, `make test_sysctl`, etc targets
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) # to build individual tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) # NOTE: Semicolon at the end is critical to override lib.mk's default static
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) # rule for binaries.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) $(notdir $(TEST_GEN_PROGS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) $(TEST_PROGS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) $(TEST_PROGS_EXTENDED) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) $(TEST_GEN_PROGS_EXTENDED) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) $(TEST_CUSTOM_PROGS)): %: $(OUTPUT)/% ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) $(OUTPUT)/%.o: %.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) $(call msg,CC,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) $(OUTPUT)/%:%.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) $(call msg,BINARY,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) $(Q)$(LINK.c) $^ $(LDLIBS) -o $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) $(OUTPUT)/urandom_read: urandom_read.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) $(call msg,BINARY,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) $(Q)$(CC) $(LDFLAGS) -o $@ $< $(LDLIBS) -Wl,--build-id=sha1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) $(OUTPUT)/test_stub.o: test_stub.c $(BPFOBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) $(call msg,CC,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) $(Q)$(CC) -c $(CFLAGS) -o $@ $<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) VMLINUX_BTF_PATHS ?= $(if $(O),$(O)/vmlinux) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) $(if $(KBUILD_OUTPUT),$(KBUILD_OUTPUT)/vmlinux) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ../../../../vmlinux \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /sys/kernel/btf/vmlinux \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /boot/vmlinux-$(shell uname -r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) VMLINUX_BTF ?= $(abspath $(firstword $(wildcard $(VMLINUX_BTF_PATHS))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ifeq ($(VMLINUX_BTF),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) $(error Cannot find a vmlinux for VMLINUX_BTF at any of "$(VMLINUX_BTF_PATHS)")
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) DEFAULT_BPFTOOL := $(SCRATCH_DIR)/sbin/bpftool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) $(OUTPUT)/runqslower: $(BPFOBJ) | $(DEFAULT_BPFTOOL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/runqslower \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) OUTPUT=$(SCRATCH_DIR)/ VMLINUX_BTF=$(VMLINUX_BTF) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) BPFOBJ=$(BPFOBJ) BPF_INCLUDE=$(INCLUDE_DIR) && \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) cp $(SCRATCH_DIR)/runqslower $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/test_stub.o $(BPFOBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) $(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) $(OUTPUT)/test_skb_cgroup_id_user: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) $(OUTPUT)/test_sock: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) $(OUTPUT)/test_sock_addr: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) $(OUTPUT)/test_socket_cookie: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) $(OUTPUT)/test_sockmap: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) $(OUTPUT)/test_tcpbpf_user: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) $(OUTPUT)/test_tcpnotify_user: cgroup_helpers.c trace_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) $(OUTPUT)/test_cgroup_storage: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) $(OUTPUT)/test_netcnt: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) $(OUTPUT)/test_sock_fields: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) $(OUTPUT)/test_sysctl: cgroup_helpers.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) BPFTOOL ?= $(DEFAULT_BPFTOOL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) $(BPFOBJ) | $(BUILD_DIR)/bpftool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) $(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) OUTPUT=$(BUILD_DIR)/bpftool/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) prefix= DESTDIR=$(SCRATCH_DIR)/ install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) $(Q)mkdir -p $(BUILD_DIR)/bpftool/Documentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) $(Q)RST2MAN_OPTS="--exit-status=1" $(MAKE) $(submake_extras) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) -C $(BPFTOOLDIR)/Documentation \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) OUTPUT=$(BUILD_DIR)/bpftool/Documentation/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) prefix= DESTDIR=$(SCRATCH_DIR)/ install
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) $(BPFOBJ): $(wildcard $(BPFDIR)/*.[ch] $(BPFDIR)/Makefile) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ../../../include/uapi/linux/bpf.h \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) | $(INCLUDE_DIR) $(BUILD_DIR)/libbpf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) $(Q)$(MAKE) $(submake_extras) -C $(BPFDIR) OUTPUT=$(BUILD_DIR)/libbpf/ \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) DESTDIR=$(SCRATCH_DIR) prefix= all install_headers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) $(BUILD_DIR)/libbpf $(BUILD_DIR)/bpftool $(BUILD_DIR)/resolve_btfids $(INCLUDE_DIR):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) $(call msg,MKDIR,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) $(Q)mkdir -p $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) $(INCLUDE_DIR)/vmlinux.h: $(VMLINUX_BTF) $(BPFTOOL) | $(INCLUDE_DIR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) ifeq ($(VMLINUX_H),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) $(call msg,GEN,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) $(Q)$(BPFTOOL) btf dump file $(VMLINUX_BTF) format c > $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) $(call msg,CP,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) $(Q)cp "$(VMLINUX_H)" $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) $(RESOLVE_BTFIDS): $(BPFOBJ) | $(BUILD_DIR)/resolve_btfids \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) $(TOOLSDIR)/bpf/resolve_btfids/main.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) $(TOOLSDIR)/lib/rbtree.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) $(TOOLSDIR)/lib/zalloc.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) $(TOOLSDIR)/lib/string.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) $(TOOLSDIR)/lib/ctype.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) $(TOOLSDIR)/lib/str_error_r.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) $(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) OUTPUT=$(BUILD_DIR)/resolve_btfids/ BPFOBJ=$(BPFOBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) # Get Clang's default includes on this system, as opposed to those seen by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) # '-target bpf'. This fixes "missing" files on some architectures/distros,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) # Use '-idirafter': Don't interfere with include mechanics except where the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) # build would have failed anyways.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) define get_sys_includes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) $(shell $(1) -v -E - </dev/null 2>&1 \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) $(shell $(1) -dM -E - </dev/null | grep '#define __riscv_xlen ' | sed 's/#define /-D/' | sed 's/ /=/')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) # Determine target endianness.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) IS_LITTLE_ENDIAN = $(shell $(CC) -dM -E - </dev/null | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) grep 'define __BYTE_ORDER__ __ORDER_LITTLE_ENDIAN__')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) -I$(abspath $(OUTPUT)/../usr/include)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) -Wno-compare-distinct-pointer-types
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) $(OUTPUT)/test_l4lb_noinline.o: BPF_CFLAGS += -fno-inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) $(OUTPUT)/test_xdp_noinline.o: BPF_CFLAGS += -fno-inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) $(OUTPUT)/flow_dissector_load.o: flow_dissector_load.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) # Build BPF object using Clang
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) # $1 - input .c file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) # $2 - output .o file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) # $3 - CFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) # $4 - LDFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) define CLANG_BPF_BUILD_RULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) $(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) $(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) -c $1 -o - || echo "BPF obj compilation failed") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) $(LLC) -mattr=dwarfris -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) # Similar to CLANG_BPF_BUILD_RULE, but with disabled alu32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) define CLANG_NOALU32_BPF_BUILD_RULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) $(call msg,CLNG-LLC,$(TRUNNER_BINARY),$2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) $(Q)($(CLANG) $3 -O2 -target bpf -emit-llvm \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) -c $1 -o - || echo "BPF obj compilation failed") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) $(LLC) -march=bpf -mcpu=v2 $4 -filetype=obj -o $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) # Similar to CLANG_BPF_BUILD_RULE, but using native Clang and bpf LLC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) define CLANG_NATIVE_BPF_BUILD_RULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) $(call msg,CLNG-BPF,$(TRUNNER_BINARY),$2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) $(Q)($(CLANG) $3 -O2 -emit-llvm \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) -c $1 -o - || echo "BPF obj compilation failed") | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) $(LLC) -march=bpf -mcpu=v3 $4 -filetype=obj -o $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) # Build BPF object using GCC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) define GCC_BPF_BUILD_RULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) $(call msg,GCC-BPF,$(TRUNNER_BINARY),$2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) $(Q)$(BPF_GCC) $3 $4 -O2 -c $1 -o $2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) SKEL_BLACKLIST := btf__% test_pinning_invalid.c test_sk_assign.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) # Set up extra TRUNNER_XXX "temporary" variables in the environment (relies on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) # Parameters:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) # $1 - test runner base binary name (e.g., test_progs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) define DEFINE_TEST_RUNNER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) TRUNNER_BINARY := $1$(if $2,-)$2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) TRUNNER_TEST_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.test.o, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) $$(notdir $$(wildcard $(TRUNNER_TESTS_DIR)/*.c)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) TRUNNER_EXTRA_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) $$(filter %.c,$(TRUNNER_EXTRA_SOURCES)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) TRUNNER_EXTRA_HDRS := $$(filter %.h,$(TRUNNER_EXTRA_SOURCES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) TRUNNER_TESTS_HDR := $(TRUNNER_TESTS_DIR)/tests.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) TRUNNER_BPF_SRCS := $$(notdir $$(wildcard $(TRUNNER_BPF_PROGS_DIR)/*.c))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) TRUNNER_BPF_OBJS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.o, $$(TRUNNER_BPF_SRCS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) TRUNNER_BPF_SKELS := $$(patsubst %.c,$$(TRUNNER_OUTPUT)/%.skel.h, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) $$(filter-out $(SKEL_BLACKLIST), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) $$(TRUNNER_BPF_SRCS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) TEST_GEN_FILES += $$(TRUNNER_BPF_OBJS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) # Evaluate rules now with extra TRUNNER_XXX variables above already defined
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) $$(eval $$(call DEFINE_TEST_RUNNER_RULES,$1,$2))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) # Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) # set up by DEFINE_TEST_RUNNER itself, create test runner build rules with:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) # $1 - test runner base binary name (e.g., test_progs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) # $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) define DEFINE_TEST_RUNNER_RULES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ifeq ($($(TRUNNER_OUTPUT)-dir),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) $(TRUNNER_OUTPUT)-dir := y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) $(TRUNNER_OUTPUT):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) $$(call msg,MKDIR,,$$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) $(Q)mkdir -p $$@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) # ensure we set up BPF objects generation rule just once for a given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) # input/output directory combination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ifeq ($($(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) $(TRUNNER_BPF_PROGS_DIR)$(if $2,-)$2-bpfobjs := y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) $(TRUNNER_BPF_OBJS): $(TRUNNER_OUTPUT)/%.o: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) $(TRUNNER_BPF_PROGS_DIR)/%.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) $(TRUNNER_BPF_PROGS_DIR)/*.h \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) $$(INCLUDE_DIR)/vmlinux.h \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) $(wildcard $(BPFDIR)/bpf_*.h) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) | $(TRUNNER_OUTPUT) $$(BPFOBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) $$(call $(TRUNNER_BPF_BUILD_RULE),$$<,$$@, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) $(TRUNNER_BPF_CFLAGS), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) $(TRUNNER_BPF_LDFLAGS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) $(TRUNNER_BPF_SKELS): $(TRUNNER_OUTPUT)/%.skel.h: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) $(TRUNNER_OUTPUT)/%.o \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) $(BPFTOOL) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) | $(TRUNNER_OUTPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) $$(call msg,GEN-SKEL,$(TRUNNER_BINARY),$$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) $(Q)$$(BPFTOOL) gen skeleton $$< > $$@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) # ensure we set up tests.h header generation rule just once
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ifeq ($($(TRUNNER_TESTS_DIR)-tests-hdr),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) $(TRUNNER_TESTS_DIR)-tests-hdr := y
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) $(TRUNNER_TESTS_HDR): $(TRUNNER_TESTS_DIR)/*.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) $$(call msg,TEST-HDR,$(TRUNNER_BINARY),$$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) $$(shell ( cd $(TRUNNER_TESTS_DIR); \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) echo '/* Generated header, do not edit */'; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) ls *.c 2> /dev/null | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) sed -e 's@\([^\.]*\)\.c@DEFINE_TEST(\1)@'; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) ) > $$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) # compile individual test files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) # Note: we cd into output directory to ensure embedded BPF object is found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) $(TRUNNER_TEST_OBJS): $(TRUNNER_OUTPUT)/%.test.o: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) $(TRUNNER_TESTS_DIR)/%.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) $(TRUNNER_EXTRA_HDRS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) $(TRUNNER_BPF_OBJS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) $(TRUNNER_BPF_SKELS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) $$(BPFOBJ) | $(TRUNNER_OUTPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) $$(call msg,TEST-OBJ,$(TRUNNER_BINARY),$$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) $(Q)cd $$(@D) && $$(CC) -I. $$(CFLAGS) -c $(CURDIR)/$$< $$(LDLIBS) -o $$(@F)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) $(TRUNNER_EXTRA_OBJS): $(TRUNNER_OUTPUT)/%.o: \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) %.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) $(TRUNNER_EXTRA_HDRS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) $(TRUNNER_TESTS_HDR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) $$(BPFOBJ) | $(TRUNNER_OUTPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) $$(call msg,EXT-OBJ,$(TRUNNER_BINARY),$$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) $(Q)$$(CC) $$(CFLAGS) -c $$< $$(LDLIBS) -o $$@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) # only copy extra resources if in flavored build
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) $(TRUNNER_BINARY)-extras: $(TRUNNER_EXTRA_FILES) | $(TRUNNER_OUTPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) ifneq ($2,)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) $$(call msg,EXT-COPY,$(TRUNNER_BINARY),$(TRUNNER_EXTRA_FILES))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) $(Q)cp -a $$^ $(TRUNNER_OUTPUT)/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) $(OUTPUT)/$(TRUNNER_BINARY): $(TRUNNER_TEST_OBJS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) $(TRUNNER_EXTRA_OBJS) $$(BPFOBJ) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) $(RESOLVE_BTFIDS) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) | $(TRUNNER_BINARY)-extras
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) $$(call msg,BINARY,,$$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) $(Q)$$(CC) $$(CFLAGS) $$(filter %.a %.o,$$^) $$(LDLIBS) -o $$@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) $(Q)$(RESOLVE_BTFIDS) --no-fail --btf btf_data.o $$@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) endef
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) # Define test_progs test runner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) TRUNNER_TESTS_DIR := prog_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) TRUNNER_BPF_PROGS_DIR := progs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) TRUNNER_EXTRA_SOURCES := test_progs.c cgroup_helpers.c trace_helpers.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) network_helpers.c testing_helpers.c \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) flow_dissector_load.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) $(wildcard progs/btf_dump_test_case_*.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) TRUNNER_BPF_LDFLAGS := -mattr=+alu32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) $(eval $(call DEFINE_TEST_RUNNER,test_progs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) # Define test_progs-no_alu32 test runner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) TRUNNER_BPF_BUILD_RULE := CLANG_NOALU32_BPF_BUILD_RULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) TRUNNER_BPF_LDFLAGS :=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) $(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) # Define test_progs BPF-GCC-flavored test runner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) ifneq ($(BPF_GCC),)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) TRUNNER_BPF_BUILD_RULE := GCC_BPF_BUILD_RULE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(call get_sys_includes,gcc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) TRUNNER_BPF_LDFLAGS :=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) $(eval $(call DEFINE_TEST_RUNNER,test_progs,bpf_gcc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) # Define test_maps test runner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) TRUNNER_TESTS_DIR := map_tests
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) TRUNNER_BPF_PROGS_DIR := progs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) TRUNNER_EXTRA_SOURCES := test_maps.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) TRUNNER_EXTRA_FILES :=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) TRUNNER_BPF_BUILD_RULE := $$(error no BPF objects should be built)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) TRUNNER_BPF_CFLAGS :=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) TRUNNER_BPF_LDFLAGS :=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) $(eval $(call DEFINE_TEST_RUNNER,test_maps))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) # Define test_verifier test runner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) # It is much simpler than test_maps/test_progs and sufficiently different from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) # them (e.g., test.h is using completely pattern), that it's worth just
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) # explicitly defining all the rules explicitly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) verifier/tests.h: verifier/*.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) $(shell ( cd verifier/; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) echo '/* Generated header, do not edit */'; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) echo '#ifdef FILL_ARRAY'; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) ls *.c 2> /dev/null | sed -e 's@\(.*\)@#include \"\1\"@'; \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) echo '#endif' \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) ) > verifier/tests.h)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) $(call msg,BINARY,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) $(Q)$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) # Make sure we are able to include and link libbpf against c++.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) $(OUTPUT)/test_cpp: test_cpp.cpp $(OUTPUT)/test_core_extern.skel.h $(BPFOBJ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) $(call msg,CXX,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) $(Q)$(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) # Benchmark runner
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) $(OUTPUT)/bench_%.o: benchs/bench_%.c bench.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) $(call msg,CC,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) $(Q)$(CC) $(CFLAGS) -c $(filter %.c,$^) $(LDLIBS) -o $@
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) $(OUTPUT)/bench_rename.o: $(OUTPUT)/test_overhead.skel.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) $(OUTPUT)/bench_trigger.o: $(OUTPUT)/trigger_bench.skel.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) $(OUTPUT)/bench_ringbufs.o: $(OUTPUT)/ringbuf_bench.skel.h \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) $(OUTPUT)/perfbuf_bench.skel.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) $(OUTPUT)/bench.o: bench.h testing_helpers.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) $(OUTPUT)/bench: LDLIBS += -lm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) $(OUTPUT)/bench: $(OUTPUT)/bench.o $(OUTPUT)/testing_helpers.o \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) $(OUTPUT)/bench_count.o \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) $(OUTPUT)/bench_rename.o \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) $(OUTPUT)/bench_trigger.o \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) $(OUTPUT)/bench_ringbufs.o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) $(call msg,BINARY,,$@)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) $(Q)$(CC) $(LDFLAGS) -o $@ $(filter %.a %.o,$^) $(LDLIBS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) $(SCRATCH_DIR) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) prog_tests/tests.h map_tests/tests.h verifier/tests.h \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) feature \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) $(addprefix $(OUTPUT)/,*.o *.skel.h no_alu32 bpf_gcc)