4 using System
.Reflection
;
5 using System
.Runtime
.InteropServices
;
6 using System
.Runtime
.CompilerServices
;
7 using System
.Collections
;
8 using System
.Collections
.Generic
;
9 using System
.Collections
.ObjectModel
;
12 * Regression tests for the AOT/FULL-AOT code.
22 static int Main (String
[] args
) {
23 return TestDriver
.RunTests (typeof (Tests
), args
);
27 public delegate void ArrayDelegate (int[,] arr
);
29 [Category ("!WASM")] //Requires a working threadpool
30 static int test_0_array_delegate_full_aot () {
31 ArrayDelegate d
= delegate (int[,] arr
) {
33 int[,] a
= new int[5, 6];
34 d
.BeginInvoke (a
, null, null);
47 /* The 'd' argument is used to shift the register indexes so 't' doesn't start at the first reg */
48 public static T
Get_T (double d
, T t
) {
54 public static T
Get_T (double d
, T t
) {
57 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_T3 (double d
, int i
, T t
) {
63 public static T
Get_T4 (int i
, double d
, T t
)
70 public static T
Get_T (double d
, T t
) {
71 return Foo2
<T
>.Get_T (d
, t
);
75 [Category ("DYNCALL")]
76 static int test_0_arm64_dyncall_double () {
79 var res
= (double)typeof (Foo
<double>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s }
);
85 [Category ("DYNCALL")]
86 static int test_0_arm64_dyncall_float () {
89 var res
= (float)typeof (Foo
<float>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s }
);
95 [Category ("DYNCALL")]
96 static int test_0_amd64_dyncall_double_int_double ()
101 var res
= (double)typeof (Foo2
<double>).GetMethod ("Get_T3").Invoke (null, new object [] { arg1, arg2, s }
);
107 [Category ("DYNCALL")]
108 static int test_0_amd64_dyncall_double_int_float ()
113 var res
= (float)typeof (Foo2
<float>).GetMethod ("Get_T3").Invoke (null, new object [] { arg1, arg2, s }
);
119 [Category ("DYNCALL")]
120 static int test_0_amd64_dyncall_int_double_int ()
125 var res
= (int)typeof (Foo2
<int>).GetMethod ("Get_T4").Invoke (null, new object [] { arg1, arg2, s }
);
131 [Category ("DYNCALL")]
132 static int test_0_amd64_dyncall_int_double_ref ()
136 object s
= new object ();
137 var res
= (object)typeof (Foo2
<object>).GetMethod ("Get_T4").Invoke (null, new object [] { arg1, arg2, s }
);
143 [Category ("DYNCALL")]
144 static int test_0_arm64_dyncall_hfa_double () {
146 // HFA with double members
147 var s
= new Struct1 ();
150 var s_res
= (Struct1
)typeof (Foo
<Struct1
>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s }
);
151 if (s_res
.a
!= 1.0f
|| s_res
.b
!= 2.0f
)
156 [Category ("DYNCALL")]
157 static int test_0_arm64_dyncall_hfa_float () {
159 var s
= new Struct2 ();
162 var s_res
= (Struct2
)typeof (Foo
<Struct2
>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s }
);
163 if (s_res
.a
!= 1.0f
|| s_res
.b
!= 2.0f
)
168 [Category ("DYNCALL")]
169 static int test_0_amd64_dyncall_use_stack_float ()
172 var res
= (float)typeof (Foo2
<float>).GetMethod ("Get_T2").Invoke (null, new object [] { 1.0f, 2, 3, 4, 5, 6, 7, 8, 9, s }
);
178 [Category ("DYNCALL")]
179 static int test_0_amd64_dyncall_use_stack_double ()
182 var res
= (double)typeof (Foo2
<double>).GetMethod ("Get_T2").Invoke (null, new object [] { 1.0f, 2, 3, 4, 5, 6, 7, 8, 9, s }
);
188 [Category ("DYNCALL")]
189 static int test_0_amd64_dyncall_use_stack_int ()
192 var res
= (int)typeof (Foo2
<int>).GetMethod ("Get_T2").Invoke (null, new object [] { 1.0f, 2, 3, 4, 5, 6, 7, 8, 9, s }
);
198 [Category ("DYNCALL")]
199 static int test_0_amd64_dyncall_use_stack_ref ()
201 object s
= new object ();
202 var res
= (object)typeof (Foo2
<object>).GetMethod ("Get_T2").Invoke (null, new object [] { 1.0f, 2, 3, 4, 5, 6, 7, 8, 9, s }
);
208 [Category ("DYNCALL")]
209 static int test_0_amd64_dyncall_use_stack_struct ()
211 Struct1 s
= new Struct1 ();
214 var res
= (Struct1
)typeof (Foo2
<Struct1
>).GetMethod ("Get_T2").Invoke (null, new object [] { 1.0f, 2, 3, 4, 5, 6, 7, 8, 9, s }
);
215 if (res
.a
!= s
.a
|| res
.b
!= s
.b
)
220 [Category ("DYNCALL")]
221 [Category ("GSHAREDVT")]
222 static int test_0_arm64_dyncall_gsharedvt_out_hfa_double () {
223 /* gsharedvt out trampoline with double hfa argument */
226 var s
= new Struct1 ();
229 // Call Foo2.Get_T directly, so its gets an instance
230 Foo2
<Struct1
>.Get_T (arg1
, s
);
231 Type t
= typeof (Foo3
<>).MakeGenericType (new Type
[] { typeof (Struct1) }
);
232 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
233 var s_res
= (Struct1
)t
.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s }
);
234 if (s_res
.a
!= 1.0f
|| s_res
.b
!= 2.0f
)
239 [Category ("DYNCALL")]
240 [Category ("GSHAREDVT")]
241 static int test_0_arm64_dyncall_gsharedvt_out_hfa_float () {
242 /* gsharedvt out trampoline with double hfa argument */
245 var s
= new Struct2 ();
248 // Call Foo2.Get_T directly, so its gets an instance
249 Foo2
<Struct2
>.Get_T (arg1
, s
);
250 Type t
= typeof (Foo3
<>).MakeGenericType (new Type
[] { typeof (Struct2) }
);
251 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
252 var s_res
= (Struct2
)t
.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s }
);
253 if (s_res
.a
!= 1.0f
|| s_res
.b
!= 2.0f
)
258 interface IFaceFoo4
<T
> {
259 T
Get_T (double d
, T t
);
260 T
Get_T2 (double d
, T t
);
263 class Foo4
<T
> : IFaceFoo4
<T
> {
264 public T
Get_T (double d
, T t
) {
265 return Foo2
<T
>.Get_T (d
, t
);
267 public T
Get_T2 (double d
, T t
) {
268 return Foo2
<T
>.Get_T2 (d
, 1, 2, 3, 4, 5, 6, 7, 8, t
);
272 struct VTypeByRefStruct
{
273 public long o1
, o2
, o3
;
276 [Category ("GSHAREDVT")]
277 public static int test_0_arm64_gsharedvt_out_vtypebyref () {
278 /* gsharedvt out trampoline with vtypebyref argument */
279 var s
= new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 }
;
281 // Call Foo2.Get_T directly, so its gets an instance
282 Foo2
<VTypeByRefStruct
>.Get_T (1.0f
, s
);
283 var o
= (IFaceFoo4
<VTypeByRefStruct
>)Activator
.CreateInstance (typeof (Foo4
<>).MakeGenericType (new Type
[] { typeof (VTypeByRefStruct) }
));
284 // Call Foo4.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
285 var s_res
= o
.Get_T (1.0f
, s
);
286 if (s_res
.o1
!= 1 || s_res
.o2
!= 2 || s_res
.o3
!= 3)
288 // Same with the byref argument passed on the stack
289 s_res
= o
.Get_T2 (1.0f
, s
);
290 if (s_res
.o1
!= 1 || s_res
.o2
!= 2 || s_res
.o3
!= 3)
296 public static T
Get_T (object o
) {
300 public static long vtype_by_val
<T1
, T2
, T3
, T4
, T5
> (T1 t1
, T2 t2
, T3 t3
, T4 t4
, long? t5
) {
305 [Category ("DYNCALL")]
306 [Category ("GSHAREDVT")]
307 static int test_0_arm64_dyncall_vtypebyref_ret () {
308 var s
= new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 }
;
309 Type t
= typeof (Foo5
<>).MakeGenericType (new Type
[] { typeof (VTypeByRefStruct) }
);
310 var o
= Activator
.CreateInstance (t
);
312 var s_res
= (VTypeByRefStruct
)t
.GetMethod ("Get_T").Invoke (o
, new object [] { s }
);
313 if (s_res
.o1
!= 1 || s_res
.o2
!= 2 || s_res
.o3
!= 3)
315 } catch (TargetInvocationException
) {
321 [Category ("DYNCALL")]
322 [Category ("GSHAREDVT")]
323 static int test_42_arm64_dyncall_vtypebyval () {
324 var method
= typeof (Foo5
<string>).GetMethod ("vtype_by_val").MakeGenericMethod (new Type
[] { typeof (int), typeof (long?), typeof (long?), typeof (long?), typeof (long?) }
);
325 long res
= (long)method
.Invoke (null, new object [] { 1, 2L, 3L, 4L, 42L }
);
334 public static string vtypeonstack_align (string s1
, string s2
, string s3
, string s4
, string s5
, string s6
, string s7
, string s8
, bool b
, Struct7 s
) {
339 [Category ("DYNCALL")]
340 static int test_0_arm64_ios_dyncall_vtypeonstack_align () {
341 var m
= typeof (Foo7
).GetMethod ("vtypeonstack_align");
343 string s
= (string)m
.Invoke (null, new object [] { null, null, null, null, null, null, null, null, true, new Struct7 () { value = "ABC" }
});
344 return s
== "ABC" ? 0 : 1;
348 public T reg_stack_split_inner
<T
> (int i
, int j
, T l
) {
353 [Category ("DYNCALL")]
354 [Category ("GSHAREDVT")]
355 static int test_0_arm_dyncall_reg_stack_split () {
356 var m
= typeof (Foo6
).GetMethod ("reg_stack_split_inner").MakeGenericMethod (new Type
[] { typeof (long) }
);
358 if ((long)m
.Invoke (o
, new object [] { 1, 2, 3 }
) != 3)
360 if ((long)m
.Invoke (o
, new object [] { 1, 2, Int64.MaxValue }
) != Int64
.MaxValue
)
365 static int test_0_partial_sharing_regress_30204 () {
366 var t
= typeof (System
.Collections
.Generic
.Comparer
<System
.Collections
.Generic
.KeyValuePair
<string, string>>);
367 var d
= new SortedDictionary
<string, string> ();
368 d
.Add ("key1", "banana");
369 return d
["key1"] == "banana" ? 0 : 1;
372 class NullableMethods
{
373 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
374 public static bool GetHasValue
<T
>(Nullable
<T
> value) where T
: struct {
375 return value.HasValue
;
378 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
379 public static T GetValue
<T
>(Nullable
<T
> value) where T
: struct {
383 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
384 public static Nullable
<T
> Get
<T
>(T t
) where T
: struct {
388 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
389 public static int NullableMany(long? i1
, long? i2
, long? i3
, long? i4
, long? i5
, long? i6
, long? i7
, long? i8
,
390 long? i11
, long? i12
, long? i13
, long? i14
, long? i15
, long? i16
, long? i17
, long? i18
,
391 long? i21
, long? i22
, long? i23
, long? i24
, long? i25
, long? i26
, long? i27
, long? i28
,
392 long? i31
, long? i32
, long? i33
, long? i34
, long? i35
, long? i36
, long? i37
, long? i38
) {
393 return (int)((i1
+ i8
+ i11
+ i18
+ i21
+ i28
+ i31
+ i38
).Value
);
396 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
397 public static Nullable
<T
> GetNull
<T
>() where T
: struct {
401 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
402 public static bool GetHasValueManyArgs
<T
>(int i1
, int i2
, int i3
, int i4
, int i5
, int i6
, int i7
, int i8
, T
? value) where T
: struct
404 return value.HasValue
;
408 [Category ("DYNCALL")]
409 public static int test_0_dyncall_nullable () {
413 NullableMethods
.GetHasValue (v
);
414 bool b
= (bool)typeof (NullableMethods
).GetMethod ("GetHasValue").MakeGenericMethod (new Type
[] { typeof (int) }
).Invoke (null, new object [] { v }
);
418 b
= (bool)typeof (NullableMethods
).GetMethod ("GetHasValue").MakeGenericMethod (new Type
[] { typeof (int) }
).Invoke (null, new object [] { v }
);
423 NullableMethods
.GetValue (v
);
424 var res
= (int)typeof (NullableMethods
).GetMethod ("GetValue").MakeGenericMethod (new Type
[] { typeof (int) }
).Invoke (null, new object [] { v }
);
428 NullableMethods
.Get (42);
429 var res2
= (int?)typeof (NullableMethods
).GetMethod ("Get").MakeGenericMethod (new Type
[] { typeof (int) }
).Invoke (null, new object [] { 42 }
);
432 res2
= (int?)typeof (NullableMethods
).GetMethod ("GetNull").MakeGenericMethod (new Type
[] { typeof (int) }
).Invoke (null, new object [] { }
);
436 NullableMethods
.NullableMany (1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8);
437 res2
= (int?)typeof (NullableMethods
).GetMethod ("NullableMany").Invoke (null, new object [] { 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L }
);
443 [Category ("DYNCALL")]
444 public static int test_0_arm64_dyncall_vtypebyrefonstack () {
445 var s
= new LargeStruct () { a = 1, b = 2, c = 3, d = 4 }
;
447 NullableMethods
.GetHasValueManyArgs
<LargeStruct
> (1, 2, 3, 4, 5, 6, 7, 8, s
);
449 Type type
= typeof (LargeStruct
?).GetGenericArguments () [0];
450 var m
= typeof(NullableMethods
).GetMethod("GetHasValueManyArgs", BindingFlags
.Static
| BindingFlags
.Public
);
451 bool b1
= (bool)m
.MakeGenericMethod (new Type
[] {type}
).Invoke (null, new object[] { 1, 2, 3, 4, 5, 6, 7, 8, s }
);
454 bool b2
= (bool)m
.MakeGenericMethod (new Type
[] {type}
).Invoke (null, new object[] { 1, 2, 3, 4, 5, 6, 7, 8, null }
);
465 public static int test_0_enum_eq_comparer () {
466 var c
= EqualityComparer
<AnEnum
>.Default
;
467 return (!c
.Equals (AnEnum
.A
, AnEnum
.B
) && c
.Equals (AnEnum
.A
, AnEnum
.A
)) ? 0 : 1;
470 public static int test_0_enum_comparer () {
471 var c
= Comparer
<AnEnum
>.Default
;
472 return c
.Compare (AnEnum
.A
, AnEnum
.A
);
475 private static Dictionary
<long, TValue
> ConvertDictionary
<TValue
>(Dictionary
<long, IList
<TValue
>> source
) {
476 return source
.ToDictionary(pair
=> pair
.Key
, pair
=> pair
.Value
[0]);
479 [Category ("GSHAREDVT")]
480 public static int test_0_gsharedvt_non_variable_arg () {
481 Dictionary
<long, IList
<int>> data
= new Dictionary
<long, IList
<int>>
483 {123L, new List<int> {2}}
485 Dictionary
<long, int> newDict
= ConvertDictionary(data
);
486 if (newDict
.Count
!= 1)
491 enum LongEnum
: ulong {
495 public static int test_0_long_enum_eq_comparer () {
496 var c
= EqualityComparer
<LongEnum
>.Default
;
497 c
.GetHashCode (LongEnum
.A
);
501 enum UInt32Enum
: uint {
505 enum Int32Enum
: int {
509 enum Int16Enum
: short {
513 enum UInt16Enum
: ushort {
517 enum Int8Enum
: sbyte {
521 enum UInt8Enum
: byte {
525 public static int test_0_int_enum_eq_comparer () {
526 var t1
= new Dictionary
<Int32Enum
, object> ();
527 t1
[Int32Enum
.A
] = "foo";
529 var t2
= new Dictionary
<UInt32Enum
, object> ();
530 t2
[UInt32Enum
.A
] = "foo";
532 var t3
= new Dictionary
<UInt16Enum
, object> ();
533 t3
[UInt16Enum
.A
] = "foo";
535 var t4
= new Dictionary
<Int16Enum
, object> ();
536 t4
[Int16Enum
.A
] = "foo";
538 var t5
= new Dictionary
<Int8Enum
, object> ();
539 t5
[Int8Enum
.A
] = "foo";
541 var t6
= new Dictionary
<UInt8Enum
, object> ();
542 t6
[UInt8Enum
.A
] = "foo";
547 [Category ("DYNCALL")]
548 public static int test_0_array_accessor_runtime_invoke_ref () {
549 var t
= typeof (string[]);
550 var arr
= Array
.CreateInstance (typeof (string), 1);
551 arr
.GetType ().GetMethod ("Set").Invoke (arr
, new object [] { 0, "A" }
);
552 var res
= (string)arr
.GetType ().GetMethod ("Get").Invoke (arr
, new object [] { 0 }
);
558 public static void SetArrayValue_
<T
> (T
[] values
) {
559 values
.Select (x
=> x
).ToArray ();
562 [Category ("GSHAREDVT")]
563 public static int test_0_delegate_invoke_wrappers_gsharedvt () {
564 var enums
= new LongEnum
[] { LongEnum.A }
;
565 SetArrayValue_ (enums
);
570 public int a
, b
, c
, d
;
573 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
574 public static bool GetHasValue
<T
>(T
? value) where T
: struct
576 return value.HasValue
;
579 [Category ("DYNCALL")]
580 [Category ("!WASM")] //Interp fails
581 public static int test_0_large_nullable_invoke () {
582 var s
= new LargeStruct () { a = 1, b = 2, c = 3, d = 4 }
;
584 NullableMethods
.GetHasValue
<LargeStruct
> (s
);
586 var m
= typeof(NullableMethods
).GetMethod("GetHasValue", BindingFlags
.Static
| BindingFlags
.Public
);
588 Type type
= typeof (LargeStruct
?).GetGenericArguments () [0];
589 bool b1
= (bool)m
.MakeGenericMethod (new Type
[] {type}
).Invoke (null, new object[] { s }
);
592 bool b2
= (bool)m
.MakeGenericMethod (new Type
[] {type}
).Invoke (null, new object[] { null }
);
599 public float a
, b
, c
;
602 struct LargeStruct2
{
604 public int a
, b
, c
, d
, e
, f
, g
, h
;
607 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
608 static int pass_hfa_on_stack (FpStruct s1
, FpStruct s2
, FpStruct s3
) {
612 public static int test_10_arm64_hfa_on_stack_llvm () {
613 var arr
= new LargeStruct2
[10, 10];
614 for (int i
= 0; i
< 10; ++i
)
615 for (int j
= 0; j
< 10; ++j
)
616 arr
[i
, j
].x
= new FpStruct ();
618 var s1
= new FpStruct () { a = 1, b = 1, c = 10 }
;
619 return pass_hfa_on_stack (s1
, s1
, s1
);
622 public static int test_0_get_current_method () {
623 var m
= MethodBase
.GetCurrentMethod ();
625 var m2
= typeof (AotTests
).GetMethod ("test_0_get_current_method");
627 var m2
= typeof (Tests
).GetMethod ("test_0_get_current_method");
629 return m
== m2
? 0 : 1;
632 class GetCurrentMethodClass
<T
> {
633 [MethodImplAttribute (MethodImplOptions
.NoInlining
)]
634 public MethodBase
get_current () {
635 return MethodBase
.GetCurrentMethod ();
639 public static int test_0_get_current_method_generic () {
640 var c
= new GetCurrentMethodClass
<string> ();
641 var m
= c
.get_current ();
642 var m2
= typeof (GetCurrentMethodClass
<>).GetMethod ("get_current");
643 return m
== m2
? 0 : 1;
646 public static int test_0_array_wrappers_runtime_invoke () {
647 string[][] arr
= new string [10][];
648 IEnumerable
<string[]> iface
= arr
;
649 var m
= typeof(IEnumerable
<string[]>).GetMethod ("GetEnumerator");
650 m
.Invoke (arr
, null);
654 public static int test_0_fault_clauses () {
655 object [] data
= { 1, 2, 3 }
;
656 int [] expected
= { 1, 2, 3 }
;
659 Action d
= delegate () { data.Cast<IEnumerable> ().GetEnumerator ().MoveNext (); }
;
661 } catch (Exception
) {
666 public static int test_0_regress_gh_7364 () {
667 var map1
= new Dictionary
<Type
, IntPtr
> (EqualityComparer
<Type
>.Default
);
668 var map2
= new Dictionary
<IntPtr
, WeakReference
> (EqualityComparer
<IntPtr
>.Default
);
672 public static int test_0_byte_equality_compater_devirt () {
673 var dict
= new Dictionary
<byte, Struct1
>();
674 dict
[1] = new Struct1 ();
675 dict
[1] = new Struct1 ();
681 public interface GameComponent
{
684 public struct Components
<T
> {
685 public T
[] Collection
;
689 struct AStruct
: GameComponent
{
692 public class ReadonlyTest
<T
> where T
: GameComponent
{
693 private static Components
<T
> _components
;
695 public static T
[] GetArray()
697 ref readonly Components
<T
> components
= ref GetComponents();
698 return components
.Collection
;
701 public static ref readonly Components
<T
> GetComponents()
703 return ref _components
;
708 public static int test_0_readonly_modopt () {
709 typeof (ReadonlyTest
<>).MakeGenericType (new Type
[] { typeof (AStruct) }
).GetMethod ("GetArray").Invoke (null, null);