Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: Bring back c++ include/link test

Commit 5c26f9a78358 ("libbpf: Don't use cxx to test_libpf target")
converted existing c++ test to c. We still want to include and
link against libbpf from c++ code, so reinstate this test back,
this time in a form of a selftest with a clear comment about
its purpose.

v2:
* -lelf -> $(LDLIBS) (Andrii Nakryiko)

Fixes: 5c26f9a78358 ("libbpf: Don't use cxx to test_libpf target")
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20191202215931.248178-1-sdf@google.com

authored by

Stanislav Fomichev and committed by
Alexei Starovoitov
6bf6affe 01d434ce

+7 -6
-1
tools/lib/bpf/.gitignore
··· 1 1 libbpf_version.h 2 2 libbpf.pc 3 3 FEATURE-DUMP.libbpf 4 - test_libbpf 5 4 libbpf.so.* 6 5 TAGS 7 6 tags
+1 -4
tools/lib/bpf/Makefile
··· 152 152 VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \ 153 153 grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l) 154 154 155 - CMD_TARGETS = $(LIB_TARGET) $(PC_FILE) $(OUTPUT)test_libbpf 155 + CMD_TARGETS = $(LIB_TARGET) $(PC_FILE) 156 156 157 157 all: fixdep 158 158 $(Q)$(MAKE) all_cmd ··· 195 195 196 196 $(OUTPUT)libbpf.a: $(BPF_IN_STATIC) 197 197 $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ 198 - 199 - $(OUTPUT)test_libbpf: test_libbpf.c $(OUTPUT)libbpf.a 200 - $(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDES) $^ -lelf -o $@ 201 198 202 199 $(OUTPUT)libbpf.pc: 203 200 $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
tools/lib/bpf/test_libbpf.c tools/testing/selftests/bpf/test_cpp.cpp
+1
tools/testing/selftests/bpf/.gitignore
··· 37 37 test_hashmap 38 38 test_btf_dump 39 39 xdping 40 + test_cpp 40 41 /no_alu32 41 42 /bpf_gcc
+5 -1
tools/testing/selftests/bpf/Makefile
··· 71 71 # Compile but not part of 'make run_tests' 72 72 TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \ 73 73 flow_dissector_load test_flow_dissector test_tcp_check_syncookie_user \ 74 - test_lirc_mode2_user xdping 74 + test_lirc_mode2_user xdping test_cpp 75 75 76 76 TEST_CUSTOM_PROGS = urandom_read 77 77 ··· 316 316 ) > verifier/tests.h) 317 317 $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT) 318 318 $(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@ 319 + 320 + # Make sure we are able to include and link libbpf against c++. 321 + $(OUTPUT)/test_cpp: test_cpp.cpp $(BPFOBJ) 322 + $(CXX) $(CFLAGS) $^ $(LDLIBS) -o $@ 319 323 320 324 EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) \ 321 325 prog_tests/tests.h map_tests/tests.h verifier/tests.h \