Merge pull request #601 from knocte/sock_improvements
[mono.git] / mcs / class / Mono.Debugger.Soft / Test / dtest-app.cs
index ad2747fb9a86cd2e20bca5ba88f379b3a8811ed9..2208c579bf9f2fb751cd22b444f36d8e341cff6a 100644 (file)
@@ -29,8 +29,37 @@ public enum AnEnum {
        B= 1
 }
 
+public sealed class Tests3 {
+       public static void M1 () {
+       }
+
+       static void M2 () {
+       }
+
+       public void M3 () {
+       }
+
+       void M4 () {
+       }
+
+}
+
+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;
@@ -86,6 +115,10 @@ public class GClass<T> {
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public GClass () {
        }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public void bp<T2> () {
+       }
 }
 
 public struct GStruct<T> {
@@ -99,6 +132,40 @@ public struct GStruct<T> {
        }
 }
 
+interface ITest
+{
+       void Foo ();
+       void Bar ();
+}
+
+interface ITest<T>
+{
+       void Foo ();
+       void Bar ();
+}
+
+class TestIfaces : ITest
+{
+       void ITest.Foo () {
+       }
+
+       void ITest.Bar () {
+       }
+
+       TestIfaces<int> Baz () {
+               return null;
+       }
+}
+
+class TestIfaces<T> : ITest<T>
+{
+       void ITest<T>.Foo () {
+       }
+
+       void ITest<T>.Bar () {
+       }
+}
+
 public class Tests : TestsBase
 {
 #pragma warning disable 0414
@@ -117,6 +184,7 @@ public class Tests : TestsBase
        double field_double;
        Thread field_class;
        IntPtr field_intptr;
+       int? field_nullable;
        static int static_i = 55;
        static string static_s = "A";
        public const int literal_i = 56;
@@ -161,6 +229,14 @@ public class Tests : TestsBase
                if (args.Length > 0 && args [0] == "suspend-test")
                        /* This contains an infinite loop, so execute it conditionally */
                        suspend ();
+               if (args.Length >0 && args [0] == "unhandled-exception") {
+                       unhandled_exception ();
+                       return 0;
+               }
+               if (args.Length >0 && args [0] == "unhandled-exception-user") {
+                       unhandled_exception_user ();
+                       return 0;
+               }
                breakpoints ();
                single_stepping ();
                arguments ();
@@ -177,6 +253,9 @@ public class Tests : TestsBase
                threads ();
                dynamic_methods ();
                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 ();
@@ -184,7 +263,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;
        }
@@ -202,7 +281,7 @@ public class Tests : TestsBase
                bp4 ();
                bp4 ();
                bp5 ();
-               bp6<string> ();
+               bp6<string> (new GClass <int> ());
                bp7<int> ();
                bp7<string> ();
        }
