using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Runtime.CompilerServices; using System.Threading.Tasks; struct Foo { public int i, j, k, l, m, n; } struct GFoo { public T dummy; public T t; public int i; public Foo f; public static T static_dummy; public static T static_t; public static Foo static_f; } struct GFoo2 { public T t, t2, t3; } class GFoo3 { public T t, t2; public GFoo3 () { } [MethodImplAttribute (MethodImplOptions.NoInlining)] public GFoo3 (T i1, T i2) { t = i1; t2 = i2; } } // // Tests for generic sharing of vtypes. // The tests use arrays to pass/receive values to keep the calling convention of the methods stable, which is a current limitation of the runtime support for gsharedvt. // // // Interfaces are used to prevent the AOT compiler from discovering instantiations, thus forcing the usage of the gsharedvt // versions of methods. Unused vtype type arguments are used to test gsharedvt methods with ref type arguments, i.e. // when calling foo as foo, the gsharedvt version is used, but with a ref type argument. // // FIXME: Add mixed ref/noref tests, i.e. Dictionary #if __MOBILE__ public class GSharedTests #else public class Tests #endif { #if !__MOBILE__ public static int Main (String[] args) { return TestDriver.RunTests (typeof (Tests), args); } #endif [MethodImplAttribute (MethodImplOptions.NoInlining)] static void gshared (T [] array, int i, int j) { T tmp = array [i]; array [i] = array [j]; array [j] = tmp; } // Test that the gshared and gsharedvt versions don't mix public static int test_0_vt_gshared () { string[] sarr = new string [2] { "A", "B" }; gshared (sarr, 0, 1); Foo[] arr = new Foo [2]; arr [0] = new Foo () { i = 1, j = 2 }; arr [1] = new Foo () { i = 3, j = 4 }; gshared (arr, 0, 1); if (arr [0].i != 3 || arr [0].j != 4) return 1; if (arr [1].i != 1 || arr [1].j != 2) return 2; return 0; } static void ldelem_stelem (T [] array, int i, int j) { T tmp = array [i]; array [i] = array [j]; array [j] = tmp; } public static int test_0_vt_ldelem_stelem () { Foo[] arr = new Foo [2]; arr [0] = new Foo () { i = 1, j = 2 }; arr [1] = new Foo () { i = 3, j = 4 }; ldelem_stelem (arr, 0, 1); if (arr [0].i != 3 || arr [0].j != 4) return 1; if (arr [1].i != 1 || arr [1].j != 2) return 2; int[] arr2 = new int [2] { 1, 2 }; ldelem_stelem (arr2, 0, 1); if (arr2 [0] !=2 || arr2 [1] != 1) return 3; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] private static void initobj (T [] array, int i, int j) { T x = default(T); array [i] = x; } public static int test_0_vt_initobj () { Foo[] arr = new Foo [2]; arr [0] = new Foo () { i = 1, j = 2 }; arr [1] = new Foo () { i = 3, j = 4 }; initobj (arr, 0, 1); if (arr [0].i != 0 || arr [0].j != 0) return 1; if (arr [1].i != 3 || arr [1].j != 4) return 2; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static T ldobj_stobj (ref T t1, ref T t2) { t1 = t2; T t = t2; t2 = default(T); return t; } public static int test_0_vt_ldobj_stobj () { int i = 5; int j = 6; if (ldobj_stobj (ref i, ref j) != 6) return 1; if (i != 6 || j != 0) return 2; double d1 = 1.0; double d2 = 2.0; if (ldobj_stobj (ref d1, ref d2) != 2.0) return 3; if (d1 != 2.0 || d2 != 0.0) return 4; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] private static void box (T [] array, object[] arr) { object x = array [0]; arr [0] = x; } public static int test_0_vt_box () { Foo[] arr = new Foo [2]; arr [0] = new Foo () { i = 1, j = 2 }; object[] arr2 = new object [16]; box (arr, arr2); if (arr2 [0].GetType () != typeof (Foo)) return 1; Foo f = (Foo)arr2 [0]; if (f.i != 1 || f.j != 2) return 2; string[] arr3 = new string [16]; object[] arr4 = new object [16]; arr3 [0] = "OK"; box (arr3, arr4); if (arr4 [0] != (object)arr3 [0]) return 3; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] private static void unbox_any (T [] array, object[] arr) { T t = (T)arr [0]; array [0] = t; } public static int test_0_vt_unbox_any () { int[] iarr = new int [16]; unbox_any (iarr, new object [] { 12 }); Foo[] arr = new Foo [2]; object[] arr2 = new object [16]; arr2 [0] = new Foo () { i = 1, j = 2 }; unbox_any (arr, arr2); if (arr [0].i != 1 || arr [0].j != 2) return 2; return 0; } interface IFaceUnbox { T Unbox (T t, T2 t2, object o); } class ClassUnbox : IFaceUnbox { public T Unbox (T t, T2 t2, object o) { return (T)o; } } // unbox.any on a ref type in a gsharedvt method public static int test_0_ref_gsharedvt_aot_unbox_any () { IFaceUnbox iface = new ClassUnbox (); string s = iface.Unbox ("A", 2, "A"); if (s != "A") return 1; return 0; } public static int test_0_unbox_any_enum () { IFaceUnbox iface = new ClassUnbox (); AnEnum res = iface.Unbox (AnEnum.One, 0, 1); if (res != AnEnum.Two) return 1; res = iface.Unbox (AnEnum.One, 0, AnEnum.Two); if (res != AnEnum.Two) return 2; int res2 = iface.Unbox (0, AnEnum.One, AnEnum.Two); if (res2 != 1) return 3; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void ldfld_nongeneric (GFoo[] foo, int[] arr) { arr [0] = foo [0].i; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void ldfld (GFoo[] foo, T[] arr) { arr [0] = foo [0].t; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void stfld_nongeneric (GFoo[] foo, int[] arr) { foo [0].i = arr [0]; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void stfld (GFoo[] foo, T[] arr) { foo [0].t = arr [0]; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void ldflda (GFoo[] foo, int[] arr) { arr [0] = foo [0].f.i; } public static int test_0_vt_ldfld_stfld () { var foo = new GFoo () { t = new Foo () { i = 1, j = 2 }, i = 5, f = new Foo () { i = 5, j = 6 } }; var farr = new GFoo[] { foo }; /* Normal fields with a variable offset */ var iarr = new int [10]; ldfld_nongeneric (farr, iarr); if (iarr [0] != 5) return 1; iarr [0] = 16; stfld_nongeneric (farr, iarr); if (farr [0].i != 16) return 2; /* Variable type field with a variable offset */ var arr = new Foo [10]; ldfld (farr, arr); if (arr [0].i != 1 || arr [0].j != 2) return 3; arr [0] = new Foo () { i = 3, j = 4 }; stfld (farr, arr); if (farr [0].t.i != 3 || farr [0].t.j != 4) return 4; ldflda (farr, iarr); if (iarr [0] != 5) return 5; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void stsfld (T[] arr) { GFoo.static_t = arr [0]; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void ldsfld (T[] arr) { arr [0] = GFoo.static_t; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void ldsflda (int[] iarr) { iarr [0] = GFoo.static_f.i; } public static int test_0_stsfld () { Foo[] farr = new Foo [] { new Foo () { i = 1, j = 2 } }; stsfld (farr); if (GFoo.static_t.i != 1 || GFoo.static_t.j != 2) return 1; Foo[] farr2 = new Foo [1]; ldsfld (farr2); if (farr2 [0].i != 1 || farr2 [0].j != 2) return 2; var iarr = new int [10]; GFoo.static_f = new Foo () { i = 5, j = 6 }; ldsflda (iarr); if (iarr [0] != 5) return 3; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static object newarr () { object o = new T[10]; return o; } public static int test_0_vt_newarr () { object o = newarr (); if (!(o is Foo[])) return 1; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static Type ldtoken () { return typeof (GFoo); } public static int test_0_vt_ldtoken () { Type t = ldtoken (); if (t != typeof (GFoo)) return 1; t = ldtoken (); if (t != typeof (GFoo)) return 2; return 0; } public static int test_0_vtype_list () { List l = new List (); l.Add (5); if (l.Count != 1) return 1; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static int args_simple (T t, int i) { return i; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static int args_simple (T t, int i, T t2) { return i; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static Type args_rgctx (T t, int i) { return typeof (T); } [MethodImplAttribute (MethodImplOptions.NoInlining)] static Type eh_in (T t, int i) { throw new OverflowException (); } [MethodImplAttribute (MethodImplOptions.NoInlining)] static T return_t (T t) { return t; } [MethodImplAttribute (MethodImplOptions.NoInlining)] T return_this_t (T t) { return t; } interface IFaceGSharedVtIn { T return_t (T t); } class ClassGSharedVtIn : IFaceGSharedVtIn { public T return_t (T t) { return t; } } public static int test_0_gsharedvt_in () { // Check that the non-generic argument is passed at the correct stack position int r = args_simple (true, 42); if (r != 42) return 1; r = args_simple (new Foo (), 43); if (r != 43) return 2; // Check that the proper rgctx is passed to the method Type t = args_rgctx (5, 42); if (t != typeof (int)) return 3; var v = args_simple> (new GFoo2 () { t = 11, t2 = 12 }, 44, new GFoo2 () { t = 11, t2 = 12 }); if (v != 44) return 4; // Check that EH works properly try { eh_in (1, 2); } catch (OverflowException) { } return 0; } public static int test_0_gsharedvt_in_ret () { int i = return_t (42); if (i != 42) return 1; long l = return_t (Int64.MaxValue); if (l != Int64.MaxValue) return 2; double d = return_t (3.0); if (d != 3.0) return 3; float f = return_t (3.0f); if (f != 3.0f) return 4; short s = return_t (16); if (s != 16) return 5; var v = new GFoo2 () { t = 55, t2 = 32 }; var v2 = return_t> (v); if (v2.t != 55 || v2.t2 != 32) return 6; IFaceGSharedVtIn o = new ClassGSharedVtIn (); var v3 = new GFoo2 () { t = 55, t2 = 32 }; var v4 = o.return_t> (v3); if (v4.t != 55 || v4.t2 != 32) return 7; i = new GSharedTests ().return_this_t (42); if (i != 42) return 8; return 0; } public static int test_0_gsharedvt_in_delegates () { Func f = new Func (return_t); if (f (42) != 42) return 1; return 0; } class DelClass { [MethodImplAttribute (MethodImplOptions.NoInlining)] public static T return_t (T t) { return t; } } public static int test_0_gsharedvt_in_delegates_reflection () { var m = typeof(DelClass).GetMethod ("return_t").MakeGenericMethod (new Type [] { typeof (int) }); Func f = (Func)Delegate.CreateDelegate (typeof (Func), null, m, false); if (f (42) != 42) return 1; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static T return2_t (T t) { return return_t (t); } public static int test_0_gsharedvt_calls () { if (return2_t (2) != 2) return 1; if (return2_t ("A") != "A") return 2; if (return2_t (2.0) != 2.0) return 3; return 0; } static GFoo3 newobj (T t1, T t2) { return new GFoo3 (t1, t2); } public static int test_0_gshared_new () { var g1 = newobj (1, 2); if (g1.t != 1 || g1.t2 != 2) return 1; var g2 = newobj (1.0, 2.0); if (g1.t != 1.0 || g1.t2 != 2.0) return 2; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static GFoo2 newobj_vt (T t1, T t2) { return new GFoo2 () { t = t1, t2 = t2 }; } public static int test_0_gshared_new_vt () { GFoo2 v1 = newobj_vt (1, 2); if (v1.t != 1 || v1.t2 != 2) return 1; GFoo2 v2 = newobj_vt (1.0, 2.0); if (v2.t != 1.0 || v2.t2 != 2.0) return 2; return 0; } // // Tests for transitioning out of gsharedvt code // // T1=Nullable<..> is not currently supported by gsharedvt [MethodImplAttribute (MethodImplOptions.NoInlining)] static T return_t_nogshared (T t) { object o = t; T t2 = (T)o; //Console.WriteLine ("X: " + t); return t; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static int return_int_nogshared (T t) { object o = t; T t2 = (T)o; return 2; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static A return_vtype_nogshared (T t) { object o = t; T t2 = (T)o; return new A () { a = 1, b = 2, c = 3 }; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static T return2_t_out (T t) { return return_t_nogshared (t); } [MethodImplAttribute (MethodImplOptions.NoInlining)] static int return2_int_out (T t) { return return_int_nogshared (t); } [MethodImplAttribute (MethodImplOptions.NoInlining)] static A return2_vtype_out (T t) { return return_vtype_nogshared (t); } struct A { public int a, b, c; } [Category ("!FULLAOT")] public static int test_0_gsharedvt_out () { if (return2_t_out (2) != 2) return 1; if (return2_t_out ("A") != "A") return 2; if (return2_t_out (2.0) != 2.0) return 3; if (return2_t_out (2.0f) != 2.0f) return 4; A a = new A () { a = 1, b = 2, c = 3 }; A a2 = return2_t_out (a); if (a2.a != 1 || a2.b != 2 || a2.c != 3) return 5; // Calls with non gsharedvt return types if (return2_int_out (1) != 2) return 6; A c = return2_vtype_out (a); if (a2.a != 1 || a2.b != 2 || a2.c != 3) return 7; return 0; } public class GenericClass { public static T Z (IList x, int index) { return x [index]; } } public static int test_0_generic_array_helpers () { int[] x = new int[] {100, 200}; // Generic array helpers should be treated as gsharedvt-out if (GenericClass.Z (x, 0) != 100) return 1; return 0; } internal class IntComparer : IComparer { public int Compare (int ix, int iy) { if (ix == iy) return 0; if (((uint) ix) < ((uint) iy)) return -1; return 1; } } [MethodImplAttribute (MethodImplOptions.NoInlining)] static int gshared_out_iface (T t1, T t2, IComparer comp) { return comp.Compare (t1, t2); } public static int test_0_gshared_out_iface () { // Call out from gshared to a nongeneric method through a generic interface method if (gshared_out_iface (2, 2, new IntComparer ()) != 0) return 1; return 0; } struct Foo1 { public int i1, i2, i3; } struct Foo2 { int i1, i2, i3, i4, i5; public T foo; } [MethodImplAttribute (MethodImplOptions.NoInlining)] public static void locals (T t) { Foo2 t2 = new Foo2 (); object o = t2; } public static int test_0_locals () { // Test that instantiations of type parameters are allocated the proper local type int i = 1; for (int j = 0; j < 10; ++j) i ++; locals (new Foo1 () { i1 = 1, i2 = 2, i3 = 3 }); return 0; } public interface IFace { T return_t_iface (T t); } public class Parent { public virtual T return_t_vcall (T t) { throw new Exception (); return t; } } public class Child : Parent, IFace { public override T return_t_vcall (T t) { return t; } public T return_t_iface (T t) { return t; } } [MethodImplAttribute (MethodImplOptions.NoInlining)] static T return_t_vcall (Parent r, T t) { return r.return_t_vcall (t); } public static int test_0_vcalls () { if (return_t_vcall (new Child (), 2) != 2) return 1; // Patching for (int i = 0; i < 10; ++i) { if (return_t_vcall (new Child (), 2) != 2) return 2; } if (return_t_vcall (new Child (), 2.0) != 2.0) return 3; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static T return_t_iface (IFace r, T t) { return r.return_t_iface (t); } public static int test_0_iface_calls () { if (return_t_iface (new Child (), 2) != 2) return 1; if (return_t_iface (new Child (), 2.0) != 2.0) return 3; return 0; } interface IFaceKVP { T do_kvp (T a); } static KeyValuePair make_kvp (T1 t1, T2 t2) { return new KeyValuePair (t1, t2); } static T2 use_kvp (KeyValuePair kvp) { return kvp.Value; } class ClassKVP : IFaceKVP { public T do_kvp (T a) { var t = make_kvp (a, a); // argument is an instance of a vtype instantiated with gsharedvt type arguments return use_kvp (t); } } public static int test_0_gsharedvt_ginstvt_constructed_arg () { { // AOT: Force a instantiation of use_kvp long a = 1; var t = make_kvp (a, a); var z = use_kvp (t); } IFaceKVP c = new ClassKVP (); if (c.do_kvp (1) != 1) return 1; return 0; } public static int test_0_gsharedvt_ginstvt_constructed_arg_float () { { // AOT: Force a instantiation of use_kvp double a = 1; var t = make_kvp (a, a); var z = use_kvp (t); } IFaceKVP c = new ClassKVP (); if (c.do_kvp (1) != 1) return 1; return 0; } interface IGetter { T Get(); } class Getter : IGetter { public T Get() { return default(T); } } abstract class Session { public abstract IGetter Getter { get; } } class IosSession : Session { private IGetter getter = new Getter(); public override IGetter Getter { get { return getter; } } } enum ENUM_TYPE { } public static int test_0_regress_5156 () { new IosSession().Getter.Get(); return 0; } public struct VT { public Action a; } public class D { } public class A3 { public void OuterMethod(TArg1 value) { this.InnerMethod(value, 0); } private void InnerMethod(TArg1 v1, TArg2 v2) { //Console.WriteLine("{0} {1}",v1,v2); } } public static int test_0_regress_2096 () { var a = new A3(); // The following work: a.OuterMethod(1); a.OuterMethod(DateTime.Now); var v = new VT(); a.OuterMethod(v); var x = new D(); // Next line will crash with Attempting to JIT compile method on device // Attempting to JIT compile method a.OuterMethod(x); return 0; } public class B { public void Test() { //System.Console.WriteLine(typeof(T)); } } public class A { public void Test() { new B().Test>(); } } public static int test_0_regress_6040 () { //new B().Test>(); new A().Test(); new A().Test(); new A().Test(); return 0; } class ArrayContainer { private T[,] container = new T[1,1]; public T Prop { [MethodImplAttribute (MethodImplOptions.NoInlining)] get { return container [0, 0]; } [MethodImplAttribute (MethodImplOptions.NoInlining)] set { container [0, 0] = value; } } } [MethodImplAttribute (MethodImplOptions.NoInlining)] public static int test_0_multi_dim_arrays () { var c = new ArrayContainer (); c.Prop = 5; return c.Prop == 5 ? 0 : 1; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static T2 rgctx_in_call_innner_inner (T1 t1, T2 t2) { return t2; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static GFoo3 rgctx_in_call_inner (T t) { return rgctx_in_call_innner_inner (1, new GFoo3 ()); } public static int test_0_rgctx_in_call () { // The call is made through the rgctx call, and it needs an IN trampoline var t = rgctx_in_call_inner (1); if (t is GFoo3) return 0; return 1; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void arm_params1 (T t1, T t2, T t3, T t4, T t5, T t6) { } [MethodImplAttribute (MethodImplOptions.NoInlining)] static void arm_params2 (T t1, T t2, T t3, long t4, T t5, T t6) { } public static int test_0_arm_param_passing () { arm_params1 (1, 2, 3, 4, 5, 6); arm_params1 (1, 2, 3, 4, 5, 6); return 0; } sealed class ScheduledItem { private readonly object _scheduler; private readonly TValue _state; private readonly object _action; public ScheduledItem(object o, TValue state, object action, TAbsolute dueTime) { _state = state; } } abstract class VirtualTimeSchedulerBase { public abstract void ScheduleAbsolute(TState state, TAbsolute dueTime); } class VirtualTimeScheduler : VirtualTimeSchedulerBase { public override void ScheduleAbsolute(TState state, TAbsolute dueTime) { var si = new ScheduledItem(this, state, null, dueTime); } } public static int test_0_rx_mixed_regress () { var v = new VirtualTimeScheduler (); v.ScheduleAbsolute (null, 22); return 0; } public class Base { public virtual T foo (T t) { return t; } } class Class1 : Base { public object o; public override T foo (T t) { o = t; return t; } } class Class2 : Base { public object o; public override T foo (T t) { o = t; return t; } } [MethodImplAttribute (MethodImplOptions.NoInlining)] public static void bar (Base b, T t) { b.foo (t); } public static int test_0_virtual_generic () { Class1 c1 = new Class1 (); Class2 c2 = new Class2 (); bar (c1, 5); if (!(c1.o is int) || ((int)c1.o != 5)) return 1; bar (c1, 6.0); if (!(c1.o is double) || ((double)c1.o != 6.0)) return 2; bar (c1, 7.0f); if (!(c1.o is float) || ((float)c1.o != 7.0f)) return 3; bar (c2, 5); if (!(c2.o is int) || ((int)c2.o != 5)) return 4; bar (c2, 6.0); bar (c2, 7.0f); return 0; } public interface IFace1 { void m1 (); void m2 (); void m3 (); void m4 (); void m5 (); } public class ClassIFace : IFace1 { public void m1 () { } public void m2 () { } public void m3 () { } public void m4 () { } public void m5 () { } } interface IFaceIFaceCall { void call (IFace1 iface); } class MakeIFaceCall : IFaceIFaceCall { public void call (IFace1 iface) { iface.m1 (); } } // Check normal interface calls from gsharedvt call to fully instantiated methods public static int test_0_instatiated_iface_call () { ClassIFace c1 = new ClassIFace (); IFaceIFaceCall c = new MakeIFaceCall (); c.call (c1); return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static string to_string(T t, T2 t2) { return t.ToString (); } public enum AnEnum { One, Two }; public static int test_0_constrained_tostring () { if (to_string (1, 1) != "1") return 1; if (to_string (AnEnum.One, 1) != "One") return 2; if (to_string ("A", 1) != "A") return 3; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static int get_hash(T t, T2 t2) { return t.GetHashCode (); } public static int test_0_constrained_get_hash () { if (get_hash (1, 1) != 1.GetHashCode ()) return 1; if (get_hash (1.0, 1) != 1.0.GetHashCode ()) return 2; if (get_hash (AnEnum.One, 1) != AnEnum.One.GetHashCode ()) return 3; if (get_hash ("A", 1) != "A".GetHashCode ()) return 4; return 0; } [MethodImplAttribute (MethodImplOptions.NoInlining)] static bool equals(T t, T2 t2) { return t.Equals (t); } public static int test_0_constrained_equals () { if (equals (1, 1) != true) return 1; if (equals (1.0, 1) != true) return 2; if (equals (AnEnum.One, 1) != true) return 3; if (equals ("A", 1) != true) return 4; return 0; } interface IGetType { Type gettype(T t, T2 t2); } public class CGetType : IGetType { [MethodImplAttribute (MethodImplOptions.NoInlining)] public Type gettype(T t, T2 t2) { return t.GetType (); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public Type gettype2(T t) { return t.GetType (); } } public static int test_0_constrained_gettype () { IGetType c = new CGetType (); if (c.gettype (1, 1) != typeof (int)) return 1; if (c.gettype ("A", 1) != typeof (string)) return 2; /* Partial sharing */ var c2 = new CGetType (); if (c2.gettype2 (1) != typeof (long)) return 3; return 0; } interface IConstrainedCalls { Pair vtype_ret(T t, T2 t2) where T: IReturnVType; AnEnum enum_ret(T t, T2 t2) where T: IReturnVType; } public interface IReturnVType { Pair return_vtype (); AnEnum return_enum (); } public class CConstrainedCalls : IConstrainedCalls { [MethodImplAttribute (MethodImplOptions.NoInlining)] public Pair vtype_ret(T t, T2 t2) where T : IReturnVType { return t.return_vtype (); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public AnEnum enum_ret(T t, T2 t2) where T : IReturnVType { return t.return_enum (); } } class ReturnVType : IReturnVType { public Pair return_vtype () { return new Pair () { First = 1, Second = 2 }; } public AnEnum return_enum () { return AnEnum.Two; } } public static int test_0_constrained_vtype_ret () { IConstrainedCalls c = new CConstrainedCalls (); var r = c.vtype_ret (new ReturnVType (), 1); if (r.First != 1 || r.Second != 2) return 1; return 0; } public static int test_0_constrained_enum_ret () { IConstrainedCalls c = new CConstrainedCalls (); var r = c.enum_ret (new ReturnVType (), 1); if (r != AnEnum.Two) return 1; return 0; } public struct Pair { public T1 First; public T2 Second; } [MethodImplAttribute (MethodImplOptions.NoInlining)] public static TState call_del(TState state, Func action) { return action(null, state); } [Category ("!FULLAOT")] public static int test_0_delegate_wrappers () { Func, Pair> del1 = delegate (object o, Pair p) { return p; }; Func, Pair> del2 = delegate (object o, Pair p) { return p; }; Func, Pair> del3 = delegate (object o, Pair p) { return p; }; var r1 = call_del> (new Pair { First = 1, Second = 2}, del1); if (r1.First != 1 || r1.Second != 2) return 1; var r2 = call_del> (new Pair { First = 3, Second = 4}, del2); if (r2.First != 3 || r2.Second != 4) return 2; var r3 = call_del> (new Pair { First = 1.0, Second = 2}, del3); if (r3.First != 1.0 || r3.Second != 2) return 3; return 0; } class Base { [MethodImplAttribute (MethodImplOptions.NoInlining)] public object foo (T1 t1, T t, object o) { return o; } } class AClass : Base { [MethodImplAttribute (MethodImplOptions.NoInlining)] public object bar (T t, long time, object o) { return foo (t, time, o); } } public static int test_0_out_in_wrappers () { var a = new AClass (); object o1 = "A"; object o2 = a.bar (1024, 0, o1); if (o1 != o2) return 1; return 0; } interface BIFace { object AMethod (); } class Base : BIFace { public TAbsolute Clock { get; set; } public virtual object AMethod () { return Clock; } } class BClass : Base { } public static int test_0_regress_1 () { BIFace c = new BClass (); object o = c.AMethod (); if (!(o is long) || ((long)o != 0)) return 1; return 0; } interface IFace3 { T unbox_any (object o); } class Class3 : IFace3 { public virtual T unbox_any (object o) { return (T)o; } } public static int test_0_unbox_any () { IFace3 o = new Class3 (); if (o.unbox_any (16) != 16) return 1; if (o.unbox_any ((long)32) != 32) return 2; if (o.unbox_any (2.0) != 2.0) return 3; try { o.unbox_any (2.0); return 4; } catch (Exception) { } return 0; } interface IFace4 { TSource Catch(TSource t) where TException : Exception; } class Class4 : IFace4 { [MethodImplAttribute (MethodImplOptions.NoInlining)] public TSource Catch(TSource t) where TException : Exception { return t; } } // Check that mixed instantiations are correctly created/found in AOT public static int test_0_constraints () { IFace4 o = new Class4 (); o.Catch (1); return 0; } internal static Type Process (TSource[] arr, Action call) { arr [0] = default (TSource); return typeof (TSource); } interface IFace5 { Type foo (); } class Class5 : IFace5 { public Type foo () { return Process, T> (new KeyValuePair [10], null); } } public static int test_0_rgctx_call_from_gshared_code () { var c = new Class5 (); if (c.foo () != typeof (KeyValuePair)) return 1; return 0; } public class Enumbers { public object Enumerate (List> alist) { return alist.ToArray (); } } public static int test_0_checkthis_gshared_call () { Enumbers e = new Enumbers (); try { e.Enumerate (null); return 1; } catch (NullReferenceException) { } return 0; } interface IFace6 { T[] Del (T t); } class Class6 : IFace6 { public T[] Del (T t) { var res = new T [5]; Func func = delegate(T t1, T t2, T t3, T t4) { res [0] = t1; res [1] = t2; res [2] = t3; res [3] = t4; return t1; }; var v = func.BeginInvoke(t, t, t, t, null, null); res [4] = func.EndInvoke (v); return res; } } // FIXME: The runtime-invoke wrapper used by BeginInvoke is not found [Category ("!FULLAOT")] public static int test_0_begin_end_invoke () { IFace6 o = new Class6 (); var arr1 = o.Del (1); if (arr1 [0] != 1 || arr1 [1] != 1 || arr1 [2] != 1 || arr1 [3] != 1 || arr1 [4] != 1) return 1; var arr2 = o.Del (2.0); if (arr2 [0] != 2.0 || arr2 [1] != 2.0 || arr2 [2] != 2.0 || arr2 [3] != 2.0 || arr2 [4] != 2.0) return 2; return 0; } public class TAbstractTableItem { [MethodImplAttribute (MethodImplOptions.NoInlining)] public static void SetProperty () { } [MethodImplAttribute (MethodImplOptions.NoInlining)] public static void Test () { SetProperty (); } } public static int test_0_gsharedvt_method_on_shared_class () { TAbstractTableItem.Test (); return 0; } interface IFaceBox { object box (T t); bool is_null (T t); } class ClassBox : IFaceBox { public object box (T t) { object o = t; return o; } public bool is_null (T t) { if (!(default(T) == null)) return false; return true; } } public static int test_0_nullable_box () { IFaceBox c = new ClassBox (); int i = 5; object o = c.box (i); if ((int)o != i) return 1; if (c.box (null) != null) return 2; long l = Int64.MaxValue - 1; o = c.box (l); if ((long)o != l) return 3; if (c.box (null) != null) return 4; string s = "A"; if (c.box (s) != (object)s) return 5; return 0; } public static int test_0_nullable_box_brtrue_opt () { IFaceBox c = new ClassBox (); if (c.is_null (null)) return 0; else return 1; } interface IFaceUnbox2 { T unbox (object o); } class ClassUnbox2 : IFaceUnbox2 { public T unbox (object o) { return (T)o; } } public static int test_0_nullable_unbox () { IFaceUnbox2 c = new ClassUnbox2 (); int? i = c.unbox (5); if (i != 5) return 1; int? j = c.unbox (null); if (j != null) return 2; return 0; } interface IConstrained { void foo (); void foo_ref_arg (string s); } interface IConstrained { void foo_gsharedvt_arg (T3 s); T3 foo_gsharedvt_ret (T3 s); } static object constrained_res; struct ConsStruct : IConstrained { public int i; public void foo () { constrained_res = i; } public void foo_ref_arg (string s) { constrained_res = s == "A" ? 42 : 0; } } class ConsClass : IConstrained { public int i; public void foo () { constrained_res = i; } public void foo_ref_arg (string s) { constrained_res = s == "A" ? 43 : 0; } } struct ConsStruct : IConstrained { public void foo_gsharedvt_arg (T s) { constrained_res = s; } public T foo_gsharedvt_ret (T s) { return s; } } struct ConsStructThrow : IConstrained { public void foo () { throw new Exception (); } public void foo_ref_arg (string s) { } } interface IFaceConstrained { void constrained_void_iface_call(T t, T2 t2) where T2 : IConstrained; void constrained_void_iface_call_ref_arg(T t, T2 t2) where T2 : IConstrained; void constrained_void_iface_call_gsharedvt_arg(T t, T2 t2, T3 t3) where T2 : IConstrained; T constrained_iface_call_gsharedvt_ret(T t, T2 t2, T3 t3) where T2 : IConstrained; T2 constrained_normal_call(T t, T2 t2) where T2 : VClass; } class ClassConstrained : IFaceConstrained { [MethodImplAttribute (MethodImplOptions.NoInlining)] public void constrained_void_iface_call(T t, T2 t2) where T2 : IConstrained { t2.foo (); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public void constrained_void_iface_call_ref_arg(T t, T2 t2) where T2 : IConstrained { t2.foo_ref_arg ("A"); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public void constrained_void_iface_call_gsharedvt_arg(T t, T2 t2, T3 t3) where T2 : IConstrained { t2.foo_gsharedvt_arg (t); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public T constrained_iface_call_gsharedvt_ret(T t, T2 t2, T3 t3) where T2 : IConstrained { return t2.foo_gsharedvt_ret (t); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public T2 constrained_normal_call(T t, T2 t2) where T2 : VClass { /* This becomes a constrained call even through 't2' is forced to be a reference type by the constraint */ return (T2)t2.foo (5); } } class VClass { public virtual VClass foo (int i) { return this; } } public static int test_0_constrained_void_iface_call () { IFaceConstrained c = new ClassConstrained (); var s = new ConsStruct () { i = 42 }; constrained_res = null; c.constrained_void_iface_call (1, s); if (!(constrained_res is int) || ((int)constrained_res) != 42) return 1; constrained_res = null; c.constrained_void_iface_call_ref_arg (1, s); if (!(constrained_res is int) || ((int)constrained_res) != 42) return 2; var s2 = new ConsClass () { i = 43 }; constrained_res = null; c.constrained_void_iface_call (1, s2); if (!(constrained_res is int) || ((int)constrained_res) != 43) return 3; constrained_res = null; c.constrained_void_iface_call_ref_arg (1, s2); if (!(constrained_res is int) || ((int)constrained_res) != 43) return 4; return 0; } public static int test_0_constrained_eh () { var s2 = new ConsStructThrow () { }; try { IFaceConstrained c = new ClassConstrained (); c.constrained_void_iface_call (1, s2); return 1; } catch (Exception) { return 0; } } public static int test_0_constrained_void_iface_call_gsharedvt_arg () { // This tests constrained calls through interfaces with one gsharedvt arg, like IComparable.CompareTo () IFaceConstrained c = new ClassConstrained (); var s = new ConsStruct (); constrained_res = null; c.constrained_void_iface_call_gsharedvt_arg, int> (42, s, 55); if (!(constrained_res is int) || ((int)constrained_res) != 42) return 1; var s2 = new ConsStruct (); constrained_res = null; c.constrained_void_iface_call_gsharedvt_arg, int> ("A", s2, 55); if (!(constrained_res is string) || ((string)constrained_res) != "A") return 2; return 0; } public static int test_0_constrained_iface_call_gsharedvt_ret () { IFaceConstrained c = new ClassConstrained (); var s = new ConsStruct (); int ires = c.constrained_iface_call_gsharedvt_ret, int> (42, s, 55); if (ires != 42) return 1; var s2 = new ConsStruct (); string sres = c.constrained_iface_call_gsharedvt_ret, int> ("A", s2, 55); if (sres != "A") return 2; return 0; } public static int test_0_constrained_normal_call () { IFaceConstrained c = new ClassConstrained (); var o = new VClass (); var res = c.constrained_normal_call (1, o); return res == o ? 0 : 1; } public static async Task FooAsync (int i, int j) { Task t = new Task (delegate () { return 42; }); var response = await t; return default(T); } [MethodImplAttribute (MethodImplOptions.NoInlining)] public static void call_async (int i, int j) { Task t = FooAsync (1, 2); // FIXME: This doesn't work //t.RunSynchronously (); } // In AOT mode, the async infrastructure depends on gsharedvt methods public static int test_0_async_call_from_generic () { call_async (1, 2); return 0; } public static int test_0_array_helper_gsharedvt () { var arr = new AnEnum [16]; var c = new ReadOnlyCollection (arr); return c.Contains (AnEnum.Two) == false ? 0 : 1; } interface IFaceCallPatching { bool caller (); } class CallPatching2 { T t; public object o; [MethodImplAttribute (MethodImplOptions.NoInlining)] public bool callee () { return (string)o == "ABC"; } } class CallPatching : IFaceCallPatching { public bool caller () { var c = new CallPatching2 (); c.o = "ABC"; return c.callee (); } } // // This tests that generic calls made from gsharedvt methods are not patched normally. // If they are, the first call to 'caller' would patch in the gshared version of // 'callee', causing the second call to fail because the gshared version of callee // wouldn't work with CallPatching2 since it has a different object layout. // public static int test_0_call_patching () { IFaceCallPatching c = new CallPatching (); c.caller (); if (!c.caller ()) return 1; return 0; } struct EmptyStruct { } public struct BStruct { public int a, b, c, d; } interface IFoo3 { int Bytes (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8); int SBytes (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, sbyte b1, sbyte b2, sbyte b3, sbyte b4); int Shorts (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, short b1, short b2, short b3, short b4); int UShorts (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, ushort b1, ushort b2, ushort b3, ushort b4); int Ints (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, int i1, int i2, int i3, int i4); int UInts (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, uint i1, uint i2, uint i3, uint i4); int Structs (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, BStruct s); void Generic (T t, T2[] arr, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, T2 i1, T2 i2, T2 i3, T2 i4); } class Foo3 : IFoo3 { public int Bytes (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8) { return b1 + b2 + b3 + b4 + b5 + b6 + b7 + b8; } public int SBytes (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, sbyte b1, sbyte b2, sbyte b3, sbyte b4) { return b1 + b2 + b3 + b4; } public int Shorts (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, short b1, short b2, short b3, short b4) { return b1 + b2 + b3 + b4; } public int UShorts (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, ushort b1, ushort b2, ushort b3, ushort b4) { return b1 + b2 + b3 + b4; } public int Ints (T t, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int i1, int i2, int i3, int i4) { return i1 + i2 + i3 + i4; } public int UInts (T t, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, uint i1, uint i2, uint i3, uint i4) { return (int)(i1 + i2 + i3 + i4); } public int Structs (T t, int dummy1, int a2, int a3, int a4, int a5, int a6, int a7, int dummy8, BStruct s) { return s.a + s.b + s.c + s.d; } public void Generic (T t, T2[] arr, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, T2 i1, T2 i2, T2 i3, T2 i4) { arr [0] = i1; arr [1] = i2; arr [2] = i3; arr [3] = i4; } } // Passing small normal arguments on the stack public static int test_0_arm64_small_stack_args () { IFoo3 o = (IFoo3)Activator.CreateInstance (typeof (Foo3<>).MakeGenericType (new Type [] { typeof (EmptyStruct) })); int res = o.Bytes (new EmptyStruct (), 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8); if (res != 36) return 1; int res2 = o.SBytes (new EmptyStruct (), 1, 2, 3, 4, 5, 6, 7, 8, -1, -2, -3, -4); if (res2 != -10) return 2; int res3 = o.Shorts (new EmptyStruct (), 1, 2, 3, 4, 5, 6, 7, 8, -1, -2, -3, -4); if (res3 != -10) return 3; int res4 = o.UShorts (new EmptyStruct (), 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4); if (res4 != 10) return 4; int res5 = o.Ints (new EmptyStruct (), 1, 2, 3, 4, 5, 6, 7, 8, -1, -2, -3, -4); if (res5 != -10) return 5; int res6 = o.UInts (new EmptyStruct (), 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4); if (res6 != 10) return 6; int[] arr = new int [4]; o.Generic (new EmptyStruct (), arr, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4); if (arr [0] != 1 || arr [1] != 2 || arr [2] != 3 || arr [3] != 4) return 7; return 0; } interface ISmallArg { T foo (string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8, string s9, string s10, string s11, string s12, string s13, T t); } class SmallArgClass : ISmallArg { public T foo (string s1, string s2, string s3, string s4, string s5, string s6, string s7, string s8, string s9, string s10, string s11, string s12, string s13, T t) { return t; } } public static int test_1_small_gsharedvt_stack_arg_ios () { ISmallArg o = new SmallArgClass (); return o.foo ("", "", "", "", "", "", "", "", "", "", "", "", "", 1); } // Passing vtype normal arguments on the stack public static int test_0_arm64_vtype_stack_args () { IFoo3 o = (IFoo3)Activator.CreateInstance (typeof (Foo3<>).MakeGenericType (new Type [] { typeof (EmptyStruct) })); int res = o.Structs (new EmptyStruct (), 1, 2, 3, 4, 5, 6, 7, 8, new BStruct () { a = 1, b = 2, c = 3, d = 4 }); if (res != 10) return 1; return 0; } interface IFoo4 { T Get(T[,] arr, T t); } class Foo4 : IFoo4 { public T Get(T[,] arr, T t) { arr [1, 1] = t; return arr [1, 1]; } } struct AStruct { public int a, b; } public static int test_0_multi_dim_arrays_2 () { IFoo4 foo = new Foo4 (); var arr = new int [10, 10]; int res = foo.Get (arr, 10); if (res != 10) return 1; IFoo4 foo2 = new Foo4 (); var arr2 = new AStruct [10, 10]; var res2 = foo2.Get (arr2, new AStruct () { a = 1, b = 2 }); if (res2.a != 1 || res2.b != 2) return 2; return 0; } public interface IFaceTest { int iface_method (); } public interface IFaceConstrainedIFace { int foo (ref T val) where T: IFaceTest; } class ConstrainedIFace : IFaceConstrainedIFace { public int foo (ref T val) where T: IFaceTest { return val.iface_method (); } } class ClassTest : IFaceTest { public int iface_method () { return 42; } } struct StructTest : IFaceTest { int i; public StructTest (int arg) { i = arg; } public int iface_method () { return i; } } // Test constrained calls on an interface made from gsharedvt methods public static int test_42_gsharedvt_constrained_iface () { IFaceConstrainedIFace obj = new ConstrainedIFace (); IFaceTest t = new ClassTest (); return obj.foo (ref t); } public static int test_42_gsharedvt_constrained_iface_vtype () { IFaceConstrainedIFace obj = new ConstrainedIFace (); IFaceTest t = new StructTest (42); return obj.foo (ref t); } // Sign extension tests // 0x55 == 85 == 01010101 // 0xAA == 170 == 10101010 // 0x5555 == 21845 == 0101010101010101 // 0xAAAA == 43690 == 1010101010101010 // 0x55555555 == 1431655765 // 0xAAAAAAAA == 2863311530 // 0x5555555555555555 == 6148914691236517205 // 0xAAAAAAAAAAAAAAAA == 12297829382473034410 public interface SEFace { T Copy (int a, int b, int c, int d, T t); } class SEClass : SEFace { public T Copy (int a, int b, int c, int d, T t) { return t; } } // Test extension static int test_20_signextension_sbyte () { Type t = typeof (sbyte); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; long zz = i.Copy (1,2,3,4,(sbyte)(-0x55)); bool success = zz == -0x55; return success ? 20 : 1; } static int test_20_signextension_byte () { Type t = typeof (byte); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; ulong zz = i.Copy (1,2,3,4,(byte)(0xAA)); bool success = zz == 0xAA; return success ? 20 : 1; } static int test_20_signextension_short () { Type t = typeof (short); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; long zz = i.Copy (1,2,3,4,(short)(-0x5555)); bool success = zz == -0x5555; return success ? 20 : 1; } static int test_20_signextension_ushort () { Type t = typeof (ushort); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; ulong zz = i.Copy (1,2,3,4,(ushort)(0xAAAA)); bool success = zz == 0xAAAA; return success ? 20 : 1; } static int test_20_signextension_int () { Type t = typeof (int); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; long zz = i.Copy (1,2,3,4,(int)(-0x55555555)); bool success = zz == -0x55555555; return success ? 20 : 1; } static int test_20_signextension_uint () { Type t = typeof (uint); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; ulong zz = i.Copy (1,2,3,4,(uint)(0xAAAAAAAA)); bool success = zz == 0xAAAAAAAA; return success ? 20 : 1; } static int test_20_signextension_long () { Type t = typeof (long); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; long zz = i.Copy (1,2,3,4,(long)(-0x5555555555555555)); bool success = zz == -0x5555555555555555; return success ? 20 : 1; } static int test_20_signextension_ulong () { Type t = typeof (ulong); object o = Activator.CreateInstance (typeof (SEClass<>).MakeGenericType (new Type[] { t })); var i = (SEFace)o; ulong zz = i.Copy (1,2,3,4,(ulong)(0xAAAAAAAAAAAAAAAA)); bool success = zz == 0xAAAAAAAAAAAAAAAA; return success ? 20 : 1; } void gsharedvt_try_at_offset_0 (ref T disposable) where T : class, IDisposable { try { disposable.Dispose (); } finally { disposable = null; } } [MethodImplAttribute (MethodImplOptions.NoInlining)] static DateTimeOffset gsharedvt_vphi_inner (T t) { return DateTimeOffset.MinValue; } static DateTimeOffset gsharedvt_vphi (T t) { int[] arr = new int [10]; try { DateTimeOffset v; if (arr [0] == 0) v = gsharedvt_vphi_inner (t); else v = gsharedvt_vphi_inner (t); return v; } catch { return DateTimeOffset.MinValue; } } static int test_0_gsharedvt_vphi_volatile () { gsharedvt_vphi (0); return 0; } struct AStruct3 { T1 t1; T2 t2; T3 t3; } interface IFaceIsRef { bool is_ref (); } class ClassIsRef : IFaceIsRef { [MethodImplAttribute (MethodImplOptions.NoInlining)] public bool is_ref () { return RuntimeHelpers.IsReferenceOrContainsReferences (); } } public static int test_0_isreference_intrins () { IFaceIsRef iface = new ClassIsRef (); if (iface.is_ref> ()) return 1; if (!iface.is_ref> ()) return 2; return 0; } } // #13191 public class MobileServiceCollection { public async Task LoadMoreItemsAsync(int count = 0) { await Task.Delay (1000); int results = await ProcessQueryAsync (); return results; } protected async virtual Task ProcessQueryAsync() { await Task.Delay (1000); throw new Exception (); } } #if !__MOBILE__ public class GSharedTests : Tests { } #endif