5 ${CMAKE_CURRENT_SOURCE_DIR}
6 ${CMAKE_SOURCE_DIR}/src
10 set(TORTURE_LIBRARY torture)
12 # A simple DNS server for testing
13 add_executable(dns_srv dns_srv.c)
14 target_compile_options(dns_srv PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
15 target_link_libraries(dns_srv ${RWRAP_REQUIRED_LIBRARIES})
17 add_executable(test_real_res_query test_real_res_query.c)
18 target_compile_options(test_real_res_query PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
19 target_link_libraries(test_real_res_query ${RWRAP_REQUIRED_LIBRARIES} ${CMOCKA_LIBRARY})
21 configure_file(fake_hosts.in ${CMAKE_CURRENT_BINARY_DIR}/fake_hosts @ONLY)
23 add_library(${TORTURE_LIBRARY} STATIC torture.c)
24 target_compile_options(${TORTURE_LIBRARY} PRIVATE ${DEFAULT_C_COMPILE_FLAGS})
25 target_link_libraries(${TORTURE_LIBRARY}
27 ${SWRAP_REQUIRED_LIBRARIES})
30 set(TESTSUITE_LIBRARIES ${RWRAP_REQUIRED_LIBRARIES} ${CMOCKA_LIBRARY})
32 # Some tests require socket_wrapper as well.
33 find_package(socket_wrapper REQUIRED)
35 set(RWRAP_TESTS test_res_init)
38 set(RWRAP_TESTS ${RWRAP_TESTS} test_res_query_search)
41 function(ADD_CMOCKA_TEST_ENVIRONMENT _TEST_NAME)
43 string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
44 if (CMAKE_BUILD_TYPE_LOWER STREQUAL "addresssanitizer")
45 find_library(ASAN_LIBRARY
48 foreach(version RANGE 10 1)
50 find_library(ASAN_LIBRARY libasan.so.${version})
58 list(APPEND PRELOAD_LIBRARIES ${ASAN_LIBRARY})
60 list(APPEND PRELOAD_LIBRARIES ${RESOLV_WRAPPER_LOCATION})
61 list(APPEND PRELOAD_LIBRARIES ${SOCKET_WRAPPER_LIBRARY})
64 set(TORTURE_ENVIRONMENT "DYLD_FORCE_FLAT_NAMESPACE=1;DYLD_INSERT_LIBRARIES=${RESOLV_WRAPPER_LOCATION}:${SOCKET_WRAPPER_LIBRARY}")
66 string(REPLACE ";" ":" _TMP_ENV "${PRELOAD_LIBRARIES}")
67 set(TORTURE_ENVIRONMENT "LD_PRELOAD=${_TMP_ENV}")
70 list(APPEND TORTURE_ENVIRONMENT RESOLV_WRAPPER=1)
73 list(APPEND TORTURE_ENVIRONMENT ${_arg})
79 ENVIRONMENT "${TORTURE_ENVIRONMENT}")
82 foreach(_RWRAP_TEST ${RWRAP_TESTS})
83 add_cmocka_test(${_RWRAP_TEST} ${_RWRAP_TEST}.c ${TORTURE_LIBRARY} ${TESTSUITE_LIBRARIES})
85 add_cmocka_test_environment(${_RWRAP_TEST})
88 add_cmocka_test(test_dns_fake test_dns_fake.c ${TORTURE_LIBRARY} ${TESTSUITE_LIBRARIES})
89 add_cmocka_test_environment(test_dns_fake RESOLV_WRAPPER_HOSTS=${CMAKE_CURRENT_BINARY_DIR}/fake_hosts)