From f59298d8e53c96dc34b3c5e535757a7671042f8e Mon Sep 17 00:00:00 2001 From: Gabor Buella Date: Thu, 29 Jun 2017 16:12:26 +0200 Subject: [PATCH] Introduce TEST_EXTRA_PRELOAD variable For preload asan runtime when needed. --- CMakeLists.txt | 1 + test/CMakeLists.txt | 11 +++++++++++ test/check.cmake | 12 +++++++++--- test/check_log.cmake | 12 ++++++++++-- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d712a50..772fd6ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7ffc6320..648bd392 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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=$ -DTEST_PROG=$ @@ -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=$ -DTEST_PROG=$ @@ -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=$ -DTEST_PROG=$ @@ -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=$ -P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake) set_tests_properties("filter_none" @@ -162,6 +166,7 @@ get_filename_component(filter_test_filename $ NAME) add_test(NAME "filter_positive" COMMAND ${CMAKE_COMMAND} + -DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD} -DFILTER=${filter_test_filename} -DTEST_PROG=$ -P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake) @@ -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=$ -P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake) @@ -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=$ -DLIB_FILE=$ @@ -221,6 +228,7 @@ endif() add_test(NAME "prog_pie_intercept_libc_only" COMMAND ${CMAKE_COMMAND} + -DTEST_EXTRA_PRELOAD=${TEST_EXTRA_PRELOAD} -DTEST_PROG=$ -DLIB_FILE=$ -DTEST_PROG_ARGS=original_syscall @@ -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=$ -DLIB_FILE=$ -DTEST_PROG_ARGS=original_syscall @@ -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=$ -DLIB_FILE=$ @@ -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=$ -DLIB_FILE=$ diff --git a/test/check.cmake b/test/check.cmake index ab1882ad..b60511d6 100644 --- a/test/check.cmake +++ b/test/check.cmake @@ -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) diff --git a/test/check_log.cmake b/test/check_log.cmake index 4f7a3d28..9c1525de 100644 --- a/test/check_log.cmake +++ b/test/check_log.cmake @@ -45,7 +45,11 @@ 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) @@ -53,7 +57,11 @@ if(HAS_SECOND_LOG) 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})