Skip to content

Commit 3e78750

Browse files
committed
add dynamic override test on windows
1 parent 84aadcb commit 3e78750

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,18 +705,25 @@ if (MI_BUILD_TESTS)
705705
endforeach()
706706

707707
# dynamic override test
708-
if(MI_BUILD_SHARED AND NOT (WIN32 OR MI_TRACK_ASAN OR MI_DEBUG_TSAN OR MI_DEBUG_UBSAN))
708+
if(MI_BUILD_SHARED AND NOT (MI_TRACK_ASAN OR MI_DEBUG_TSAN OR MI_DEBUG_UBSAN))
709709
add_executable(mimalloc-test-stress-dynamic test/test-stress.c)
710710
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE ${mi_defines} "USE_STD_MALLOC=1")
711+
if(WIN32)
712+
target_compile_definitions(mimalloc-test-stress-dynamic PRIVATE "MI_LINK_VERSION=1")
713+
endif()
711714
target_compile_options(mimalloc-test-stress-dynamic PRIVATE ${mi_cflags})
712715
target_include_directories(mimalloc-test-stress-dynamic PRIVATE include)
713-
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE ${mi_libraries}) # pthread
714-
if(APPLE)
715-
set(LD_PRELOAD "DYLD_INSERT_LIBRARIES")
716+
target_link_libraries(mimalloc-test-stress-dynamic PRIVATE mimalloc ${mi_libraries}) # mi_version
717+
if(WIN32)
718+
add_test(NAME test-stress-dynamic COMMAND ${CMAKE_COMMAND} -E env MIMALLOC_SHOW_STATS=1 $<TARGET_FILE:mimalloc-test-stress-dynamic>)
716719
else()
717-
set(LD_PRELOAD "LD_PRELOAD")
720+
if(APPLE)
721+
set(LD_PRELOAD "DYLD_INSERT_LIBRARIES")
722+
else()
723+
set(LD_PRELOAD "LD_PRELOAD")
724+
endif()
725+
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>)
718726
endif()
719-
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>)
720727
endif()
721728
endif()
722729

test/test-stress.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ static void test_leak(void) {
268268
}
269269
#endif
270270

271+
#if defined(USE_STD_MALLOC) && defined(MI_LINK_VERSION)
272+
#ifdef __cplusplus
273+
extern "C"
274+
#endif
275+
int mi_version(void);
276+
#endif
277+
271278
int main(int argc, char** argv) {
279+
#ifdef MI_LINK_VERSION
280+
mi_version();
281+
#endif
272282
#ifdef HEAP_WALK
273283
mi_option_enable(mi_option_visit_abandoned);
274284
#endif
@@ -318,7 +328,7 @@ int main(int argc, char** argv) {
318328
#ifndef NDEBUG
319329
mi_debug_show_arenas();
320330
mi_collect(true);
321-
#endif
331+
#endif
322332
mi_stats_print(NULL);
323333
#endif
324334
//bench_end_program();

0 commit comments

Comments
 (0)