Merge pull request #3290 from BrzVlad/fix-finalizer-tests
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 21 Jul 2016 22:32:18 +0000 (15:32 -0700)
committerGitHub <noreply@github.com>
Thu, 21 Jul 2016 22:32:18 +0000 (15:32 -0700)
[tests] Fix finalizer tests

mcs/class/System.ServiceModel/System.ServiceModel_test.dll.sources
mcs/class/corlib/Test/System.Runtime.CompilerServices/ConditionalWeakTableTest.cs
mcs/class/corlib/corlib_test.dll.sources
mcs/class/test-helpers/TestHelpers.cs [new symlink]
mono/mini/Makefile.am.in
mono/mini/TestHelpers.cs [new file with mode: 0644]
mono/tests/Makefile.am
mono/tests/sgen-toggleref.cs

index dd2dc7f1c70d6e37264ac1c428b2d6592f37eacf..d06cb33fe21c43bca6002a04358d3c9f0c28bbe9 100644 (file)
@@ -1,5 +1,4 @@
 NUnitMoonHelper.cs
-../../test-helpers/NetworkHelpers.cs
 FeatureBased/Features.Client/AsyncCallTesterProxy.cs
 FeatureBased/Features.Client/AsyncPatternServer.cs
 FeatureBased/Features.Client/DataContractTesterProxy.cs
index d4dcbcef6ec3a15b59370d05b2747cd6c868a993..5483974809bed349bde1a190afdd83810cd4038c 100644 (file)
@@ -36,6 +36,7 @@ using System.Runtime.Serialization;
 using System.Security.Permissions;
 using System.Collections.Generic;
 using System.Threading;
