Skip to content

Commit 7dd598e

Browse files
committed
add dynamic override test
1 parent 5f9b426 commit 7dd598e

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

CMakeLists.txt

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -690,15 +690,32 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/mimalloc.pc"
690690
if (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()
702719
endif()
703720

704721
# -----------------------------------------------------------------------------

test/test-stress.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ int main(int argc, char** argv) {
319319
mi_debug_show_arenas();
320320
mi_collect(true);
321321
#endif
322-
#endif
323322
mi_stats_print(NULL);
323+
#endif
324324
//bench_end_program();
325325
return 0;
326326
}

0 commit comments

Comments
 (0)