Merge branch 'BigIntegerParse'
[mono.git] / mcs / class / Mono.Debugger.Soft / Test / dtest-app.cs
index a5b663b1cd0aa74fd6f2c1b3f7bd51ab9aec0f3c..e72069f0cab17d186e6e5fa9f8fe655e2a7d26ae 100644 (file)
@@ -44,8 +44,22 @@ public sealed class Tests3 {
 
 }
 
+public static class Tests4 {
+       static Tests4 () {
+       }
+}
+
+public class AAttribute : Attribute {
+       public int afield;
+}
+
+public class BAttribute : AAttribute {
+       public int bfield;
+}
+
 [DebuggerDisplay ("Tests", Name="FOO", Target=typeof (int))]
 [DebuggerTypeProxy (typeof (Tests))]
+[BAttribute (afield = 1, bfield = 2)]
 public class Tests2 {
        [DebuggerBrowsableAttribute (DebuggerBrowsableState.Collapsed)]
        public int field_j;
@@ -118,6 +132,13 @@ public struct GStruct<T> {
        }
 }
 
+public struct NestedStruct {
+       NestedInner nested1, nested2;
+}
+
+public struct NestedInner {
+}
+
 interface ITest
 {
        void Foo ();
@@ -152,7 +173,12 @@ class TestIfaces<T> : ITest<T>
        }
 }
 
-public class Tests : TestsBase
+public interface ITest2
+{
+       int invoke_iface ();
+}
+
+public class Tests : TestsBase, ITest2
 {
 #pragma warning disable 0414
        int field_i;
@@ -179,9 +205,11 @@ public class Tests : TestsBase
        public AStruct field_struct;
        public object field_boxed_struct;
        public GStruct<int> generic_field_struct;
+       public KeyValuePair<int, object> boxed_struct_field;
        [ThreadStatic]
        public static int tls_i;
        public static bool is_attached = Debugger.IsAttached;
+       public NestedStruct nested_struct;
 
 #pragma warning restore 0414
 
@@ -209,6 +237,12 @@ public class Tests : TestsBase
                }
        }
 
+       public static void wait_one ()
+       {
+               ManualResetEvent evt = new ManualResetEvent (false);
+               evt.WaitOne ();
+       }
+
        public static int Main (String[] args) {
                tls_i = 42;
 
@@ -219,6 +253,18 @@ public class Tests : TestsBase
                        unhandled_exception ();
                        return 0;
                }
+               if (args.Length >0 && args [0] == "unhandled-exception-endinvoke") {
+                       unhandled_exception_endinvoke ();
+                       return 0;
+               }
+               if (args.Length >0 && args [0] == "unhandled-exception-user") {
+                       unhandled_exception_user ();
+                       return 0;
+               }
+               if (args.Length >0 && args [0] == "wait-one") {
+                       wait_one ();
+                       return 0;
+               }
                breakpoints ();
                single_stepping ();
                arguments ();
@@ -237,6 +283,7 @@ public class Tests : TestsBase
                user ();
                type_load ();
                regress ();
+               gc_suspend ();
                if (args.Length > 0 && args [0] == "domain-test")
                        /* This takes a lot of time, so execute it conditionally */
                        domains ();
@@ -244,7 +291,7 @@ public class Tests : TestsBase
                        ref_emit ();
                if (args.Length > 0 && args [0] == "frames-in-native")
                        frames_in_native ();
-               if (args.Length >0 && args [0] == "invoke-single-threaded")
+               if (args.Length > 0 && args [0] == "invoke-single-threaded")
                        new Tests ().invoke_single_threaded ();
                return 3;
        }
@@ -310,7 +357,11 @@ public class Tests : TestsBase
                } catch {
                }
                ss7 ();
+               ss_nested ();
                ss_regress_654694 ();
