From 4e909d2389d48f6393a35742b71a3e30c98157aa Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 7 Jun 2018 12:09:57 +0300 Subject: [PATCH] Fix gctest in leak-finding mode * tests/test.c [!FIND_LEAK] (mktree): Do not call GC_REGISTER_FINALIZER and GC_GENERAL_REGISTER_DISAPPEARING_LINK if GC_get_find_leak(). * tests/test.c (run_one_test): Replace "ifdef FIND_LEAK" with if(GC_get_find_leak()). * tests/test.c (check_heap_stats): Do not fail on unexpected heap growth if GC_get_find_leak(). --- tests/test.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/test.c b/tests/test.c index 69fd7bd..2a1aa3d 100644 --- a/tests/test.c +++ b/tests/test.c @@ -894,7 +894,8 @@ tn * mktree(int n) FINALIZER_UNLOCK(); } -# ifndef GC_NO_FINALIZATION +# ifndef GC_NO_FINALIZATION + if (!GC_get_find_leak()) { GC_REGISTER_FINALIZER((void *)result, finalizer, (void *)(GC_word)n, (GC_finalization_proc *)0, (void * *)0); if (my_index >= MAX_FINALIZED) { @@ -962,8 +963,9 @@ tn * mktree(int n) FAIL; } # endif -# endif - GC_reachable_here(result); + } +# endif + GC_reachable_here(result); } GC_END_STUBBORN_CHANGE(result); return(result); @@ -1283,11 +1285,10 @@ void run_one_test(void) int wstatus; # endif -# ifdef FIND_LEAK + if (GC_get_find_leak()) GC_printf( - "This test program is not designed for leak detection mode\n"); - GC_printf("Expect lots of problems\n"); -# endif + "This test program is not designed for leak detection mode\n" + "Expect lots of problems\n"); GC_FREE(0); # ifdef THREADS if (!GC_thread_is_registered()) { @@ -1666,7 +1667,8 @@ void check_heap_stats(void) GC_printf("Reallocated %d objects\n", (int)realloc_count); GC_printf("Finalized %d/%d objects - ", finalized_count, finalizable_count); -# ifndef GC_NO_FINALIZATION +# ifndef GC_NO_FINALIZATION + if (!GC_get_find_leak()) { # ifdef FINALIZE_ON_DEMAND if (finalized_count != late_finalize_count) { GC_printf("Demand finalization error\n"); @@ -1706,7 +1708,8 @@ void check_heap_stats(void) GC_printf("%d 'long' links remain\n", still_long_live); } # endif -# endif + } +# endif GC_printf("Total number of bytes allocated is %lu\n", (unsigned long)GC_get_total_bytes()); GC_printf("Total memory use by allocated blocks is %lu bytes\n", @@ -1723,7 +1726,8 @@ void check_heap_stats(void) GC_printf("Incorrect execution - missed some allocations\n"); FAIL; } - if (GC_get_heap_size() + GC_get_unmapped_bytes() > max_heap_sz) { + if (GC_get_heap_size() + GC_get_unmapped_bytes() > max_heap_sz + && !GC_get_find_leak()) { GC_printf("Unexpected heap growth - collector may be broken" " (heapsize: %lu, expected: %lu)\n", (unsigned long)(GC_get_heap_size() + GC_get_unmapped_bytes()), @@ -1888,7 +1892,6 @@ void GC_CALLBACK warn_proc(char *msg, GC_word p) UNTESTED(GC_get_dont_precollect); UNTESTED(GC_get_finalize_on_demand); UNTESTED(GC_get_finalizer_notifier); - UNTESTED(GC_get_find_leak); UNTESTED(GC_get_force_unmap_on_gcollect); UNTESTED(GC_get_free_bytes); UNTESTED(GC_get_free_space_divisor); -- 2.7.4