Skip to content

Commit

Permalink
Add test_libbcc_no_libbpf test
Browse files Browse the repository at this point in the history
It's the same code as for test_libbcc test,
but linked with libbcc-no-libbpf.so library.

Added LIBBCC_NAME macro to be used in dynamic loader
test where we need to provide the library name.

Signed-off-by: Jiri Olsa [email protected]
  • Loading branch information
olsajiri committed Nov 12, 2019
1 parent 19c625e commit 7ec8bde
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
17 changes: 16 additions & 1 deletion tests/cc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-result")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-result")

if(ENABLE_USDT)
add_executable(test_libbcc
set(TEST_LIBBCC_SOURCES
test_libbcc.cc
test_c_api.cc
test_array_table.cc
Expand All @@ -28,13 +28,28 @@ add_executable(test_libbcc
test_usdt_args.cc
test_usdt_probes.cc
utils.cc)

add_executable(test_libbcc ${TEST_LIBBCC_SOURCES})

file(COPY dummy_proc_map.txt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
add_library(usdt_test_lib SHARED usdt_test_lib.c)

add_dependencies(test_libbcc bcc-shared)
target_link_libraries(test_libbcc ${PROJECT_BINARY_DIR}/src/cc/libbcc.so dl usdt_test_lib)
set_target_properties(test_libbcc PROPERTIES INSTALL_RPATH ${PROJECT_BINARY_DIR}/src/cc)
target_compile_definitions(test_libbcc PRIVATE -DLIBBCC_NAME=\"libbcc.so\")

add_test(NAME test_libbcc COMMAND ${TEST_WRAPPER} c_test_all sudo ${CMAKE_CURRENT_BINARY_DIR}/test_libbcc)

if(LIBBPF_FOUND)
add_executable(test_libbcc_no_libbpf ${TEST_LIBBCC_SOURCES})
add_dependencies(test_libbcc_no_libbpf bcc-shared-no-libbpf)

target_link_libraries(test_libbcc_no_libbpf ${PROJECT_BINARY_DIR}/src/cc/libbcc-no-libbpf.so dl usdt_test_lib bpf)
set_target_properties(test_libbcc_no_libbpf PROPERTIES INSTALL_RPATH ${PROJECT_BINARY_DIR}/src/cc)
target_compile_definitions(test_libbcc_no_libbpf PRIVATE -DLIBBCC_NAME=\"libbcc-no-libbpf.so\")

add_test(NAME test_libbcc_no_libbpf COMMAND ${TEST_WRAPPER} c_test_all_no_libbpf sudo ${CMAKE_CURRENT_BINARY_DIR}/test_libbcc_no_libbpf)
endif()

endif(ENABLE_USDT)
8 changes: 4 additions & 4 deletions tests/cc/test_c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ TEST_CASE("resolve symbol name in external library using loaded libraries", "[c_
struct bcc_symbol sym;

REQUIRE(bcc_resolve_symname("bcc", "bcc_procutils_which", 0x0, getpid(), nullptr, &sym) == 0);
REQUIRE(string(sym.module).find("libbcc.so") != string::npos);
REQUIRE(string(sym.module).find(LIBBCC_NAME) != string::npos);
REQUIRE(sym.module[0] == '/');
REQUIRE(sym.offset != 0);
bcc_procutils_free(sym.module);
Expand Down Expand Up @@ -233,15 +233,15 @@ TEST_CASE("resolve symbol addresses for a given PID", "[c_api]") {
REQUIRE(string(lazy_sym.module) == sym.module);
}

SECTION("resolve in libbcc.so") {
void *libbcc = dlopen("libbcc.so", RTLD_LAZY | RTLD_NOLOAD);
SECTION("resolve in " LIBBCC_NAME) {
void *libbcc = dlopen(LIBBCC_NAME, RTLD_LAZY | RTLD_NOLOAD);
REQUIRE(libbcc);

void *libbcc_fptr = dlsym(libbcc, "bcc_resolve_symname");
REQUIRE(libbcc_fptr);

REQUIRE(bcc_symcache_resolve(resolver, (uint64_t)libbcc_fptr, &sym) == 0);
REQUIRE(string(sym.module).find("libbcc.so") != string::npos);
REQUIRE(string(sym.module).find(LIBBCC_NAME) != string::npos);
REQUIRE(string("bcc_resolve_symname") == sym.name);

REQUIRE(bcc_symcache_resolve(lazy_resolver, (uint64_t)libbcc_fptr, &lazy_sym) == 0);
Expand Down

0 comments on commit 7ec8bde

Please sign in to comment.