Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

catch_discover_tests with ASan results in errors running test executable

Open Oipo opened this issue 3 years ago • 0 comments

Describe the bug Compiling my project with address sanitizer enabled results in Catch2 not being able to run the text executables:

cd /home/oipo-unencrypted/Programming/ichor/build2/test && /usr/bin/cmake -D TEST_TARGET=DependencyManagerTests -D TEST_EXECUTABLE=/home/oipo-unencrypted/Programming/ichor/bin/DependencyManagerTests -D TEST_EXECUTOR= -D TEST_WORKING_DIR=/home/oipo-unencrypted/Programming/ichor/build2/test -D TEST_SPEC= -D TEST_EXTRA_ARGS= -D TEST_PROPERTIES= -D TEST_PREFIX= -D TEST_SUFFIX= -D TEST_LIST=DependencyManagerTests_TESTS -D TEST_REPORTER= -D TEST_OUTPUT_DIR= -D TEST_OUTPUT_PREFIX= -D TEST_OUTPUT_SUFFIX= -D TEST_DL_PATHS= -D CTEST_FILE=/home/oipo-unencrypted/Programming/ichor/build2/test/DependencyManagerTests_tests-b12d07c.cmake -P /home/oipo-unencrypted/Programming/ichor/external/Catch2/extras/CatchAddTests.cmake
==46102==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
CMake Error at /home/oipo-unencrypted/Programming/ichor/external/Catch2/extras/CatchAddTests.cmake:58 (message):
  Error running test executable
  '/home/oipo-unencrypted/Programming/ichor/bin/DependencyManagerTests':

    Result: 1
    Output: 



make[2]: *** [test/CMakeFiles/DependencyManagerTests.dir/build.make:91: ../bin/DependencyManagerTests] Error 1
make[2]: *** Deleting file '../bin/DependencyManagerTests'

Expected behavior Being able to detect the tests properly.

Reproduction steps See the test CMakeLists.txt Using -fsanitize=address with this setup results in the bug.

Platform information:

  • OS: Ubuntu 20.04
  • Compiler+version: GCC v11.2
  • Catch version: v3.1.0

Additional information A workaround is to link to static-libasan:

foreach(filename ${PROJECT_TEST_SOURCES})
    get_filename_component(testname ${filename} NAME_WE)
    add_executable(${testname} ${filename})
    target_link_libraries(${testname} ${CMAKE_THREAD_LIBS_INIT})
    target_link_libraries(${testname} ichor)
    target_link_libraries(${testname} Catch2::Catch2WithMain)

    if(ICHOR_USE_SANITIZERS)
        target_link_libraries(${testname} -static-libasan)
    endif()

    catch_discover_tests(${testname})
endforeach()

Oipo avatar Aug 26 '22 21:08 Oipo