Add tests for OOM handling.
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 5 Nov 2010 18:49:28 +0000 (16:49 -0200)
committerRodrigo Kumpera <kumpera@gmail.com>
Wed, 10 Nov 2010 19:35:50 +0000 (17:35 -0200)
mono/tests/Makefile.am
mono/tests/gc-oom-handling.cs [new file with mode: 0644]
mono/tests/gc-oom-handling2.cs [new file with mode: 0644]

index 4f6fa21d73df36ec1df7502589f3c3b41e18e41a..c25eb51e784e8dcaf99527d4cad133a026ea42e9 100644 (file)
@@ -889,6 +889,20 @@ test-process-exit:
        @$(RUNTIME) bug-438454.exe > bug-438454.exe.stdout
        @diff bug-438454.exe.stdout $(srcdir)/bug-438454.exe.stdout.expected
 
+OOM_TESTS =    \
+       gc-oom-handling.exe     \
+       gc-oom-handling2.exe
+
+
+test-oom: $(OOM_TESTS)
+       @for fn in $+ ; do      \
+               echo "Testing $$fn ...";        \
+               MONO_GC_PARAMS=max-heap-size=16m,major=marksweep-par MONO_ENV_OPTIONS="--gc=sgen" $(RUNTIME) $$fn > $$fn.stdout || exit 1;      \
+               MONO_GC_PARAMS=max-heap-size=16m MONO_ENV_OPTIONS="--gc=sgen"                     $(RUNTIME) $$fn > $$fn.stdout || exit 1;      \
+               MONO_GC_PARAMS=max-heap-size=16m                                                  $(RUNTIME) $$fn > $$fn.stdout || exit 1;      \
+       done
+
+
 noinst_LTLIBRARIES = libtest.la
 
 INCLUDES = $(GLIB_CFLAGS) $(GMODULE_CFLAGS)
diff --git a/mono/tests/gc-oom-handling.cs b/mono/tests/gc-oom-handling.cs
new file mode 100644 (file)
index 0000000..dc7c7f9
--- /dev/null
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+
+class Driver {
+       static int Main () {
+               Console.WriteLine ("start");
+               var l = new List<object> ();
+               try {
+                       for (int i = 0; i < 40000; ++i) {
+                               var foo = new byte[2000];
+                               //Console.WriteLine ("done {0}",i);
+                               if (foo == null)
+                                       Console.WriteLine ("WTF");
+                               l.Add (foo);
+                       }
+                       Console.WriteLine ("done");
+                       return -1;
+               } catch (Exception e) {
+                       l.Clear ();
+                       l = null;
+                       Console.WriteLine ("OOM done");
+               }
+               return 0;
+       }
+}
+
diff --git a/mono/tests/gc-oom-handling2.cs b/mono/tests/gc-oom-handling2.cs
new file mode 100644 (file)
index 0000000..5b3cbf7
--- /dev/null
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+
+class Driver {
+       static int Main () {
+               Console.WriteLine ("start");
+               var r = new Random (123456);
+               var l = new List<object> ();
+               try {
+                       for (int i = 0; i < 40000; ++i) {
+                               var foo = new byte[r.Next () % 4000];
+                               l.Add (foo);
+                       }
+                       Console.WriteLine ("done");
+                       return -1;
+               } catch (Exception e) {
+                       l.Clear ();
+                       l = null;
+                       Console.WriteLine ("OOM done");
+               }
+               return 0;
+       }
+}
+