@@ -690,15 +690,32 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc"
690690if (MI_BUILD_TESTS)
691691 enable_testing ()
692692
693- foreach (TEST_NAME api api-fill stress)
694- add_executable (mimalloc-test -${TEST_NAME} test /test -${TEST_NAME} .c)
695- target_compile_definitions (mimalloc-test -${TEST_NAME} PRIVATE ${mi_defines} )
696- target_compile_options (mimalloc-test -${TEST_NAME} PRIVATE ${mi_cflags} )
697- target_include_directories (mimalloc-test -${TEST_NAME} PRIVATE include )
698- target_link_libraries (mimalloc-test -${TEST_NAME} PRIVATE mimalloc ${mi_libraries} )
699-
700- add_test (NAME test -${TEST_NAME} COMMAND mimalloc-test -${TEST_NAME} )
701- endforeach ()
693+ # static link tests
694+ if (MI_BUILD_STATIC)
695+ foreach (TEST_NAME api api-fill stress)
696+ add_executable (mimalloc-test -${TEST_NAME} test /test -${TEST_NAME} .c)
697+ target_compile_definitions (mimalloc-test -${TEST_NAME} PRIVATE ${mi_defines} )
698+ target_compile_options (mimalloc-test -${TEST_NAME} PRIVATE ${mi_cflags} )
699+ target_include_directories (mimalloc-test -${TEST_NAME} PRIVATE include )
700+ target_link_libraries (mimalloc-test -${TEST_NAME} PRIVATE mimalloc-static ${mi_libraries} )
701+
702+ add_test (NAME test -${TEST_NAME} COMMAND mimalloc-test -${TEST_NAME} )
703+ endforeach ()
704+ endif ()
705+
706+ # dynamic override test
707+ if (MI_BUILD_SHARED AND NOT WIN32 )
708+ add_executable (mimalloc-test -stress-dynamic test /test -stress.c)
709+ target_compile_definitions (mimalloc-test -stress-dynamic PRIVATE ${mi_defines} "USE_STD_MALLOC=1" )
710+ target_compile_options (mimalloc-test -stress-dynamic PRIVATE ${mi_cflags} )
711+ target_include_directories (mimalloc-test -stress-dynamic PRIVATE include )
712+ if (APPLE )
713+ set (LD_PRELOAD "DYLD_INSERT_LIBRARIES" )
714+ else ()
715+ set (LD_PRELOAD "LD_PRELOAD" )
716+ endif ()
717+ add_test (NAME test -stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_SHOW_STATS=1 ${LD_PRELOAD} =$<TARGET_FILE:mimalloc> $<TARGET_FILE:mimalloc-test -stress-dynamic>)
718+ endif ()
702719endif ()
703720
704721# -----------------------------------------------------------------------------
0 commit comments