Skip to content

Commit

Permalink
fix(test/libscap): adjust stats expectations for libbpf
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
  • Loading branch information
jasondellaluce authored and poiana committed Nov 15, 2023
1 parent 1b68561 commit 5b8e3bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions test/libscap/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions test/libscap/test_suites/engines/bpf/bpf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <scap.h>
#include <scap_engines.h>
#include <scap_engine_util.h>
#include <gtest/gtest.h>
#include <unordered_set>
#include <helpers/engines.h>
Expand Down Expand Up @@ -143,8 +144,12 @@ TEST(bpf, scap_stats_v2_check_results)
ASSERT_GT(nstats, 0);

/* These names should always be available */
std::unordered_set<std::string> 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<std::string> 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)
{
Expand Down
7 changes: 6 additions & 1 deletion test/libscap/test_suites/engines/modern_bpf/modern_bpf.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <scap.h>
#include <scap_engines.h>
#include <scap_engine_util.h>
#include <gtest/gtest.h>
#include <unordered_set>
#include <syscall.h>
Expand Down Expand Up @@ -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<std::string> 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<std::string> 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)
Expand Down
9 changes: 9 additions & 0 deletions userspace/libscap/scap_engine_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ limitations under the License.
#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

/**
* \brief Get the timestamp of boot with subsecond accuracy
*
Expand All @@ -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

0 comments on commit 5b8e3bf

Please sign in to comment.