X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Ftests%2Fstack-overflow.cs;h=d71f9d0719de9a0df9e8f67755a52d7f5481d7ab;hb=89fa7004411fee95ce9819c2a4e4116cafbe0f89;hp=6784347b4d3942bc8ca6f86b46ae9230f017057e;hpb=fc4b07f20f9e79fe99d4b520bb5ff8b5e80b10f6;p=mono.git diff --git a/mono/tests/stack-overflow.cs b/mono/tests/stack-overflow.cs index 6784347b4d3..d71f9d0719d 100644 --- a/mono/tests/stack-overflow.cs +++ b/mono/tests/stack-overflow.cs @@ -1,41 +1,77 @@ using System; +using System.Collections.Generic; public class Tests { struct A1 { - long a1, a2, a3, a4; + public long a1, a2, a3, a4; } struct A2 { - A1 a1, a2, a3, a4; + public A1 a1, a2, a3, a4; } struct A3 { - A2 a1, a2, a3, a4; + public A2 a1, a2, a3, a4; } struct A4 { - A3 a1, a2, a3, a4; + public A3 a1, a2, a3, a4; } struct A5 { - A4 a1, a2, a3, a4; + public A4 a1, a2, a3, a4; } public static int foo () { A5 a5; + /* Prevent a5 from being optimized away */ + a5 = new A5 (); + a5.a1.a1.a1.a1.a1 = 5; + return foo () + 1; } + // call an icall so we have a big chance to hit the + // stack overflow in unmanaged code + static void Recurse () { + Type t = typeof (Dictionary<,>); + t.GetGenericArguments (); + Recurse (); + } + public static int Main () { + // Try overflow in managed code + int count = 0; try { foo (); } catch (StackOverflowException) { Console.WriteLine ("Stack overflow caught."); - return 0; + count ++; } - return 1; + if (count != 1) + return 1; + + // Try overflow in unmanaged code + count = 0; + try { + Recurse (); + } catch (Exception ex) { + Console.WriteLine ("Handled: {0}", ex.Message); + count++; + } + // Check that the stack protection is properly restored + try { + Recurse (); + } catch (Exception ex) { + Console.WriteLine ("Again: {0}", ex.Message); + count++; + } + if (count != 2) + return 2; + + return 0; } }