Skip to content

Commit 6bf6aff

Browse files
fomichevAlexei Starovoitov
authored andcommitted
selftests/bpf: Bring back c++ include/link test
Commit 5c26f9a ("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: 5c26f9a ("libbpf: Don't use cxx to test_libpf target") Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 01d434c commit 6bf6aff

File tree

5 files changed

+7
-6
lines changed

5 files changed

+7
-6
lines changed

tools/lib/bpf/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
libbpf_version.h
22
libbpf.pc
33
FEATURE-DUMP.libbpf
4-
test_libbpf
54
libbpf.so.*
65
TAGS
76
tags

tools/lib/bpf/Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN_SHARED) | \
152152
VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \
153153
grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
154154

155-
CMD_TARGETS = $(LIB_TARGET) $(PC_FILE) $(OUTPUT)test_libbpf
155+
CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
156156

157157
all: fixdep
158158
$(Q)$(MAKE) all_cmd
@@ -196,9 +196,6 @@ $(OUTPUT)libbpf.so.$(LIBBPF_VERSION): $(BPF_IN_SHARED)
196196
$(OUTPUT)libbpf.a: $(BPF_IN_STATIC)
197197
$(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
198198

199-
$(OUTPUT)test_libbpf: test_libbpf.c $(OUTPUT)libbpf.a
200-
$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) $(INCLUDES) $^ -lelf -o $@
201-
202199
$(OUTPUT)libbpf.pc:
203200
$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
204201
-e "s|@LIBDIR@|$(libdir_SQ)|" \

tools/testing/selftests/bpf/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ libbpf.so.*
3737
test_hashmap
3838
test_btf_dump
3939
xdping
40+
test_cpp
4041
/no_alu32
4142
/bpf_gcc

tools/testing/selftests/bpf/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ TEST_PROGS_EXTENDED := with_addr.sh \
7171
# Compile but not part of 'make run_tests'
7272
TEST_GEN_PROGS_EXTENDED = test_sock_addr test_skb_cgroup_id_user \
7373
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
7575

7676
TEST_CUSTOM_PROGS = urandom_read
7777

@@ -317,6 +317,10 @@ verifier/tests.h: verifier/*.c
317317
$(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
318318
$(CC) $(CFLAGS) $(filter %.a %.o %.c,$^) $(LDLIBS) -o $@
319319

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 $@
323+
320324
EXTRA_CLEAN := $(TEST_CUSTOM_PROGS) \
321325
prog_tests/tests.h map_tests/tests.h verifier/tests.h \
322326
feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc

0 commit comments

Comments
 (0)