summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/test_cpp.cpp
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2019-12-26 22:02:53 +0100
committerDaniel Borkmann <daniel@iogearbox.net>2019-12-27 10:11:05 +0100
commit7c8dce4b166113743adad131b5a24c4acc12f92c (patch)
tree90b8cb27d1ec83d9086fac9b4d8fee846bfbc3d5 /tools/testing/selftests/bpf/test_cpp.cpp
parentbpf: Print error message for bpftool cgroup show (diff)
downloadlinux-7c8dce4b166113743adad131b5a24c4acc12f92c.tar.xz
linux-7c8dce4b166113743adad131b5a24c4acc12f92c.zip
bpftool: Make skeleton C code compilable with C++ compiler
When auto-generated BPF skeleton C code is included from C++ application, it triggers compilation error due to void * being implicitly casted to whatever target pointer type. This is supported by C, but not C++. To solve this problem, add explicit casts, where necessary. To ensure issues like this are captured going forward, add skeleton usage in test_cpp test. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20191226210253.3132060-1-andriin@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/test_cpp.cpp')
-rw-r--r--tools/testing/selftests/bpf/test_cpp.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/test_cpp.cpp b/tools/testing/selftests/bpf/test_cpp.cpp
index f0eb2727b766..6fe23a10d48a 100644
--- a/tools/testing/selftests/bpf/test_cpp.cpp
+++ b/tools/testing/selftests/bpf/test_cpp.cpp
@@ -1,12 +1,16 @@
/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
+#include <iostream>
#include "libbpf.h"
#include "bpf.h"
#include "btf.h"
+#include "test_core_extern.skel.h"
/* do nothing, just make sure we can link successfully */
int main(int argc, char *argv[])
{
+ struct test_core_extern *skel;
+
/* libbpf.h */
libbpf_set_print(NULL);
@@ -16,5 +20,11 @@ int main(int argc, char *argv[])
/* btf.h */
btf__new(NULL, 0);
+ /* BPF skeleton */
+ skel = test_core_extern__open_and_load();
+ test_core_extern__destroy(skel);
+
+ std::cout << "DONE!" << std::endl;
+
return 0;
}