Skip to content

Commit

Permalink
Merge pull request #28 from GBuella/test_env_set
Browse files Browse the repository at this point in the history
set INTERCEPT_ALL_OBJS in tests when needed
  • Loading branch information
Sarah Jelinek authored Jul 3, 2017
2 parents 6c19526 + f59298d commit a16a048
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 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 @@ -116,6 +116,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 @@ -130,6 +131,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 @@ -141,6 +143,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 @@ -155,6 +158,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 @@ -164,6 +168,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 @@ -172,6 +177,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 @@ -184,6 +190,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 @@ -223,6 +230,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 @@ -232,6 +240,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 @@ -241,6 +250,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 @@ -251,6 +261,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: 10 additions & 2 deletions test/check.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +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})
endif()

execute_process(COMMAND ${TEST_PROG} ${TEST_PROG_ARGS} RESULT_VARIABLE HAD_ERROR)
Expand Down
18 changes: 14 additions & 4 deletions test/check_log.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ set(LOG_OUTPUT .log.${TEST_NAME})

execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${LOG_OUTPUT})

set(ENV{INTERCEPT_ALL_OBJS} 1)

if(HAS_SECOND_LOG)
set(SECOND_LOG_OUTPUT .log.2.${TEST_NAME})
execute_process(COMMAND ${CMAKE_COMMAND} -E remove -f ${SECOND_LOG_OUTPUT})
Expand All @@ -43,18 +45,26 @@ 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)
set(ENV{LD_PRELOAD} "")
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)
set(ENV{LD_PRELOAD} "")
unset(ENV{LD_PRELOAD})
endif()

if(HAD_ERROR)
Expand Down

0 comments on commit a16a048

Please sign in to comment.