Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Hendrik Brueckner | 618e165 | 2017-12-04 10:56:48 +0100 | [diff] [blame] | 2 | |
Mickaël Salaün | d498f87 | 2017-02-11 23:20:23 +0100 | [diff] [blame] | 3 | LIBDIR := ../../../lib |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 4 | BPFDIR := $(LIBDIR)/bpf |
Daniel Borkmann | 02ea80b | 2017-03-31 02:24:04 +0200 | [diff] [blame] | 5 | APIDIR := ../../../include/uapi |
| 6 | GENDIR := ../../../../include/generated |
| 7 | GENHDR := $(GENDIR)/autoconf.h |
Mickaël Salaün | d498f87 | 2017-02-11 23:20:23 +0100 | [diff] [blame] | 8 | |
Daniel Borkmann | 02ea80b | 2017-03-31 02:24:04 +0200 | [diff] [blame] | 9 | ifneq ($(wildcard $(GENHDR)),) |
| 10 | GENFLAGS := -DHAVE_GENHDR |
| 11 | endif |
| 12 | |
Jakub Kicinski | d0cabbb | 2018-05-10 10:24:40 -0700 | [diff] [blame] | 13 | CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(BPFDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include |
Yonghong Song | af32efe | 2018-01-26 15:06:08 -0800 | [diff] [blame] | 14 | LDLIBS += -lcap -lelf -lrt -lpthread |
Daniel Borkmann | 5aa5bd1 | 2016-10-17 14:28:36 +0200 | [diff] [blame] | 15 | |
Song Liu | 81f77fd | 2018-03-14 10:23:22 -0700 | [diff] [blame] | 16 | TEST_CUSTOM_PROGS = $(OUTPUT)/urandom_read |
| 17 | all: $(TEST_CUSTOM_PROGS) |
| 18 | |
Anders Roxell | 1c9ca7e | 2018-06-08 08:51:27 +0200 | [diff] [blame] | 19 | $(TEST_CUSTOM_PROGS): $(OUTPUT)/%: %.c |
Alexei Starovoitov | f2467c2 | 2018-05-14 17:11:29 -0700 | [diff] [blame] | 20 | $(CC) -o $(TEST_CUSTOM_PROGS) -static $< -Wl,--build-id |
Song Liu | 81f77fd | 2018-03-14 10:23:22 -0700 | [diff] [blame] | 21 | |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 22 | # Order correspond to 'make run_tests' order |
David S. Miller | 18b3ad9 | 2017-05-10 11:43:51 -0700 | [diff] [blame] | 23 | TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \ |
Andrey Ignatov | 1d43688 | 2018-03-30 15:08:08 -0700 | [diff] [blame] | 24 | test_align test_verifier_log test_dev_cgroup test_tcpbpf_user \ |
Yonghong Song | f269099 | 2018-06-03 15:59:43 -0700 | [diff] [blame] | 25 | test_sock test_btf test_sockmap test_lirc_mode2_user get_cgroup_id_user |
Alexei Starovoitov | 6882804 | 2017-03-30 21:45:41 -0700 | [diff] [blame] | 26 | |
Yonghong Song | 18f3d6b | 2017-06-13 15:52:14 -0700 | [diff] [blame] | 27 | TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \ |
Daniel Borkmann | 22c8852 | 2017-09-25 02:25:53 +0200 | [diff] [blame] | 28 | test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \ |
Alexei Starovoitov | 3bc35c6 | 2017-12-14 17:55:11 -0800 | [diff] [blame] | 29 | sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \ |
Jakub Kicinski | 7fedbb7c | 2018-01-17 19:13:31 -0800 | [diff] [blame] | 30 | test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \ |
John Fastabend | 82a8616 | 2018-03-18 12:57:31 -0700 | [diff] [blame] | 31 | sample_map_ret0.o test_tcpbpf_kern.o test_stacktrace_build_id.o \ |
Martin KaFai Lau | c0fa1b6 | 2018-04-18 15:56:06 -0700 | [diff] [blame] | 32 | sockmap_tcp_msg_prog.o connect4_prog.o connect6_prog.o test_adjust_tail.o \ |
Yonghong Song | 173965f | 2018-04-28 22:28:15 -0700 | [diff] [blame] | 33 | test_btf_haskv.o test_btf_nokv.o test_sockmap_kern.o test_tunnel_kern.o \ |
Mathieu Xhonneux | c99a84e | 2018-05-20 14:58:17 +0100 | [diff] [blame] | 34 | test_get_stack_rawtp.o test_sockmap_kern.o test_sockhash_kern.o \ |
Yonghong Song | f269099 | 2018-06-03 15:59:43 -0700 | [diff] [blame] | 35 | test_lwt_seg6local.o sendmsg4_prog.o sendmsg6_prog.o test_lirc_mode2_kern.o \ |
| 36 | get_cgroup_id_kern.o |
Daniel Borkmann | 5aa5bd1 | 2016-10-17 14:28:36 +0200 | [diff] [blame] | 37 | |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 38 | # Order correspond to 'make run_tests' order |
| 39 | TEST_PROGS := test_kmod.sh \ |
| 40 | test_libbpf.sh \ |
| 41 | test_xdp_redirect.sh \ |
| 42 | test_xdp_meta.sh \ |
Andrey Ignatov | 622adaf | 2018-03-30 15:08:06 -0700 | [diff] [blame] | 43 | test_offload.py \ |
William Tu | 933a741 | 2018-04-26 14:01:39 -0700 | [diff] [blame] | 44 | test_sock_addr.sh \ |
Mathieu Xhonneux | c99a84e | 2018-05-20 14:58:17 +0100 | [diff] [blame] | 45 | test_tunnel.sh \ |
Sean Young | 6bdd533 | 2018-05-27 12:24:10 +0100 | [diff] [blame] | 46 | test_lwt_seg6local.sh \ |
| 47 | test_lirc_mode2.sh |
Daniel Borkmann | 5aa5bd1 | 2016-10-17 14:28:36 +0200 | [diff] [blame] | 48 | |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 49 | # Compile but not part of 'make run_tests' |
Yonghong Song | 6595c74 | 2018-04-24 14:45:04 -0700 | [diff] [blame] | 50 | TEST_GEN_PROGS_EXTENDED = test_libbpf_open test_sock_addr |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 51 | |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 52 | include ../lib.mk |
Alexei Starovoitov | 1da8ac7 | 2017-03-10 22:05:55 -0800 | [diff] [blame] | 53 | |
Jesper Dangaard Brouer | 41757dc | 2018-02-13 14:19:15 +0100 | [diff] [blame] | 54 | BPFOBJ := $(OUTPUT)/libbpf.a |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 55 | |
| 56 | $(TEST_GEN_PROGS): $(BPFOBJ) |
| 57 | |
Jesper Dangaard Brouer | f09b2e3 | 2018-02-08 12:48:27 +0100 | [diff] [blame] | 58 | $(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a |
| 59 | |
Jesper Dangaard Brouer | 41757dc | 2018-02-13 14:19:15 +0100 | [diff] [blame] | 60 | $(OUTPUT)/test_dev_cgroup: cgroup_helpers.c |
Andrey Ignatov | 1d43688 | 2018-03-30 15:08:08 -0700 | [diff] [blame] | 61 | $(OUTPUT)/test_sock: cgroup_helpers.c |
Andrey Ignatov | e50b0a6 | 2018-03-30 15:08:03 -0700 | [diff] [blame] | 62 | $(OUTPUT)/test_sock_addr: cgroup_helpers.c |
John Fastabend | 16962b2 | 2018-04-23 14:30:38 -0700 | [diff] [blame] | 63 | $(OUTPUT)/test_sockmap: cgroup_helpers.c |
Yonghong Song | 173965f | 2018-04-28 22:28:15 -0700 | [diff] [blame] | 64 | $(OUTPUT)/test_progs: trace_helpers.c |
Yonghong Song | f269099 | 2018-06-03 15:59:43 -0700 | [diff] [blame] | 65 | $(OUTPUT)/get_cgroup_id_user: cgroup_helpers.c |
Jesper Dangaard Brouer | 41757dc | 2018-02-13 14:19:15 +0100 | [diff] [blame] | 66 | |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 67 | .PHONY: force |
Mickaël Salaün | d498f87 | 2017-02-11 23:20:23 +0100 | [diff] [blame] | 68 | |
Mickaël Salaün | d498f87 | 2017-02-11 23:20:23 +0100 | [diff] [blame] | 69 | # force a rebuild of BPFOBJ when its dependencies are updated |
| 70 | force: |
| 71 | |
| 72 | $(BPFOBJ): force |
Zi Shen Lim | e8f1f34 | 2017-03-19 23:03:14 -0700 | [diff] [blame] | 73 | $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/ |
Alexei Starovoitov | 6882804 | 2017-03-30 21:45:41 -0700 | [diff] [blame] | 74 | |
| 75 | CLANG ?= clang |
Daniel Borkmann | 22c8852 | 2017-09-25 02:25:53 +0200 | [diff] [blame] | 76 | LLC ?= llc |
Martin KaFai Lau | c0fa1b6 | 2018-04-18 15:56:06 -0700 | [diff] [blame] | 77 | LLVM_OBJCOPY ?= llvm-objcopy |
| 78 | BTF_PAHOLE ?= pahole |
Daniel Borkmann | 22c8852 | 2017-09-25 02:25:53 +0200 | [diff] [blame] | 79 | |
Quentin Monnet | cd95a89 | 2017-12-21 08:52:50 -0800 | [diff] [blame] | 80 | PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1) |
Daniel Borkmann | 22c8852 | 2017-09-25 02:25:53 +0200 | [diff] [blame] | 81 | |
| 82 | # Let newer LLVM versions transparently probe the kernel for availability |
| 83 | # of full BPF instruction set. |
| 84 | ifeq ($(PROBE),) |
| 85 | CPU ?= probe |
| 86 | else |
| 87 | CPU ?= generic |
| 88 | endif |
Alexei Starovoitov | 6882804 | 2017-03-30 21:45:41 -0700 | [diff] [blame] | 89 | |
Sirio Balmelli | 167381f | 2018-05-21 09:00:03 +0200 | [diff] [blame] | 90 | # Get Clang's default includes on this system, as opposed to those seen by |
| 91 | # '-target bpf'. This fixes "missing" files on some architectures/distros, |
| 92 | # such as asm/byteorder.h, asm/socket.h, asm/sockios.h, sys/cdefs.h etc. |
| 93 | # |
| 94 | # Use '-idirafter': Don't interfere with include mechanics except where the |
| 95 | # build would have failed anyways. |
| 96 | CLANG_SYS_INCLUDES := $(shell $(CLANG) -v -E - </dev/null 2>&1 \ |
| 97 | | sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') |
| 98 | |
Alexei Starovoitov | 3bc35c6 | 2017-12-14 17:55:11 -0800 | [diff] [blame] | 99 | CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \ |
Sirio Balmelli | 167381f | 2018-05-21 09:00:03 +0200 | [diff] [blame] | 100 | $(CLANG_SYS_INCLUDES) \ |
Alexei Starovoitov | 3bc35c6 | 2017-12-14 17:55:11 -0800 | [diff] [blame] | 101 | -Wno-compare-distinct-pointer-types |
| 102 | |
| 103 | $(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline |
Alexei Starovoitov | b0b04fc | 2017-12-14 17:55:12 -0800 | [diff] [blame] | 104 | $(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline |
Alexei Starovoitov | 3bc35c6 | 2017-12-14 17:55:11 -0800 | [diff] [blame] | 105 | |
Joe Stringer | 91bc07c | 2018-05-10 15:26:51 -0700 | [diff] [blame] | 106 | BTF_LLC_PROBE := $(shell $(LLC) -march=bpf -mattr=help 2>&1 | grep dwarfris) |
| 107 | BTF_PAHOLE_PROBE := $(shell $(BTF_PAHOLE) --help 2>&1 | grep BTF) |
| 108 | BTF_OBJCOPY_PROBE := $(shell $(LLVM_OBJCOPY) --version 2>&1 | grep LLVM) |
Martin KaFai Lau | c0fa1b6 | 2018-04-18 15:56:06 -0700 | [diff] [blame] | 109 | |
| 110 | ifneq ($(BTF_LLC_PROBE),) |
| 111 | ifneq ($(BTF_PAHOLE_PROBE),) |
| 112 | ifneq ($(BTF_OBJCOPY_PROBE),) |
| 113 | CLANG_FLAGS += -g |
| 114 | LLC_FLAGS += -mattr=dwarfris |
| 115 | DWARF2BTF = y |
| 116 | endif |
| 117 | endif |
| 118 | endif |
| 119 | |
Yonghong Song | 62a0699 | 2018-01-29 21:23:28 -0800 | [diff] [blame] | 120 | $(OUTPUT)/%.o: %.c |
Alexei Starovoitov | 3bc35c6 | 2017-12-14 17:55:11 -0800 | [diff] [blame] | 121 | $(CLANG) $(CLANG_FLAGS) \ |
Daniel Borkmann | 22c8852 | 2017-09-25 02:25:53 +0200 | [diff] [blame] | 122 | -O2 -target bpf -emit-llvm -c $< -o - | \ |
Martin KaFai Lau | c0fa1b6 | 2018-04-18 15:56:06 -0700 | [diff] [blame] | 123 | $(LLC) -march=bpf -mcpu=$(CPU) $(LLC_FLAGS) -filetype=obj -o $@ |
| 124 | ifeq ($(DWARF2BTF),y) |
| 125 | $(BTF_PAHOLE) -J $@ |
| 126 | endif |
Song Liu | 81f77fd | 2018-03-14 10:23:22 -0700 | [diff] [blame] | 127 | |
| 128 | EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) |