Add test for #9590.
authorRodrigo Kumpera <kumpera@gmail.com>
Thu, 17 Jan 2013 19:15:01 +0000 (14:15 -0500)
committerRodrigo Kumpera <kumpera@gmail.com>
Thu, 17 Jan 2013 19:29:43 +0000 (14:29 -0500)
mono/tests/Makefile.am
mono/tests/sgen-weakref-stress.cs [new file with mode: 0644]

index 73bdec90e2e0ac8f646f6446fa0969cc251586b8..f3f9c9615021587d209b717639b60edb394ddd30 100644 (file)
@@ -792,12 +792,13 @@ test-type-load: TestDriver.dll
        @$(RUNTIME) load-exceptions.exe > load-exceptions.exe.stdout 2> load-exceptions.exe.stderr
 
 
-EXTRA_DIST += sgen-bridge.cs sgen-descriptors.cs sgen-gshared-vtype.cs sgen-bridge-major-fragmentation.cs sgen-domain-unload.cs
+EXTRA_DIST += sgen-bridge.cs sgen-descriptors.cs sgen-gshared-vtype.cs sgen-bridge-major-fragmentation.cs sgen-domain-unload.cs sgen-weakref-stress.cs
 
 SGEN_TESTS =   \
        sgen-descriptors.exe    \
        sgen-gshared-vtype.exe  \
-       sgen-domain-unload.exe
+       sgen-domain-unload.exe  \
+       sgen-weakref-stress.exe
 
 sgen-regular-tests: $(SGEN_TESTS)
        @for fn in $+ ; do      \
diff --git a/mono/tests/sgen-weakref-stress.cs b/mono/tests/sgen-weakref-stress.cs
new file mode 100644 (file)
index 0000000..8962377
--- /dev/null
@@ -0,0 +1,38 @@
+using System;
+using System.Threading;
+
+public class Tests
+{
+       const int thread_count = 10;
+       const int weakrefs_per_thread = 5000;
+       const int crash_loops = 5;
+       public static void CrashRound () {
+               var t = new Thread [thread_count];
+               int fcount = 0;
+               for (int i = 0; i < thread_count; ++i) {
+                       t [i] = new Thread (delegate () {
+                          for (int j = 0; j < weakrefs_per_thread; ++j) {
+                              new WeakReference (new object ());
+                          }
+                          Interlocked.Increment (ref fcount);
+                       });
+               }
+
+               for (int i = 0; i < 10; ++i)
+                       t [i].Start ();
+
+               while (true) {
+                       if (fcount == 10)
+                               break;
+                       GC.Collect ();
+                       Thread.Sleep (1);
+               }
+       }
+       
+       public static void Main () {
+               for (int i = 0; i < crash_loops; ++i) {
+                       Console.WriteLine ("{0}", i);
+                       CrashRound ();
+               }
+       }
+}
\ No newline at end of file