Skip to content

Commit

Permalink
Introduce TEST_EXTRA_PRELOAD variable
Browse files Browse the repository at this point in the history
For preload asan runtime when needed.
  • Loading branch information
GBuella committed Jun 29, 2017
1 parent 76d75eb commit f59298d
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ option(TREAT_WARNINGS_AS_ERRORS
"make the build fail on any warnings during compilation, or linking" ON)
option(EXPECT_SPURIOUS_SYSCALLS
"account for some unexpected syscalls in tests - enable while using sanitizers, gcov" OFF)
set(TEST_EXTRA_PRELOAD "" CACHE STRING "path to preloadable lib used while running tests e.g.: /usr/lib/gcc/x86_64-linux-gnu/6/libasan.so")

set(SYSCALL_INTERCEPT_VERSION_MAJOR 0)
set(SYSCALL_INTERCEPT_VERSION_MINOR 1)
Expand Down
11 changes: 11 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ set(CHECK_LOG_COMMON_ARGS
add_executable(logging_test logging_test.c)
add_test(NAME "logging"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DTEST_NAME=logging
-DLIB_FILE=$<TARGET_FILE:syscall_intercept_shared>
-DTEST_PROG=$<TARGET_FILE:logging_test>
Expand All @@ -128,6 +129,7 @@ add_library(hook_test_preload SHARED hook_test_preload.c)
target_link_libraries(hook_test_preload PRIVATE syscall_intercept_shared)
add_test(NAME "hook"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DTEST_NAME=hook
-DLIB_FILE=$<TARGET_FILE:hook_test_preload>
-DTEST_PROG=$<TARGET_FILE:hook_test>
Expand All @@ -139,6 +141,7 @@ add_library(hook_test_clone_preload SHARED hook_test_clone_preload.c)
target_link_libraries(hook_test_clone_preload PRIVATE syscall_intercept_shared)
add_test(NAME "hook_clone"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DTEST_NAME=hook_clone
-DLIB_FILE=$<TARGET_FILE:hook_test_clone_preload>
-DTEST_PROG=$<TARGET_FILE:logging_test>
Expand All @@ -153,6 +156,7 @@ target_link_libraries(filter_test PRIVATE syscall_intercept_shared)

add_test(NAME "filter_none"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DTEST_PROG=$<TARGET_FILE:filter_test>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake)
set_tests_properties("filter_none"
Expand All @@ -162,6 +166,7 @@ get_filename_component(filter_test_filename $<TARGET_FILE:filter_test> NAME)

add_test(NAME "filter_positive"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DFILTER=${filter_test_filename}
-DTEST_PROG=$<TARGET_FILE:filter_test>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake)
Expand All @@ -170,6 +175,7 @@ set_tests_properties("filter_positive"

add_test(NAME "filter_negative"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DFILTER=non_matching_filter
-DTEST_PROG=$<TARGET_FILE:filter_test>
-P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake)
Expand All @@ -182,6 +188,7 @@ add_library(test_clone_thread_preload SHARED test_clone_thread_preload.c)
target_link_libraries(test_clone_thread_preload PRIVATE syscall_intercept_shared)
add_test(NAME "clone_thread"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DFILTER=${test_clone_thread_filename}
-DTEST_PROG=$<TARGET_FILE:test_clone_thread>
-DLIB_FILE=$<TARGET_FILE:test_clone_thread_preload>
Expand Down Expand Up @@ -221,6 +228,7 @@ endif()

add_test(NAME "prog_pie_intercept_libc_only"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DTEST_PROG=$<TARGET_FILE:executable_with_syscall_pie>
-DLIB_FILE=$<TARGET_FILE:intercept_sys_write>
-DTEST_PROG_ARGS=original_syscall
Expand All @@ -230,6 +238,7 @@ set_tests_properties("prog_pie_intercept_libc_only"

add_test(NAME "prog_no_pie_intercept_libc_only"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DTEST_PROG=$<TARGET_FILE:executable_with_syscall_no_pie>
-DLIB_FILE=$<TARGET_FILE:intercept_sys_write>
-DTEST_PROG_ARGS=original_syscall
Expand All @@ -239,6 +248,7 @@ set_tests_properties("prog_no_pie_intercept_libc_only"

add_test(NAME "prog_pie_intercept_all"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DINTERCEPT_ALL=1
-DTEST_PROG=$<TARGET_FILE:executable_with_syscall_pie>
-DLIB_FILE=$<TARGET_FILE:intercept_sys_write>
Expand All @@ -249,6 +259,7 @@ set_tests_properties("prog_pie_intercept_all"

add_test(NAME "prog_no_pie_intercept_all"
COMMAND ${CMAKE_COMMAND}
-DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD}
-DINTERCEPT_ALL=1
-DTEST_PROG=$<TARGET_FILE:executable_with_syscall_no_pie>
-DLIB_FILE=$<TARGET_FILE:intercept_sys_write>
Expand Down
12 changes: 9 additions & 3 deletions test/check.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,19 @@ set(ENV{INTERCEPT_HOOK_CMDLINE_FILTER} ${FILTER})
endif()

if(LIB_FILE)
set(ENV{LD_PRELOAD} ${LIB_FILE})
if(TEST_EXTRA_PRELOAD)
set(ENV{LD_PRELOAD} ${TEST_EXTRA_PRELOAD}:${LIB_FILE})
else()
set(ENV{LD_PRELOAD} ${LIB_FILE})
endif()
endif()

endif()

if(INTERCEPT_ALL)
set(ENV{INTERCEPT_ALL_OBJS} 1)
set(ENV{INTERCEPT_ALL_OBJS} 1)
else()
unset(ENV{INTERCEPT_ALL_OBJS})
unset(ENV{INTERCEPT_ALL_OBJS})
endif()

execute_process(COMMAND ${TEST_PROG} ${TEST_PROG_ARGS} RESULT_VARIABLE HAD_ERROR)
Expand Down
12 changes: 10 additions & 2 deletions test/check_log.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ endif()
if(HAS_SECOND_LOG)
message("Executing: LD_PRELOAD=${LIB_FILE}
${TEST_PROG} ${TEST_PROG_ARG} ${LOG_OUTPUT} ${SECOND_LOG_OUTPUT}")
set(ENV{LD_PRELOAD} ${LIB_FILE})
if(TEST_EXTRA_PRELOAD)
set(ENV{LD_PRELOAD} ${TEST_EXTRA_PRELOAD}:${LIB_FILE})
else()
set(ENV{LD_PRELOAD} ${LIB_FILE})
endif()
execute_process(COMMAND ${TEST_PROG}
${TEST_PROG_ARG} ${LOG_OUTPUT} ${SECOND_LOG_OUTPUT}
RESULT_VARIABLE HAD_ERROR)
unset(ENV{LD_PRELOAD})
else()
message("Executing: LD_PRELOAD=${LIB_FILE}
${TEST_PROG} ${TEST_PROG_ARG} ${LOG_OUTPUT}")
set(ENV{LD_PRELOAD} ${LIB_FILE})
if(TEST_EXTRA_PRELOAD)
set(ENV{LD_PRELOAD} ${TEST_EXTRA_PRELOAD}:${LIB_FILE})
else()
set(ENV{LD_PRELOAD} ${LIB_FILE})
endif()
execute_process(COMMAND ${TEST_PROG} ${TEST_PROG_ARG} ${LOG_OUTPUT}
RESULT_VARIABLE HAD_ERROR)
unset(ENV{LD_PRELOAD})
Expand Down

0 comments on commit f59298d

Please sign in to comment.