From 5b8e3bf71effa5bdab7f5f375ecbcce2a12dfefd Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Wed, 15 Nov 2023 18:44:41 +0000 Subject: [PATCH] fix(test/libscap): adjust stats expectations for libbpf Signed-off-by: Jason Dellaluce --- test/libscap/CMakeLists.txt | 1 + test/libscap/test_suites/engines/bpf/bpf.cpp | 9 +++++++-- .../test_suites/engines/modern_bpf/modern_bpf.cpp | 7 ++++++- userspace/libscap/scap_engine_util.h | 9 +++++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/test/libscap/CMakeLists.txt b/test/libscap/CMakeLists.txt index 3af932aa96..cdbca01cd0 100644 --- a/test/libscap/CMakeLists.txt +++ b/test/libscap/CMakeLists.txt @@ -70,6 +70,7 @@ list(APPEND LIBSCAP_TESTS_SOURCES ${LIBSCAP_TESTS_UTILS_SOURCES}) if (CMAKE_SYSTEM_NAME MATCHES "Linux") file(GLOB_RECURSE LINUX_TEST_SUITE "${CMAKE_CURRENT_SOURCE_DIR}/test_suites/userspace/linux/*.cpp") list(APPEND LIBSCAP_TEST_SOURCES ${LINUX_TEST_SUITE}) + list(APPEND LIBSCAP_TESTS_LIBRARIES scap_engine_util) endif() # Engine-specific tests diff --git a/test/libscap/test_suites/engines/bpf/bpf.cpp b/test/libscap/test_suites/engines/bpf/bpf.cpp index ab274c4c0e..dc4dec86bf 100644 --- a/test/libscap/test_suites/engines/bpf/bpf.cpp +++ b/test/libscap/test_suites/engines/bpf/bpf.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -143,8 +144,12 @@ TEST(bpf, scap_stats_v2_check_results) ASSERT_GT(nstats, 0); /* These names should always be available */ - std::unordered_set minimal_stats_name = {"n_evts", "sys_enter.run_cnt", "sys_enter.run_time_ns", "sys_exit.run_cnt", "sys_exit.run_time_ns", "signal_deliver.run_cnt", "signal_deliver.run_time_ns"}; - + std::unordered_set minimal_stats_name = {"n_evts"}; + if (scap_get_bpf_stats_enabled()) + { + minimal_stats_name.insert({"sys_enter.run_cnt", "sys_enter.run_time_ns", "sys_exit.run_cnt", "sys_exit.run_time_ns", "signal_deliver.run_cnt", "signal_deliver.run_time_ns"}); + } + uint32_t i = 0; for(const auto& stat_name : minimal_stats_name) { diff --git a/test/libscap/test_suites/engines/modern_bpf/modern_bpf.cpp b/test/libscap/test_suites/engines/modern_bpf/modern_bpf.cpp index 9c0eafd021..85426fd41b 100644 --- a/test/libscap/test_suites/engines/modern_bpf/modern_bpf.cpp +++ b/test/libscap/test_suites/engines/modern_bpf/modern_bpf.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -244,7 +245,11 @@ TEST(modern_bpf, scap_stats_v2_check_results) ASSERT_GT(nstats, 0); /* These names should always be available */ - std::unordered_set minimal_stats_name = {"n_evts", "sys_enter.run_cnt", "sys_enter.run_time_ns", "sys_exit.run_cnt", "sys_exit.run_time_ns", "signal_deliver.run_cnt", "signal_deliver.run_time_ns"}; + std::unordered_set minimal_stats_name = {"n_evts"}; + if (scap_get_bpf_stats_enabled()) + { + minimal_stats_name.insert({"sys_enter.run_cnt", "sys_enter.run_time_ns", "sys_exit.run_cnt", "sys_exit.run_time_ns", "signal_deliver.run_cnt", "signal_deliver.run_time_ns"}); + } uint32_t i = 0; for(const auto& stat_name : minimal_stats_name) diff --git a/userspace/libscap/scap_engine_util.h b/userspace/libscap/scap_engine_util.h index d2f8be6d54..e7a019ebb1 100644 --- a/userspace/libscap/scap_engine_util.h +++ b/userspace/libscap/scap_engine_util.h @@ -21,6 +21,11 @@ limitations under the License. #include #include +#ifdef __cplusplus +extern "C" +{ +#endif + /** * \brief Get the timestamp of boot with subsecond accuracy * @@ -36,3 +41,7 @@ limitations under the License. int32_t scap_get_precise_boot_time(char* last_err, uint64_t *boot_time); bool scap_get_bpf_stats_enabled(); + +#ifdef __cplusplus +}; +#endif