Fix and re-enable some GC finalizer tests (#11216)
authorSean Gillespie <sean@swgillespie.me>
Wed, 26 Apr 2017 21:50:19 +0000 (14:50 -0700)
committerGitHub <noreply@github.com>
Wed, 26 Apr 2017 21:50:19 +0000 (14:50 -0700)
* Fix and re-enable some GC finalizer tests

* Make the Usage test a little more robust

tests/issues.targets
tests/src/GC/API/GCHandleCollector/Usage.cs
tests/src/GC/Scenarios/DoublinkList/dlcollect.cs
tests/src/GC/Scenarios/DoublinkList/dlstack.cs
tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs
tests/testsFailingOutsideWindows.txt

index 0592888..0d2fb68 100644 (file)
@@ -1,9 +1,6 @@
 <?xml version="1.0" ?>
 <Project DefaultTargets = "GetListOfTestCmds" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     <ItemGroup Condition="'$(XunitTestBinBase)' != ''">
-        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\DoublinkList\doublinkgen\*">
-            <Issue>6574</Issue>
-        </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)\GC\Coverage\271010\*">
             <Issue>3392</Issue>
         </ExcludeList>
@@ -43,9 +40,6 @@
         <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\muldimjagary\muldimjagary\*">
             <Issue>3392</Issue>
         </ExcludeList>
-        <ExcludeList Include="$(XunitTestBinBase)\GC\Scenarios\DoublinkList\dlstack\*">
-            <Issue>6553</Issue>
-        </ExcludeList>
         <ExcludeList Include="$(XunitTestBinBase)\JIT\Directed\coverage\importer\Desktop\ldelemnullarr1_il_d\ldelemnullarr1_il_d.cmd">
             <Issue>4851</Issue>
         </ExcludeList>
index b78271b..f346966 100644 (file)
@@ -146,9 +146,16 @@ public class Usage
             // ensure threshold is increasing
             if (!CheckPercentageIncrease(handleCount, prevHandleCount))
             {
-                // see github#4093 for the rationale for fail-fast in this test.
-                Environment.FailFast(string.Empty);
-                return false;
+                Console.WriteLine("Percentage not increasing, performing Collect/WFPF/Collect cycle");
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                if (handleCount == HandleCollectorTest.Count)
+                {
+                    Console.WriteLine("No handles finalized in Collect/WFPF/Collect cycle");
+                    return false;
+                }
             }
             prevHandleCount = handleCount;
         }
