History

selftests/bpf: Make sure enum-less bpf_enable_stats() API works in C++ mode

Just a simple test to make sure we don't introduce unwanted compiler warnings and API still supports passing enums as input argument.

Andrii Nakryiko committed 3 years ago

Commit f8186bf1 parent b4269341 file · +10 −3Browse files

Showing the changes to tools/testing/selftests/bpf/test_cpp.cpp (1 of 1 file). Show all

Unified · Split

tools/testing/selftests/bpf/test_cpp.cpp+10−3
@@ -1,9 +1,9 @@
11 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
22 #include <iostream>
3−#pragma GCC diagnostic push
4−#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
3+#include <unistd.h>
4+#include <linux/bpf.h>
5+#include <linux/btf.h>
56 #include <bpf/libbpf.h>
6−#pragma GCC diagnostic pop
77 #include <bpf/bpf.h>
88 #include <bpf/btf.h>
99 #include "test_core_extern.skel.h"
@@ -99,6 +99,7 @@ int main(int argc, char *argv[]) · 89 unmodified lines
9999 struct btf_dump_opts opts = { };
100100 struct test_core_extern *skel;
101101 struct btf *btf;
102+ int fd;
102103
103104 try_skeleton_template();
104105
@@ -117,6 +118,12 @@ int main(int argc, char *argv[]) · 12 unmodified lines
117118 skel = test_core_extern__open_and_load();
118119 test_core_extern__destroy(skel);
119120
121+ fd = bpf_enable_stats(BPF_STATS_RUN_TIME);
122+ if (fd < 0)
123+ std::cout << "FAILED to enable stats: " << fd << std::endl;
124+ else
125+ ::close(fd);
126+
120127 std::cout << "DONE!" << std::endl;
121128
122129 return 0;