+               ss_step_through ();
+               ss_recursive (1);
+               ss_fp_clobber ();
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -384,6 +435,72 @@ public class Tests : TestsBase
                throw new Exception ();
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_nested () {
+               ss_nested_1 (ss_nested_2 ());
+               ss_nested_1 (ss_nested_2 ());
+               ss_nested_3 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_nested_1 (int i) {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static int ss_nested_2 () {
+               return 0;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_nested_3 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_step_through () {
+               step_through_1 ();
+               StepThroughClass.step_through_2 ();
+               step_through_3 ();
+       }
+
+       [DebuggerStepThrough]
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void step_through_1 () {
+       }
+
+       [DebuggerStepThrough]
+       class StepThroughClass {
+               [MethodImplAttribute (MethodImplOptions.NoInlining)]
+               public static void step_through_2 () {
+               }
+       }
+
+       [DebuggerStepThrough]
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void step_through_3 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_recursive (int n) {
+               if (n == 10)
+                       return;
+               ss_recursive (n + 1);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_fp_clobber () {
+               double v = ss_fp_clobber_1 (5.0);
+               ss_fp_clobber_2 (v);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static double ss_fp_clobber_1 (double d) {
+               return d + 2.0;
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss_fp_clobber_2 (double d) {
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static bool is_even (int i) {
                return i % 2 == 0;
@@ -423,7 +540,7 @@ public class Tests : TestsBase
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void objects () {
-               Tests t = new Tests () { field_i = 42, field_bool1 = true, field_bool2 = false, field_char = 'A', field_byte = 129, field_sbyte = -33, field_short = Int16.MaxValue - 5, field_ushort = UInt16.MaxValue - 5, field_long = Int64.MaxValue - 5, field_ulong = UInt64.MaxValue - 5, field_float = 3.14f, field_double = 3.14f, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B, field_class = null, field_intptr = new IntPtr (Int32.MaxValue - 5) };
+               Tests t = new Tests () { field_i = 42, field_bool1 = true, field_bool2 = false, field_char = 'A', field_byte = 129, field_sbyte = -33, field_short = Int16.MaxValue - 5, field_ushort = UInt16.MaxValue - 5, field_long = Int64.MaxValue - 5, field_ulong = UInt64.MaxValue - 5, field_float = 3.14f, field_double = 3.14f, field_s = "S", base_field_i = 43, base_field_s = "T", field_enum = AnEnum.B, field_class = null, field_intptr = new IntPtr (Int32.MaxValue - 5), field_nullable = null };
                t.o1 (new Tests2 () { field_j = 43 }, new GClass <int> { field = 42 }, new GClass <string> { field = "FOO" });
                o2 (new string [] { "BAR", "BAZ" }, new int[] { 42, 43 }, new int [,] { { 1, 2 }, { 3, 4 }}, (int[,])Array.CreateInstance (typeof (int), new int [] { 2, 2}, new int [] { 1, 3}), new int[] { 0 });
        }
@@ -465,7 +582,7 @@ public class Tests : TestsBase
        }
 
        public static void vtypes () {
-               Tests t = new Tests () { field_struct = new AStruct () { i = 42, s = "S", k = 43 }, generic_field_struct = new GStruct<int> () { i = 42 }, field_boxed_struct = new AStruct () { i = 42 }};
+               Tests t = new Tests () { field_struct = new AStruct () { i = 42, s = "S", k = 43 }, generic_field_struct = new GStruct<int> () { i = 42 }, field_boxed_struct = new AStruct () { i = 42 }, boxed_struct_field = new KeyValuePair<int, object> (1, (long)42 ) };
                AStruct s = new AStruct { i = 44, s = "T", k = 45 };
                AStruct[] arr = new AStruct[] { 
                        new AStruct () { i = 1, s = "S1" },
@@ -496,24 +613,35 @@ public class Tests : TestsBase
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void locals () {
                string s = null;
+               var astruct = new AStruct () { i = 42 };
                locals1 (null);
-               locals2<string> (null, 5, "ABC", ref s);
+               locals2<string> (null, 5, "ABC", ref s, ref astruct);
                locals3 ();
                locals6 ();
+               locals7<int> (22);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void locals11 (double a, ref double b) {
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void locals1 (string[] args) {
                long foo = 42;
 
+               double ri = 1;
+               locals11 (b: ref ri, a: ri);
+
                for (int j = 0; j < 10; ++j) {
                        foo ++;
                }
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
+#if NET_4_5
        [StateMachine (typeof (int))]
-       public static void locals2<T> (string[] args, int arg, T t, ref string rs) {
+#endif
+       public static void locals2<T> (string[] args, int arg, T t, ref string rs, ref AStruct astruct) {
                long i = 42;
                string s = "AB";
 
@@ -522,10 +650,12 @@ public class Tests : TestsBase
                                i ++;
                        if (t != null)
                                i ++;
+                       astruct = new AStruct ();
                }
                rs = "A";
        }
 
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void locals3 () {
                string s = "B";
@@ -608,6 +738,12 @@ public class Tests : TestsBase
        public static void locals6_6 (int arg) {
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void locals7<T> (T arg) {
+               T t = arg;
+               T t2 = t;
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void line_numbers () {
                LineNumbers.ln1 ();
@@ -762,6 +898,10 @@ public class Tests : TestsBase
                throw new Exception ();
        }
 
+       public int invoke_iface () {
+               return 42;
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void exceptions () {
                try {
@@ -780,6 +920,15 @@ public class Tests : TestsBase
                        throw new OverflowException ();
                } catch (Exception) {
                }
+               // no subclasses
+               try {
+                       throw new OverflowException ();
+               } catch (Exception) {
+               }
+               try {
+                       throw new Exception ();
+               } catch (Exception) {
+               }
 
                object o = null;
                try {
@@ -801,6 +950,42 @@ public class Tests : TestsBase
                Thread.Sleep (10000);
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void unhandled_exception_endinvoke_2 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void unhandled_exception_endinvoke () {
+                       Action action = new Action (() => 
+                       {
+                               throw new Exception ("thrown");
+                       });
+                       action.BeginInvoke ((ar) => {
+                               try {
+                                       action.EndInvoke (ar);
+                               } catch (Exception ex) {
+                                       //Console.WriteLine (ex);
+                               }
+                       }, null);
+               Thread.Sleep (1000);
+               unhandled_exception_endinvoke_2 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void unhandled_exception_user () {
+#if NET_4_5
+               System.Threading.Tasks.Task.Factory.StartNew (() => {
+                               Throw ();
+                       });
+               Thread.Sleep (10000);
+#endif
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void Throw () {
+               throw new Exception ();
+       }
+
        internal static Delegate create_filter_delegate (Delegate dlg, MethodInfo filter_method)
        {
                if (dlg == null)
@@ -976,6 +1161,23 @@ public class Tests : TestsBase
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void frames_in_native () {
                Thread.Sleep (500);
+               var evt = new ManualResetEvent (false);
+               
+               object mon = new object ();
+               ThreadPool.QueueUserWorkItem (delegate {
+                               frames_in_native_2 ();
+                               evt.Set ();
+                       });
+               evt.WaitOne ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void frames_in_native_2 () {
+               frames_in_native_3 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void frames_in_native_3 () {
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -1037,6 +1239,41 @@ public class Tests : TestsBase
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void regress_2755_3 (int sum) {
        }
+
+       static object gc_suspend_field;
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static unsafe void set_gc_suspend_field () {
+               set_gc_suspend_field_2 ();
+               // Clear stack
+               int* buffer = stackalloc int [4096];
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void set_gc_suspend_field_2 () {
+               gc_suspend_field = new object ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void gc_suspend_1 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void gc_suspend_invoke () {
+               gc_suspend_field = null;
+               GC.Collect ();
+               GC.WaitForPendingFinalizers ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void gc_suspend () {
+               set_gc_suspend_field ();
+               gc_suspend_1 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void generic_method<T> () where T : class {
+       }
 }
 
 class TypeLoadClass {