+using MonoTests.Helpers;
 
 
 namespace MonoTests.System.Runtime.CompilerServices {
@@ -197,11 +198,9 @@ namespace MonoTests.System.Runtime.CompilerServices {
                var cwt = new ConditionalWeakTable <object,object> ();
                List<object> keepAlive = null;
                List<WeakReference> keys = null;
-               Thread t = new Thread (delegate () {
+               FinalizerHelpers.PerformNoPinAction (delegate () {
                                FillStuff (cwt, out keepAlive, out keys);
                        });
-               t.Start ();
-               t.Join ();
 
                GC.Collect ();
 
@@ -254,10 +253,7 @@ namespace MonoTests.System.Runtime.CompilerServices {
                cwt.Add (b, new object ());
 
                List<WeakReference> res = null;
-               ThreadStart dele = () => { res = FillWithNetwork (cwt); };
-               var th = new Thread(dele);
-               th.Start ();
-               th.Join ();
+               FinalizerHelpers.PerformNoPinAction (() => { res = FillWithNetwork (cwt); });
 
                GC.Collect ();
                GC.Collect ();
@@ -301,16 +297,12 @@ namespace MonoTests.System.Runtime.CompilerServices {
                List<WeakReference> res, res2;
                res = res2 = null;
 
-               ThreadStart dele = () => {
+               FinalizerHelpers.PerformNoPinAction (() => {
                        res = FillWithNetwork2 (cwt);
                        ForcePromotion ();
                        k = FillReachable (cwt);
                        res2 = FillWithNetwork2 (cwt);
-               };
-
-               var th = new Thread(dele);
-               th.Start ();
-               th.Join ();
+               });
 
                GC.Collect ();
 
@@ -445,10 +437,7 @@ namespace MonoTests.System.Runtime.CompilerServices {
                        Assert.Ignore ("Not working on Boehm.");
                lock (_lock1) { 
                        var cwt = new ConditionalWeakTable <object,object> ();
-                       ThreadStart dele = () => { FillWithFinalizable (cwt); };
-                       var th = new Thread(dele);
-                       th.Start ();
-                       th.Join ();
+                       FinalizerHelpers.PerformNoPinAction (() => { FillWithFinalizable (cwt); });
                        GC.Collect ();
                        GC.Collect ();
 
index b7cf0d04b3a6a481de7fc9391d73868df0a04c7b..7dfe833f16380903f66c61071e763743e1c1d92d 100644 (file)
@@ -513,4 +513,4 @@ System.Threading/CountdownEventTests.cs
 System/AggregateExceptionTests.cs
 System.Threading/ThreadLocalTests.cs
 System.Threading/SpinLockTests.cs
-
+../../test-helpers/TestHelpers.cs
diff --git a/mcs/class/test-helpers/TestHelpers.cs b/mcs/class/test-helpers/TestHelpers.cs
new file mode 120000 (symlink)
index 0000000..5cf769a
--- /dev/null
@@ -0,0 +1 @@
+../../../mono/mini/TestHelpers.cs
\ No newline at end of file
index 15a89aade3676522290c0affa9c36f4bceb677bd..0145a955d42e90c429645a6e9f675fe73a4edc33 100755 (executable)
@@ -632,8 +632,8 @@ generics.exe: generics.cs TestDriver.dll generics-variant-types.dll
 %.exe: %.il
        $(ILASM) -output=$@ $<
 
-TestDriver.dll: $(srcdir)/TestDriver.cs
-       $(MCS) -out:$@ -target:library $<
+TestDriver.dll: $(srcdir)/TestDriver.cs $(srcdir)/TestHelpers.cs
+       $(MCS) -out:$@ -target:library $^
 
 generics-variant-types.dll: generics-variant-types.il
        $(ILASM) -dll -output=$@ $<
@@ -839,6 +839,7 @@ BUILT_SOURCES = version.h $(arch_built)
 
 CLEANFILES= $(BUILT_SOURCES) *.exe *.dll
 EXTRA_DIST = TestDriver.cs \
+       TestHelpers.cs \
        genmdesc.pl                             \
        emitnunit.pl                    \
        $(test_sources)                         \
diff --git a/mono/mini/TestHelpers.cs b/mono/mini/TestHelpers.cs
new file mode 100644 (file)
index 0000000..01ed135
--- /dev/null
@@ -0,0 +1,29 @@
+using System;
+using System.Threading;
+
+namespace MonoTests.Helpers {
+
+       public static class FinalizerHelpers {
+               private static IntPtr aptr;
+
+               private static unsafe void NoPinActionHelper (int depth, Action act)
+               {
+                       // Avoid tail calls
+                       int* values = stackalloc int [20];
+                       aptr = new IntPtr (values);
+
+                       if (depth <= 0)
+                               act ();
+                       else
+                               NoPinActionHelper (depth - 1, act);
+               }
+
+               public static void PerformNoPinAction (Action act)
+               {
+                       Thread thr = new Thread (() => NoPinActionHelper (1024, act));
+                       thr.Start ();
+                       thr.Join ();
+               }
+       }
+}
+
index c8aaaa3d0f55fc1c6c8221201f8fff3c6a4ee239..3f225f93cde330f8ed3b73251abc83a08e55b3be 100644 (file)
@@ -931,7 +931,7 @@ assemblyresolve/test/asm.dll:
        $(MAKE) -C assemblyresolve prereq
 
 TestDriver.dll:
-       $(MCS) -target:library -out:$@ $(srcdir)/../mini/TestDriver.cs
+       $(MCS) -target:library -out:$@ $(srcdir)/../mini/TestDriver.cs $(srcdir)/../mini/TestHelpers.cs
 
 test_cs: $(TEST_PROG) $(TESTSI_CS) libtest.la
        @failed=0; \
index f4f2df11555816c07308e4935012b020ea486dd1..9e5738078fe4d4a2b8a6d8d8028fa2e969229660 100644 (file)
@@ -4,6 +4,7 @@ using System.Collections.Generic;
 using System.Threading;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
+using MonoTests.Helpers;
 
 public class Toggleref {
        public int __test;
@@ -60,9 +61,7 @@ class Driver {
        static int test_0_root_keeps_child ()
        {
                Console.WriteLine ("test_0_root_keeps_child");
-               var t = new Thread (SetupLinks);
-               t.Start ();
-               t.Join ();
+               FinalizerHelpers.PerformNoPinAction (SetupLinks);
                
                GC.Collect ();
                GC.WaitForPendingFinalizers ();
@@ -113,9 +112,7 @@ class Driver {
        {
                Console.WriteLine ("test_0_child_goes_away");
 
-               var t = new Thread (SetupLinks2);
-               t.Start ();
-               t.Join ();
+               FinalizerHelpers.PerformNoPinAction (SetupLinks2);
 
                GC.Collect ();
                GC.WaitForPendingFinalizers ();
@@ -161,9 +158,7 @@ class Driver {
        {
                Console.WriteLine ("test_0_CWT_keep_child_alive");
 
-               var t = new Thread (SetupLinks3);
-               t.Start ();
-               t.Join ();
+               FinalizerHelpers.PerformNoPinAction (SetupLinks3);
 
                GC.Collect ();
                GC.WaitForPendingFinalizers ();
@@ -207,4 +202,4 @@ class Driver {
                return TestDriver.RunTests (typeof (Driver), args);
        }
 
-}
\ No newline at end of file
+}