@@ -228,7 +307,8 @@ public class Tests : TestsBase
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
-       public static void bp6<T> () {
+       public static void bp6<T> (GClass<int> gc) {
+               gc.bp<int> ();
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -237,6 +317,7 @@ public class Tests : TestsBase
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void single_stepping () {
+               bool b = true;
                ss1 ();
                ss2 ();
                ss3 ();
@@ -244,9 +325,10 @@ public class Tests : TestsBase
                ss4 ();
                ss5 (new int [] { 1, 2, 3 }, new Func<int, bool> (is_even));
                try {
-                       ss6 (true);
+                       ss6 (b);
                } catch {
                }
+               ss7 ();
                ss_regress_654694 ();
        }
 
@@ -293,13 +375,32 @@ public class Tests : TestsBase
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void ss6 (bool b) {
                if (b) {
-                       ss7 ();
+                       ss6_2 ();
                        throw new Exception ();
                }
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss6_2 () {
+       }
+
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void ss7 () {
+               try {
+                       ss7_2 ();
+                       ss7_3 ();
+               } catch {
+               }
+               ss7_2 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss7_2 () {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void ss7_3 () {
+               throw new Exception ();
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -341,7 +442,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 });
        }
@@ -413,23 +514,32 @@ public class Tests : TestsBase
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void locals () {
+               string s = null;
                locals1 (null);
-               locals2<string> (null, 5, "ABC");
+               locals2<string> (null, 5, "ABC", ref s);
                locals3 ();
                locals6 ();
        }
 
+       [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)]
-       public static void locals2<T> (string[] args, int arg, T t) {
+       [StateMachine (typeof (int))]
+       public static void locals2<T> (string[] args, int arg, T t, ref string rs) {
                long i = 42;
                string s = "AB";
 
@@ -439,6 +549,7 @@ public class Tests : TestsBase
                        if (t != null)
                                i ++;
                }
+               rs = "A";
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -708,6 +819,29 @@ public class Tests : TestsBase
                }
        }
 
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void unhandled_exception () {
+               ThreadPool.QueueUserWorkItem (delegate {
+                               throw new InvalidOperationException ();
+                       });
+               Thread.Sleep (10000);
+       }
+
+       [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)
@@ -807,6 +941,8 @@ public class Tests : TestsBase
                CrossDomain o = (CrossDomain)domain.CreateInstanceAndUnwrap (
                                   typeof (CrossDomain).Assembly.FullName, "CrossDomain");
 
+               domains_2 (o, new CrossDomain ());
+
                o.invoke_2 ();
 
                o.invoke ();
@@ -815,11 +951,15 @@ public class Tests : TestsBase
 
                AppDomain.Unload (domain);
 
-               domains_2 ();
+               domains_3 ();
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
-       public static void domains_2 () {
+       public static void domains_2 (object o, object o2) {
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void domains_3 () {
        }
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
@@ -877,6 +1017,25 @@ public class Tests : TestsBase
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void frames_in_native () {
                Thread.Sleep (500);
+               object mon = new object ();
+               ThreadPool.QueueUserWorkItem (delegate {
+                               frames_in_native_2 ();
+                               lock (mon) {
+                                       Monitor.Pulse (mon);
+                               }
+                       });
+               lock (mon) {
+                       Monitor.Wait (mon);
+               }
+       }
+
+       [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)]
@@ -897,6 +1056,84 @@ public class Tests : TestsBase
 
                Debugger.Log (5, Debugger.IsLogging () ? "A" : "", "B");
        }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void type_load () {
+               type_load_2 ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       static void type_load_2 () {
+               var c1 = new Dictionary<int, int> ();
+               c1.ToString ();
+               var c = new TypeLoadClass ();
+               c.ToString ();
+               var c2 = new TypeLoadClass2 ();
+               c2.ToString ();
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void regress () {
+               regress_2755 (DateTime.Now);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static unsafe void regress_2755 (DateTime d) {
+               int* buffer = stackalloc int [128];
+
+               regress_2755_2 ();
+
+               int sum = 0;
+               for (int i = 0; i < 128; ++i)
+                       sum += buffer [i];
+
+               regress_2755_3 (sum);
+       }
+
+       [MethodImplAttribute (MethodImplOptions.NoInlining)]
+       public static void regress_2755_2 () {
+       }
+
+       [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 ();
+       }
+}
+
+class TypeLoadClass {
+}
+
+class TypeLoadClass2 {
 }
 
 public class CrossDomain : MarshalByRefObject
@@ -908,6 +1145,10 @@ public class CrossDomain : MarshalByRefObject
        public void invoke_2 () {
                Tests.invoke_in_domain_2 ();
        }
+
+       public int invoke_3 () {
+               return 42;
+       }
 }      
 
 public class Foo
@@ -920,6 +1161,7 @@ public class LineNumbers
 {
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void ln1 () {
+               // Column 3
                ln2 ();
                ln3 ();
        }
@@ -930,5 +1172,9 @@ public class LineNumbers
 
        [MethodImplAttribute (MethodImplOptions.NoInlining)]
        public static void ln3 () {
+#pragma warning disable 0219
+               int i = 5;
+#pragma warning restore 0219
+               #line 55 "FOO"
        }
 }