bpf: add initial suite for selftests
[linux-2.6-block.git] / samples / bpf / Makefile
CommitLineData
3c731eba
AS
1# kbuild trick to avoid linker error. Can be omitted if a module is built.
2obj- := dummy.o
3
4# List of programs to build
03f4723e 5hostprogs-y += sock_example
42984d7c 6hostprogs-y += fds_example
a8085782 7hostprogs-y += sockex1
fbe33108 8hostprogs-y += sockex2
530b2c86 9hostprogs-y += sockex3
b896c4f9 10hostprogs-y += tracex1
d822a192 11hostprogs-y += tracex2
5c7fc2d2 12hostprogs-y += tracex3
9811e353 13hostprogs-y += tracex4
5bacd780 14hostprogs-y += tracex5
47efb302 15hostprogs-y += tracex6
cf9b1199 16hostprogs-y += test_probe_write_user
39111695 17hostprogs-y += trace_output
0fb1170e 18hostprogs-y += lathist
a6ffe7b9 19hostprogs-y += offwaketime
9d8b612d 20hostprogs-y += spintest
26e90931 21hostprogs-y += map_perf_test
e3edfdec 22hostprogs-y += test_overhead
a3f74617 23hostprogs-y += test_cgrp2_array_pin
86af8b41 24hostprogs-y += xdp1
764cbcce 25hostprogs-y += xdp2
9e6e60ec 26hostprogs-y += test_current_task_under_cgroup
1c47910e 27hostprogs-y += trace_event
72874418 28hostprogs-y += sampleip
3c731eba 29
03f4723e 30sock_example-objs := sock_example.o libbpf.o
42984d7c 31fds_example-objs := bpf_load.o libbpf.o fds_example.o
a8085782 32sockex1-objs := bpf_load.o libbpf.o sockex1_user.o
fbe33108 33sockex2-objs := bpf_load.o libbpf.o sockex2_user.o
530b2c86 34sockex3-objs := bpf_load.o libbpf.o sockex3_user.o
b896c4f9 35tracex1-objs := bpf_load.o libbpf.o tracex1_user.o
d822a192 36tracex2-objs := bpf_load.o libbpf.o tracex2_user.o
5c7fc2d2 37tracex3-objs := bpf_load.o libbpf.o tracex3_user.o
9811e353 38tracex4-objs := bpf_load.o libbpf.o tracex4_user.o
5bacd780 39tracex5-objs := bpf_load.o libbpf.o tracex5_user.o
47efb302 40tracex6-objs := bpf_load.o libbpf.o tracex6_user.o
cf9b1199 41test_probe_write_user-objs := bpf_load.o libbpf.o test_probe_write_user_user.o
39111695 42trace_output-objs := bpf_load.o libbpf.o trace_output_user.o
0fb1170e 43lathist-objs := bpf_load.o libbpf.o lathist_user.o
a6ffe7b9 44offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o
9d8b612d 45spintest-objs := bpf_load.o libbpf.o spintest_user.o
26e90931 46map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o
e3edfdec 47test_overhead-objs := bpf_load.o libbpf.o test_overhead_user.o
a3f74617 48test_cgrp2_array_pin-objs := libbpf.o test_cgrp2_array_pin.o
86af8b41 49xdp1-objs := bpf_load.o libbpf.o xdp1_user.o
764cbcce
BB
50# reuse xdp1 source intentionally
51xdp2-objs := bpf_load.o libbpf.o xdp1_user.o
9e6e60ec
SD
52test_current_task_under_cgroup-objs := bpf_load.o libbpf.o \
53 test_current_task_under_cgroup_user.o
1c47910e 54trace_event-objs := bpf_load.o libbpf.o trace_event_user.o
72874418 55sampleip-objs := bpf_load.o libbpf.o sampleip_user.o
3c731eba
AS
56
57# Tell kbuild to always build the programs
58always := $(hostprogs-y)
a8085782 59always += sockex1_kern.o
fbe33108 60always += sockex2_kern.o
530b2c86 61always += sockex3_kern.o
b896c4f9 62always += tracex1_kern.o
d822a192 63always += tracex2_kern.o
5c7fc2d2 64always += tracex3_kern.o
9811e353 65always += tracex4_kern.o
5bacd780 66always += tracex5_kern.o
47efb302 67always += tracex6_kern.o
cf9b1199 68always += test_probe_write_user_kern.o
39111695 69always += trace_output_kern.o
91bc4822 70always += tcbpf1_kern.o
6afb1e28 71always += tcbpf2_kern.o
0fb1170e 72always += lathist_kern.o
a6ffe7b9 73always += offwaketime_kern.o
9d8b612d 74always += spintest_kern.o
26e90931 75always += map_perf_test_kern.o
e3edfdec
AS
76always += test_overhead_tp_kern.o
77always += test_overhead_kprobe_kern.o
65d472fb 78always += parse_varlen.o parse_simple.o parse_ldabs.o
a3f74617 79always += test_cgrp2_tc_kern.o
86af8b41 80always += xdp1_kern.o
764cbcce 81always += xdp2_kern.o
9e6e60ec 82always += test_current_task_under_cgroup_kern.o
1c47910e 83always += trace_event_kern.o
72874418 84always += sampleip_kern.o
3c731eba
AS
85
86HOSTCFLAGS += -I$(objtree)/usr/include
a8085782
AS
87
88HOSTCFLAGS_bpf_load.o += -I$(objtree)/usr/include -Wno-unused-variable
42984d7c 89HOSTLOADLIBES_fds_example += -lelf
a8085782 90HOSTLOADLIBES_sockex1 += -lelf
fbe33108 91HOSTLOADLIBES_sockex2 += -lelf
530b2c86 92HOSTLOADLIBES_sockex3 += -lelf
b896c4f9 93HOSTLOADLIBES_tracex1 += -lelf
d822a192 94HOSTLOADLIBES_tracex2 += -lelf
5c7fc2d2 95HOSTLOADLIBES_tracex3 += -lelf
9811e353 96HOSTLOADLIBES_tracex4 += -lelf -lrt
5bacd780 97HOSTLOADLIBES_tracex5 += -lelf
47efb302 98HOSTLOADLIBES_tracex6 += -lelf
cf9b1199 99HOSTLOADLIBES_test_probe_write_user += -lelf
39111695 100HOSTLOADLIBES_trace_output += -lelf -lrt
0fb1170e 101HOSTLOADLIBES_lathist += -lelf
a6ffe7b9 102HOSTLOADLIBES_offwaketime += -lelf
9d8b612d 103HOSTLOADLIBES_spintest += -lelf
26e90931 104HOSTLOADLIBES_map_perf_test += -lelf -lrt
e3edfdec 105HOSTLOADLIBES_test_overhead += -lelf -lrt
86af8b41 106HOSTLOADLIBES_xdp1 += -lelf
764cbcce 107HOSTLOADLIBES_xdp2 += -lelf
9e6e60ec 108HOSTLOADLIBES_test_current_task_under_cgroup += -lelf
1c47910e 109HOSTLOADLIBES_trace_event += -lelf
72874418 110HOSTLOADLIBES_sampleip += -lelf
a8085782 111
bdefbbf2
JDB
112# Allows pointing LLC/CLANG to a LLVM backend with bpf support, redefine on cmdline:
113# make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
6ccfba75 114LLC ?= llc
bdefbbf2 115CLANG ?= clang
6ccfba75 116
b62a796c
JDB
117# Trick to allow make to be run from this directory
118all:
119 $(MAKE) -C ../../ $$PWD/
120
121clean:
122 $(MAKE) -C ../../ M=$$PWD clean
123 @rm -f *~
124
bdefbbf2
JDB
125# Verify LLVM compiler tools are available and bpf target is supported by llc
126.PHONY: verify_cmds verify_target_bpf $(CLANG) $(LLC)
7b01dd57 127
bdefbbf2
JDB
128verify_cmds: $(CLANG) $(LLC)
129 @for TOOL in $^ ; do \
130 if ! (which -- "$${TOOL}" > /dev/null 2>&1); then \
131 echo "*** ERROR: Cannot find LLVM tool $${TOOL}" ;\
132 exit 1; \
133 else true; fi; \
134 done
7b01dd57 135
bdefbbf2 136verify_target_bpf: verify_cmds
7b01dd57
JDB
137 @if ! (${LLC} -march=bpf -mattr=help > /dev/null 2>&1); then \
138 echo "*** ERROR: LLVM (${LLC}) does not support 'bpf' target" ;\
139 echo " NOTICE: LLVM version >= 3.7.1 required" ;\
140 exit 2; \
141 else true; fi
142
143$(src)/*.c: verify_target_bpf
144
128d1514
NR
145# asm/sysreg.h - inline assembly used by it is incompatible with llvm.
146# But, there is no easy way to fix it, so just exclude it since it is
30b50aa6 147# useless for BPF samples.
b88c06e3 148$(obj)/%.o: $(src)/%.c
bdefbbf2 149 $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) \
30b50aa6 150 -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \
65d472fb 151 -Wno-compare-distinct-pointer-types \
6ccfba75 152 -O2 -emit-llvm -c $< -o -| $(LLC) -march=bpf -filetype=obj -o $@