From fd473d7c55e5c0d23beca198ae5ef4a520cff641 Mon Sep 17 00:00:00 2001 From: chantra Date: Fri, 12 Aug 2022 05:09:55 +0000 Subject: [PATCH] [test] fix module search test The test "searching for modules in /proc/[pid]/maps" was trying to load `dummy_proc_map.txt` from the current directory. When running in a container, the current directory is set to `/`. One way around this in CI would be to use the argument `-w /bcc/build/tests/cc` so we change current directory. On the other hand, our CMakeLists.txt file already copy the dummy file to CMAKE_CURRENT_BINARY_DIR. So we may as well use this. This diff sets `CMAKE_CURRENT_BINARY_DIR` as a define flag at compilation and we re-use this within the test itself to load the file properly. Test: ``` $ docker run -ti \ --privileged \ --network=host \ --pid=host \ -v $(pwd):/bcc \ -v /sys/kernel/debug:/sys/kernel/debug:rw \ -v /lib/modules:/lib/modules:ro \ -v /usr/src:/usr/src:ro \ -e CTEST_OUTPUT_ON_FAILURE=1 \ bcc-docker-fedora \ /bin/bash -c \ '/bcc/build/tests/wrapper.sh \ c_test_all sudo /bcc/build/tests/cc/test_libbcc "searching for modules *"' =============================================================================== All tests passed (15 assertions in 1 test case) ``` --- tests/cc/CMakeLists.txt | 1 + tests/cc/test_c_api.cc | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/cc/CMakeLists.txt b/tests/cc/CMakeLists.txt index 677867d7dad3..8ad8fdb89cf4 100644 --- a/tests/cc/CMakeLists.txt +++ b/tests/cc/CMakeLists.txt @@ -14,6 +14,7 @@ else() endif() add_test(NAME c_test_static COMMAND ${TEST_WRAPPER} c_test_static sudo ${CMAKE_CURRENT_BINARY_DIR}/test_static) +add_compile_options(-DCMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result -fPIC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result -fPIC") diff --git a/tests/cc/test_c_api.cc b/tests/cc/test_c_api.cc index d5b3cfeb337a..21a44025cf74 100644 --- a/tests/cc/test_c_api.cc +++ b/tests/cc/test_c_api.cc @@ -34,6 +34,7 @@ #include "catch.hpp" + using namespace std; static pid_t spawn_child(void *, bool, bool, int (*)(void *)); @@ -495,7 +496,8 @@ struct mod_search { }; TEST_CASE("searching for modules in /proc/[pid]/maps", "[c_api][!mayfail]") { - FILE *dummy_maps = fopen("dummy_proc_map.txt", "r"); + std::string dummy_maps_path = CMAKE_CURRENT_BINARY_DIR + std::string("/dummy_proc_map.txt"); + FILE *dummy_maps = fopen(dummy_maps_path.c_str(), "r"); REQUIRE(dummy_maps != NULL); SECTION("name match") {