index a17e95a..f7aa10d 100644 (file)
@@ -11,6 +11,7 @@
 namespace DoubLink {
     using System;
     using System.Collections.Generic;
+    using System.Runtime.CompilerServices;
 
     public class DLCollect
     {
@@ -63,11 +64,38 @@ namespace DoubLink {
 
         }
 
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        public bool DrainFinalizerQueue(int iRep, int iObj)
+        {
+            int lastValue = DLinkNode.FinalCount;
+            while (true)
+            {
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                if (DLinkNode.FinalCount == iRep * iObj * 10)
+                {
+                    return true;
+                }
+
+                if (DLinkNode.FinalCount != lastValue)
+                {
+                    Console.WriteLine(" Performing Collect/Wait/Collect cycle again");
+                    lastValue = DLinkNode.FinalCount;
+                    continue;
+                }
+
+                Console.WriteLine(" Finalized number stable at " + lastValue);
+                return false;
+            }
+        }
 
         public bool runTest(int iRep, int iObj)
         {
 
             Mv_Collect = new List<DoubLink>(iRep);
+            bool success = false;
             for(int i=0; i <10; i++)
             {
                 SetLink(iRep, iObj);
@@ -75,16 +103,13 @@ namespace DoubLink {
                 GC.Collect();
             }
 
-            GC.WaitForPendingFinalizers();
-
-            if (DLinkNode.FinalCount != iRep * iObj * 10)
+            if (DrainFinalizerQueue(iRep, iObj))
             {
-                // see github#4093 for the rationale for fail-fast in this test.
-                Environment.FailFast(string.Empty);
+                success = true;
             }
 
             Console.WriteLine("{0} DLinkNodes finalized", DLinkNode.FinalCount);
-            return (DLinkNode.FinalCount==iRep*iObj*10);
+            return success;
         }
 
 
index 5e207be..8fa63bf 100644 (file)
@@ -13,6 +13,7 @@
 namespace DoubLink {
 
     using System;
+    using System.Runtime.CompilerServices;
 
     public class DLStack
     {
@@ -63,36 +64,50 @@ namespace DoubLink {
 
         }
 
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        public bool DrainFinalizerQueue(int iRep, int iObj)
+        {
+            int lastValue = DLinkNode.FinalCount;
+            while (true)
+            {
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                if (DLinkNode.FinalCount == iRep * iObj * 10)
+                {
+                    return true;
+                }
+
+                if (DLinkNode.FinalCount != lastValue)
+                {
+                    Console.WriteLine(" Performing Collect/Wait/Collect cycle again");
+                    lastValue = DLinkNode.FinalCount;
+                    continue;
+                }
+
+                Console.WriteLine(" Finalized number stable at " + lastValue);
+                return false;
+            }
+        }
+
 
         public bool runTest(int iRep, int iObj)
         {
-
+            bool success = false;
             for(int i=0; i <10; i++)
             {
                 SetLink(iRep, iObj);
                 MakeLeak(iRep);
             }
 
-                       long lastTotalMemory = long.MaxValue;
-                       long curTotalMemory = GC.GetTotalMemory(false);
-                       
-                       while (lastTotalMemory != curTotalMemory)
-                       {
-                               GC.Collect();
-                               GC.WaitForPendingFinalizers();
-
-                               lastTotalMemory = curTotalMemory;
-                               curTotalMemory = GC.GetTotalMemory(false);
-                       }
-
-            if (DLinkNode.FinalCount != iRep * iObj * 10)
+            if (DrainFinalizerQueue(iRep, iObj))
             {
-                // see github#4093 for the rationale for fail-fast in this test.
-                Environment.FailFast(string.Empty);
+                success = true;
             }
 
             Console.WriteLine("{0} DLinkNodes finalized", DLinkNode.FinalCount);
-            return (DLinkNode.FinalCount==iRep*iObj*10);
+            return success;
 
         }
 
index 76436ea..0f1016c 100644 (file)
@@ -11,6 +11,7 @@
 
 namespace DoubLink {
     using System;
+    using System.Runtime.CompilerServices;
 
     public class DoubLinkGen
     {
@@ -61,25 +62,47 @@ namespace DoubLink {
             return 1;
         }
 
+        [MethodImpl(MethodImplOptions.NoInlining)]
+        public bool DrainFinalizerQueue(int iRep, int iObj)
+        {
+            int lastValue = DLinkNode.FinalCount;
+            while (true)
+            {
+                GC.Collect();
+                GC.WaitForPendingFinalizers();
+                GC.Collect();
+
+                if (DLinkNode.FinalCount == iRep * iObj)
+                {
+                    return true;
+                }
+
+                if (DLinkNode.FinalCount != lastValue)
+                {
+                    Console.WriteLine(" Performing Collect/Wait/Collect cycle again");
+                    lastValue = DLinkNode.FinalCount;
+                    continue;
+                }
+
+                Console.WriteLine(" Finalized number stable at " + lastValue);
+                return false;
+            }
+        }
 
         public bool runTest(int iRep, int iObj)
         {
             SetLink(iRep, iObj);
             Mv_Doub = null;
+            bool success = false;
 
-            GC.Collect();
-            GC.WaitForPendingFinalizers();
-            GC.Collect();
-
-            if (DLinkNode.FinalCount != iRep * iObj)
+            if (DrainFinalizerQueue(iRep, iObj))
             {
-                // see github#4093 for the rationale for fail-fast in this test.
-                Environment.FailFast(string.Empty);
+                success = true;
             }
 
             Console.Write(DLinkNode.FinalCount);
             Console.WriteLine(" DLinkNodes finalized");
-            return (DLinkNode.FinalCount==iRep*iObj);
+            return success;
 
         }
 
index 5829a8f..f286b21 100644 (file)
@@ -70,7 +70,6 @@ GC/Features/BackgroundGC/foregroundgc/foregroundgc.sh
 GC/Features/LOHFragmentation/lohfragmentation/lohfragmentation.sh
 GC/Features/SustainedLowLatency/scenario/scenario.sh
 GC/Regressions/dev10bugs/536168/536168/536168.sh
-GC/Scenarios/DoublinkList/doublinkgen/doublinkgen.sh
 Loader/classloader/TypeGeneratorTests/TypeGeneratorTest612/Generated612/Generated612.sh
 Loader/classloader/TypeGeneratorTests/TypeGeneratorTest613/Generated613/Generated613.sh
 Loader/classloader/TypeGeneratorTests/TypeGeneratorTest614/Generated614/Generated614.sh