4 using System.Reflection;
5 using System.Runtime.InteropServices;
6 using System.Runtime.CompilerServices;
7 using System.Collections.Generic;
8 using System.Collections.ObjectModel;
11 * Regression tests for the AOT/FULL-AOT code.
21 static int Main (String[] args) {
22 return TestDriver.RunTests (typeof (Tests), args);
26 public delegate void ArrayDelegate (int[,] arr);
28 static int test_0_array_delegate_full_aot () {
29 ArrayDelegate d = delegate (int[,] arr) {
31 int[,] a = new int[5, 6];
32 d.BeginInvoke (a, null, null);
45 /* The 'd' argument is used to shift the register indexes so 't' doesn't start at the first reg */
46 public static T Get_T (double d, T t) {
52 public static T Get_T (double d, T t) {
55 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) {
61 public static T Get_T (double d, T t) {
62 return Foo2<T>.Get_T (d, t);
66 [Category ("DYNCALL")]
67 static int test_0_arm64_dyncall_double () {
70 var res = (double)typeof (Foo<double>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
76 [Category ("DYNCALL")]
77 static int test_0_arm64_dyncall_float () {
80 var res = (float)typeof (Foo<float>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
86 [Category ("DYNCALL")]
87 static int test_0_arm64_dyncall_hfa_double () {
89 // HFA with double members
90 var s = new Struct1 ();
93 var s_res = (Struct1)typeof (Foo<Struct1>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
94 if (s_res.a != 1.0f || s_res.b != 2.0f)
99 [Category ("DYNCALL")]
100 static int test_0_arm64_dyncall_hfa_float () {
102 var s = new Struct2 ();
105 var s_res = (Struct2)typeof (Foo<Struct2>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
106 if (s_res.a != 1.0f || s_res.b != 2.0f)
111 [Category ("DYNCALL")]
112 [Category ("GSHAREDVT")]
113 static int test_0_arm64_dyncall_gsharedvt_out_hfa_double () {
114 /* gsharedvt out trampoline with double hfa argument */
117 var s = new Struct1 ();
120 // Call Foo2.Get_T directly, so its gets an instance
121 Foo2<Struct1>.Get_T (arg1, s);
122 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct1) });
123 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
124 var s_res = (Struct1)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
125 if (s_res.a != 1.0f || s_res.b != 2.0f)
130 [Category ("DYNCALL")]
131 [Category ("GSHAREDVT")]
132 static int test_0_arm64_dyncall_gsharedvt_out_hfa_float () {
133 /* gsharedvt out trampoline with double hfa argument */
136 var s = new Struct2 ();
139 // Call Foo2.Get_T directly, so its gets an instance
140 Foo2<Struct2>.Get_T (arg1, s);
141 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct2) });
142 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
143 var s_res = (Struct2)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
144 if (s_res.a != 1.0f || s_res.b != 2.0f)
149 interface IFaceFoo4<T> {
150 T Get_T (double d, T t);
151 T Get_T2 (double d, T t);
154 class Foo4<T> : IFaceFoo4<T> {
155 public T Get_T (double d, T t) {
156 return Foo2<T>.Get_T (d, t);
158 public T Get_T2 (double d, T t) {
159 return Foo2<T>.Get_T2 (d, 1, 2, 3, 4, 5, 6, 7, 8, t);
163 struct VTypeByRefStruct {
164 public long o1, o2, o3;
167 [Category ("GSHAREDVT")]
168 public static int test_0_arm64_gsharedvt_out_vtypebyref () {
169 /* gsharedvt out trampoline with vtypebyref argument */
170 var s = new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 };
172 // Call Foo2.Get_T directly, so its gets an instance
173 Foo2<VTypeByRefStruct>.Get_T (1.0f, s);
174 var o = (IFaceFoo4<VTypeByRefStruct>)Activator.CreateInstance (typeof (Foo4<>).MakeGenericType (new Type [] { typeof (VTypeByRefStruct) }));
175 // Call Foo4.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
176 var s_res = o.Get_T (1.0f, s);
177 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
179 // Same with the byref argument passed on the stack
180 s_res = o.Get_T2 (1.0f, s);
181 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
187 public static T Get_T (object o) {
192 [Category ("DYNCALL")]
193 static int test_0_arm64_dyncall_vtypebyref_ret () {
194 var s = new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 };
195 Type t = typeof (Foo5<>).MakeGenericType (new Type [] { typeof (VTypeByRefStruct) });
196 var o = Activator.CreateInstance (t);
198 var s_res = (VTypeByRefStruct)t.GetMethod ("Get_T").Invoke (o, new object [] { s });
199 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
201 } catch (TargetInvocationException) {
208 public T reg_stack_split_inner<T> (int i, int j, T l) {
213 [Category("DYNCALL")]
214 static int test_0_arm_dyncall_reg_stack_split () {
215 var m = typeof (Foo6).GetMethod ("reg_stack_split_inner").MakeGenericMethod (new Type[] { typeof (long) });
217 if ((long)m.Invoke (o, new object [] { 1, 2, 3 }) != 3)
219 if ((long)m.Invoke (o, new object [] { 1, 2, Int64.MaxValue }) != Int64.MaxValue)
224 static int test_0_partial_sharing_regress_30204 () {
225 var t = typeof (System.Collections.Generic.Comparer<System.Collections.Generic.KeyValuePair<string, string>>);
226 var d = new SortedDictionary<string, string> ();
227 d.Add ("key1", "banana");
228 return d ["key1"] == "banana" ? 0 : 1;
231 class NullableMethods {
232 [MethodImplAttribute (MethodImplOptions.NoInlining)]
233 public static bool GetHasValue<T>(Nullable<T> value) where T : struct {
234 return value.HasValue;
237 [MethodImplAttribute (MethodImplOptions.NoInlining)]
238 public static T GetValue<T>(Nullable<T> value) where T : struct {
242 [MethodImplAttribute (MethodImplOptions.NoInlining)]
243 public static Nullable<T> Get<T>(T t) where T : struct {
247 [MethodImplAttribute (MethodImplOptions.NoInlining)]
248 public static Nullable<T> GetNull<T>() where T : struct {
253 [Category ("DYNCALL")]
254 public static int test_0_dyncall_nullable () {
258 NullableMethods.GetHasValue (v);
259 bool b = (bool)typeof (NullableMethods).GetMethod ("GetHasValue").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { v });
263 b = (bool)typeof (NullableMethods).GetMethod ("GetHasValue").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { v });
268 NullableMethods.GetValue (v);
269 var res = (int)typeof (NullableMethods).GetMethod ("GetValue").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { v });
273 NullableMethods.Get (42);
274 var res2 = (int?)typeof (NullableMethods).GetMethod ("Get").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { 42 });
277 res2 = (int?)typeof (NullableMethods).GetMethod ("GetNull").MakeGenericMethod (new Type [] { typeof (int) }).Invoke (null, new object [] { });
288 public static int test_0_enum_eq_comparer () {
289 var c = EqualityComparer<AnEnum>.Default;
290 return (!c.Equals (AnEnum.A, AnEnum.B) && c.Equals (AnEnum.A, AnEnum.A)) ? 0 : 1;
293 public static int test_0_enum_comparer () {
294 var c = Comparer<AnEnum>.Default;
295 return c.Compare (AnEnum.A, AnEnum.A);
298 private static Dictionary<long, TValue> ConvertDictionary<TValue>(Dictionary<long, IList<TValue>> source) {
299 return source.ToDictionary(pair => pair.Key, pair => pair.Value[0]);
302 [Category ("GSHAREDVT")]
303 public static int test_0_gsharedvt_non_variable_arg () {
304 Dictionary<long, IList<int>> data = new Dictionary<long, IList<int>>
306 {123L, new List<int> {2}}
308 Dictionary<long, int> newDict = ConvertDictionary(data);
309 if (newDict.Count != 1)
314 enum LongEnum : ulong {
318 public static int test_0_long_enum_eq_comparer () {
319 var c = EqualityComparer<LongEnum>.Default;
320 c.GetHashCode (LongEnum.A);
324 enum UInt32Enum : uint {
328 enum Int32Enum : int {
332 enum Int16Enum : short {
336 enum UInt16Enum : ushort {
340 enum Int8Enum : sbyte {
344 enum UInt8Enum : byte {
348 public static int test_0_int_enum_eq_comparer () {
349 var t1 = new Dictionary<Int32Enum, object> ();
350 t1 [Int32Enum.A] = "foo";
352 var t2 = new Dictionary<UInt32Enum, object> ();
353 t2 [UInt32Enum.A] = "foo";
355 var t3 = new Dictionary<UInt16Enum, object> ();
356 t3 [UInt16Enum.A] = "foo";
358 var t4 = new Dictionary<Int16Enum, object> ();
359 t4 [Int16Enum.A] = "foo";
361 var t5 = new Dictionary<Int8Enum, object> ();
362 t5 [Int8Enum.A] = "foo";
364 var t6 = new Dictionary<UInt8Enum, object> ();
365 t6 [UInt8Enum.A] = "foo";
370 public static int test_0_array_accessor_runtime_invoke_ref () {
371 var t = typeof (string[]);
372 var arr = Array.CreateInstance (typeof (string), 1);
373 arr.GetType ().GetMethod ("Set").Invoke (arr, new object [] { 0, "A" });
374 var res = (string)arr.GetType ().GetMethod ("Get").Invoke (arr, new object [] { 0 });
380 public static void SetArrayValue_<T> (T[] values) {
381 values.Select (x => x).ToArray ();
384 [Category ("GSHAREDVT")]
385 public static int test_0_delegate_invoke_wrappers_gsharedvt () {
386 var enums = new LongEnum [] { LongEnum.A };
387 SetArrayValue_ (enums);
392 public int a, b, c, d;
395 [MethodImplAttribute (MethodImplOptions.NoInlining)]
396 public static bool GetHasValue<T>(T? value) where T : struct
398 return value.HasValue;
401 [Category ("DYNCALL")]
402 public static int test_0_large_nullable_invoke () {
403 var s = new LargeStruct () { a = 1, b = 2, c = 3, d = 4 };
405 GetHasValue<LargeStruct> (s);
408 var m = typeof(AotTests).GetMethod("GetHasValue", BindingFlags.Static | BindingFlags.Public);
410 var m = typeof(Tests).GetMethod("GetHasValue", BindingFlags.Static | BindingFlags.Public);
413 Type type = typeof (LargeStruct?).GetGenericArguments () [0];
414 bool b1 = (bool)m.MakeGenericMethod (new Type[] {type}).Invoke (null, new object[] { s });
417 bool b2 = (bool)m.MakeGenericMethod (new Type[] {type}).Invoke (null, new object[] { null });
424 public float a, b, c;
427 struct LargeStruct2 {
429 public int a, b, c, d, e, f, g, h;
432 [MethodImplAttribute (MethodImplOptions.NoInlining)]
433 static int pass_hfa_on_stack (FpStruct s1, FpStruct s2, FpStruct s3) {
437 public static int test_10_arm64_hfa_on_stack_llvm () {
438 var arr = new LargeStruct2 [10, 10];
439 for (int i = 0; i < 10; ++i)
440 for (int j = 0; j < 10; ++j)
441 arr [i, j].x = new FpStruct ();
443 var s1 = new FpStruct () { a = 1, b = 1, c = 10 };
444 return pass_hfa_on_stack (s1, s1, s1);
447 public static int test_0_get_current_method () {
448 var m = MethodBase.GetCurrentMethod ();
450 var m2 = typeof (AotTests).GetMethod ("test_0_get_current_method");
452 var m2 = typeof (Tests).GetMethod ("test_0_get_current_method");
454 return m == m2 ? 0 : 1;
457 class GetCurrentMethodClass<T> {
458 [MethodImplAttribute (MethodImplOptions.NoInlining)]
459 public MethodBase get_current () {
460 return MethodBase.GetCurrentMethod ();
464 public static int test_0_get_current_method_generic () {
465 var c = new GetCurrentMethodClass<string> ();
466 var m = c.get_current ();
467 var m2 = typeof (GetCurrentMethodClass<>).GetMethod ("get_current");
468 return m == m2 ? 0 : 1;
471 public static int test_0_array_wrappers_runtime_invoke () {
472 string[][] arr = new string [10][];
473 IEnumerable<string[]> iface = arr;
474 var m = typeof(IEnumerable<string[]>).GetMethod ("GetEnumerator");
475 m.Invoke (arr, null);