4 using System.Reflection;
5 using System.Runtime.InteropServices;
6 using System.Runtime.CompilerServices;
7 using System.Collections.Generic;
10 * Regression tests for the AOT/FULL-AOT code.
20 static int Main (String[] args) {
21 return TestDriver.RunTests (typeof (Tests), args);
25 public delegate void ArrayDelegate (int[,] arr);
27 static int test_0_array_delegate_full_aot () {
28 ArrayDelegate d = delegate (int[,] arr) {
30 int[,] a = new int[5, 6];
31 d.BeginInvoke (a, null, null);
44 /* The 'd' argument is used to shift the register indexes so 't' doesn't start at the first reg */
45 public static T Get_T (double d, T t) {
51 public static T Get_T (double d, T t) {
54 public static T Get_T2 (double d, int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, T t) {
60 public static T Get_T (double d, T t) {
61 return Foo2<T>.Get_T (d, t);
65 [Category ("DYNCALL")]
66 static int test_0_arm64_dyncall_double () {
69 var res = (double)typeof (Foo<double>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
75 [Category ("DYNCALL")]
76 static int test_0_arm64_dyncall_float () {
79 var res = (float)typeof (Foo<float>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
85 [Category ("DYNCALL")]
86 static int test_0_arm64_dyncall_hfa_double () {
88 // HFA with double members
89 var s = new Struct1 ();
92 var s_res = (Struct1)typeof (Foo<Struct1>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
93 if (s_res.a != 1.0f || s_res.b != 2.0f)
98 [Category ("DYNCALL")]
99 static int test_0_arm64_dyncall_hfa_float () {
101 var s = new Struct2 ();
104 var s_res = (Struct2)typeof (Foo<Struct2>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
105 if (s_res.a != 1.0f || s_res.b != 2.0f)
110 [Category ("DYNCALL")]
111 [Category ("GSHAREDVT")]
112 static int test_0_arm64_dyncall_gsharedvt_out_hfa_double () {
113 /* gsharedvt out trampoline with double hfa argument */
116 var s = new Struct1 ();
119 // Call Foo2.Get_T directly, so its gets an instance
120 Foo2<Struct1>.Get_T (arg1, s);
121 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct1) });
122 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
123 var s_res = (Struct1)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
124 if (s_res.a != 1.0f || s_res.b != 2.0f)
129 [Category ("DYNCALL")]
130 [Category ("GSHAREDVT")]
131 static int test_0_arm64_dyncall_gsharedvt_out_hfa_float () {
132 /* gsharedvt out trampoline with double hfa argument */
135 var s = new Struct2 ();
138 // Call Foo2.Get_T directly, so its gets an instance
139 Foo2<Struct2>.Get_T (arg1, s);
140 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct2) });
141 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
142 var s_res = (Struct2)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
143 if (s_res.a != 1.0f || s_res.b != 2.0f)
148 interface IFaceFoo4<T> {
149 T Get_T (double d, T t);
150 T Get_T2 (double d, T t);
153 class Foo4<T> : IFaceFoo4<T> {
154 public T Get_T (double d, T t) {
155 return Foo2<T>.Get_T (d, t);
157 public T Get_T2 (double d, T t) {
158 return Foo2<T>.Get_T2 (d, 1, 2, 3, 4, 5, 6, 7, 8, t);
162 struct VTypeByRefStruct {
163 public long o1, o2, o3;
166 [Category ("GSHAREDVT")]
167 public static int test_0_arm64_gsharedvt_out_vtypebyref () {
168 /* gsharedvt out trampoline with vtypebyref argument */
169 var s = new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 };
171 // Call Foo2.Get_T directly, so its gets an instance
172 Foo2<VTypeByRefStruct>.Get_T (1.0f, s);
173 var o = (IFaceFoo4<VTypeByRefStruct>)Activator.CreateInstance (typeof (Foo4<>).MakeGenericType (new Type [] { typeof (VTypeByRefStruct) }));
174 // Call Foo4.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
175 var s_res = o.Get_T (1.0f, s);
176 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
178 // Same with the byref argument passed on the stack
179 s_res = o.Get_T2 (1.0f, s);
180 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
186 public static T Get_T (object o) {
191 [Category ("DYNCALL")]
192 static int test_0_arm64_dyncall_vtypebyref_ret () {
193 var s = new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 };
194 Type t = typeof (Foo5<>).MakeGenericType (new Type [] { typeof (VTypeByRefStruct) });
195 var o = Activator.CreateInstance (t);
197 var s_res = (VTypeByRefStruct)t.GetMethod ("Get_T").Invoke (o, new object [] { s });
198 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
200 } catch (TargetInvocationException) {
207 public T reg_stack_split_inner<T> (int i, int j, T l) {
212 [Category("DYNCALL")]
213 static int test_0_arm_dyncall_reg_stack_split () {
214 var m = typeof (Foo6).GetMethod ("reg_stack_split_inner").MakeGenericMethod (new Type[] { typeof (long) });
216 if ((long)m.Invoke (o, new object [] { 1, 2, 3 }) != 3)
218 if ((long)m.Invoke (o, new object [] { 1, 2, Int64.MaxValue }) != Int64.MaxValue)
223 static int test_0_partial_sharing_regress_30204 () {
224 var t = typeof (System.Collections.Generic.Comparer<System.Collections.Generic.KeyValuePair<string, string>>);
225 var d = new SortedDictionary<string, string> ();
226 d.Add ("key1", "banana");
227 return d ["key1"] == "banana" ? 0 : 1;
230 class NullableMethods {
231 [MethodImplAttribute (MethodImplOptions.NoInlining)]
232 public static bool GetHasValue<T>(Nullable<T> value) where T : struct {
233 return value.HasValue;
236 [MethodImplAttribute (MethodImplOptions.NoInlining)]
237 public static T GetValue<T>(Nullable<T> value) where T : struct {
242 [Category ("DYNCALL")]
243 public static int test_0_dyncall_nullable () {
247 NullableMethods.GetHasValue (v);
248 bool b = (bool)typeof (NullableMethods).GetMethod ("GetHasValue").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { v });
252 b = (bool)typeof (NullableMethods).GetMethod ("GetHasValue").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { v });
257 NullableMethods.GetValue (v);
258 var res = (int)typeof (NullableMethods).GetMethod ("GetValue").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { v });
269 public static int test_0_enum_eq_comparer () {
270 var c = EqualityComparer<AnEnum>.Default;
271 return (!c.Equals (AnEnum.A, AnEnum.B) && c.Equals (AnEnum.A, AnEnum.A)) ? 0 : 1;
274 public static int test_0_enum_comparer () {
275 var c = Comparer<AnEnum>.Default;
276 return c.Compare (AnEnum.A, AnEnum.A);
279 private static Dictionary<long, TValue> ConvertDictionary<TValue>(Dictionary<long, IList<TValue>> source) {
280 return source.ToDictionary(pair => pair.Key, pair => pair.Value[0]);
283 [Category ("GSHAREDVT")]
284 public static int test_0_gsharedvt_non_variable_arg () {
285 Dictionary<long, IList<int>> data = new Dictionary<long, IList<int>>
287 {123L, new List<int> {2}}
289 Dictionary<long, int> newDict = ConvertDictionary(data);
290 if (newDict.Count != 1)