blob: 8567a858b789340598f7aa3f7a8ce553b5bdea09 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Hendrik Brueckner618e1652017-12-04 10:56:48 +01002
Mickaël Salaünd498f872017-02-11 23:20:23 +01003LIBDIR := ../../../lib
Zi Shen Lime8f1f342017-03-19 23:03:14 -07004BPFDIR := $(LIBDIR)/bpf
Daniel Borkmann02ea80b2017-03-31 02:24:04 +02005APIDIR := ../../../include/uapi
6GENDIR := ../../../../include/generated
7GENHDR := $(GENDIR)/autoconf.h
Mickaël Salaünd498f872017-02-11 23:20:23 +01008
Daniel Borkmann02ea80b2017-03-31 02:24:04 +02009ifneq ($(wildcard $(GENHDR)),)
10 GENFLAGS := -DHAVE_GENHDR
11endif
12
Daniel Borkmann720f2282017-12-12 02:25:32 +010013CFLAGS += -Wall -O2 -I$(APIDIR) -I$(LIBDIR) -I$(GENDIR) $(GENFLAGS) -I../../../include
Yonghong Songaf32efe2018-01-26 15:06:08 -080014LDLIBS += -lcap -lelf -lrt -lpthread
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020015
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010016# Order correspond to 'make run_tests' order
David S. Miller18b3ad92017-05-10 11:43:51 -070017TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test_progs \
Lawrence Brakmod6d4f602018-01-25 16:14:16 -080018 test_align test_verifier_log test_dev_cgroup test_tcpbpf_user
Alexei Starovoitov68828042017-03-30 21:45:41 -070019
Yonghong Song18f3d6b2017-06-13 15:52:14 -070020TEST_GEN_FILES = test_pkt_access.o test_xdp.o test_l4lb.o test_tcp_estats.o test_obj_id.o \
Daniel Borkmann22c88522017-09-25 02:25:53 +020021 test_pkt_md_access.o test_xdp_redirect.o test_xdp_meta.o sockmap_parse_prog.o \
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080022 sockmap_verdict_prog.o dev_cgroup.o sample_ret0.o test_tracepoint.o \
Jakub Kicinski7fedbb7c2018-01-17 19:13:31 -080023 test_l4lb_noinline.o test_xdp_noinline.o test_stacktrace_map.o \
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010024 sample_map_ret0.o test_tcpbpf_kern.o
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020025
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010026# Order correspond to 'make run_tests' order
27TEST_PROGS := test_kmod.sh \
28 test_libbpf.sh \
29 test_xdp_redirect.sh \
30 test_xdp_meta.sh \
Jakub Kicinski417ec262017-12-01 15:09:00 -080031 test_offload.py
Daniel Borkmann5aa5bd12016-10-17 14:28:36 +020032
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010033# Compile but not part of 'make run_tests'
34TEST_GEN_PROGS_EXTENDED = test_libbpf_open
35
Zi Shen Lime8f1f342017-03-19 23:03:14 -070036include ../lib.mk
Alexei Starovoitov1da8ac72017-03-10 22:05:55 -080037
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010038BPFOBJ := $(OUTPUT)/libbpf.a
Zi Shen Lime8f1f342017-03-19 23:03:14 -070039
40$(TEST_GEN_PROGS): $(BPFOBJ)
41
Jesper Dangaard Brouerf09b2e32018-02-08 12:48:27 +010042$(TEST_GEN_PROGS_EXTENDED): $(OUTPUT)/libbpf.a
43
Jesper Dangaard Brouer41757dc2018-02-13 14:19:15 +010044$(OUTPUT)/test_dev_cgroup: cgroup_helpers.c
45
Zi Shen Lime8f1f342017-03-19 23:03:14 -070046.PHONY: force
Mickaël Salaünd498f872017-02-11 23:20:23 +010047
Mickaël Salaünd498f872017-02-11 23:20:23 +010048# force a rebuild of BPFOBJ when its dependencies are updated
49force:
50
51$(BPFOBJ): force
Zi Shen Lime8f1f342017-03-19 23:03:14 -070052 $(MAKE) -C $(BPFDIR) OUTPUT=$(OUTPUT)/
Alexei Starovoitov68828042017-03-30 21:45:41 -070053
54CLANG ?= clang
Daniel Borkmann22c88522017-09-25 02:25:53 +020055LLC ?= llc
56
Quentin Monnetcd95a892017-12-21 08:52:50 -080057PROBE := $(shell $(LLC) -march=bpf -mcpu=probe -filetype=null /dev/null 2>&1)
Daniel Borkmann22c88522017-09-25 02:25:53 +020058
59# Let newer LLVM versions transparently probe the kernel for availability
60# of full BPF instruction set.
61ifeq ($(PROBE),)
62 CPU ?= probe
63else
64 CPU ?= generic
65endif
Alexei Starovoitov68828042017-03-30 21:45:41 -070066
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080067CLANG_FLAGS = -I. -I./include/uapi -I../../../include/uapi \
68 -Wno-compare-distinct-pointer-types
69
70$(OUTPUT)/test_l4lb_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitovb0b04fc2017-12-14 17:55:12 -080071$(OUTPUT)/test_xdp_noinline.o: CLANG_FLAGS += -fno-inline
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080072
Yonghong Song62a06992018-01-29 21:23:28 -080073$(OUTPUT)/%.o: %.c
Alexei Starovoitov3bc35c62017-12-14 17:55:11 -080074 $(CLANG) $(CLANG_FLAGS) \
Daniel Borkmann22c88522017-09-25 02:25:53 +020075 -O2 -target bpf -emit-llvm -c $< -o - | \
76 $(LLC) -march=bpf -mcpu=$(CPU) -filetype=obj -o $@