]> granicus.if.org Git - gc/commitdiff
Fix gctest in leak-finding mode
authorIvan Maidanski <ivmai@mail.ru>
Thu, 7 Jun 2018 09:09:57 +0000 (12:09 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 17 Jul 2018 07:20:43 +0000 (10:20 +0300)
(a cherry-pick of commit c147dcba from 'release-7_6')

Also, print the message about the leak-find mode just once per gctest
execution.

* tests/test.c (INIT_FIND_LEAK): Define macro.
* tests/test.c (GC_COND_INIT): Invoke INIT_FIND_LEAK.
* 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 (run_one_test): Remove print about leak-find mode.
* tests/test.c (check_heap_stats): Do not fail on unexpected heap
growth if GC_get_find_leak().
* tests/test.c [!GC_NO_FINALIZATION] (check_heap_stats): Move
still_live and still_long_live local variables to the block of their
usage.

tests/test.c

index b1b808fe96c06e3c80daf2eabf3d0cf4b4a7a9d2..d730d6ecd9c5f6d3422399d1223886bfd34612bb 100644 (file)
 #  define GC_OPT_INIT /* empty */
 #endif
 
+#define INIT_FIND_LEAK \
+    if (!GC_get_find_leak()) {} else \
+      GC_printf("This test program is not designed for leak detection mode\n")
+
 #define GC_COND_INIT() \
-    INIT_FORK_SUPPORT; GC_OPT_INIT; CHECK_GCLIB_VERSION; INIT_PRINT_STATS
+    INIT_FORK_SUPPORT; GC_OPT_INIT; CHECK_GCLIB_VERSION; \
+    INIT_PRINT_STATS; INIT_FIND_LEAK
 
 #define CHECK_OUT_OF_MEMORY(p) \
             if ((p) == NULL) { \
@@ -845,7 +850,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) {
@@ -913,8 +919,9 @@ tn * mktree(int n)
             FAIL;
           }
 #       endif
-#     endif
-        GC_reachable_here(result);
+      }
+#   endif
+      GC_reachable_here(result);
     }
     return(result);
 }
@@ -1199,11 +1206,6 @@ void run_one_test(void)
       int wstatus;
 #   endif
 
-#   ifdef FIND_LEAK
-        GC_printf(
-              "This test program is not designed for leak detection mode\n");
-        GC_printf("Expect lots of problems\n");
-#   endif
     GC_FREE(0);
 #   ifdef THREADS
       if (!GC_thread_is_registered() && GC_is_init_called()) {
@@ -1449,10 +1451,6 @@ void check_heap_stats(void)
     size_t max_heap_sz;
     int i;
 #   ifndef GC_NO_FINALIZATION
-      int still_live;
-#     ifndef GC_LONG_REFS_NOT_NEEDED
-        int still_long_live = 0;
-#     endif
 #     ifdef FINALIZE_ON_DEMAND
         int late_finalize_count = 0;
 #     endif
@@ -1522,7 +1520,13 @@ void check_heap_stats(void)
     GC_printf("Allocated %d stubborn objects\n", stubborn_count);
     GC_printf("Finalized %d/%d objects - ",
                   finalized_count, finalizable_count);
-#   ifndef GC_NO_FINALIZATION
+# ifndef GC_NO_FINALIZATION
+    if (!GC_get_find_leak()) {
+      int still_live = 0;
+#     ifndef GC_LONG_REFS_NOT_NEEDED
+        int still_long_live = 0;
+#     endif
+
 #     ifdef FINALIZE_ON_DEMAND
         if (finalized_count != late_finalize_count) {
             GC_printf("Demand finalization error\n");
@@ -1536,7 +1540,6 @@ void check_heap_stats(void)
       } else {
         GC_printf("finalization is probably ok\n");
       }
-      still_live = 0;
       for (i = 0; i < MAX_FINALIZED; i++) {
         if (live_indicators[i] != 0) {
             still_live++;
@@ -1562,7 +1565,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("Final heap size is %lu bytes\n",
@@ -1577,7 +1581,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()),