Merge pull request #1156 from felfert/master
[mono.git] / mono / mini / aot-tests.cs
1 using System;
2 using System.Text;
3 using System.Reflection;
4 using System.Runtime.InteropServices;
5 using System.Runtime.CompilerServices;
6
7 /*
8  * Regression tests for the AOT/FULL-AOT code.
9  */
10
11 #if MOBILE
12 class AotTests
13 #else
14 class Tests
15 #endif
16 {
17 #if !MOBILE
18         static int Main () {
19                 return TestDriver.RunTests (typeof (Tests));
20         }
21 #endif
22
23         public delegate void ArrayDelegate (int[,] arr);
24
25         static int test_0_array_delegate_full_aot () {
26                 ArrayDelegate d = delegate (int[,] arr) {
27                 };
28                 int[,] a = new int[5, 6];
29                 d.BeginInvoke (a, null, null);
30                 return 0;
31         }
32
33         struct Struct1 {
34                 public double a, b;
35         }
36
37         struct Struct2 {
38                 public float a, b;
39         }
40
41         class Foo<T> {
42                 /* The 'd' argument is used to shift the register indexes so 't' doesn't start at the first reg */
43                 public static T Get_T (double d, T t) {
44                         return t;
45                 }
46         }
47
48         class Foo2<T> {
49                 public static T Get_T (double d, T t) {
50                         return t;
51                 }
52         }
53
54         class Foo3<T> {
55                 public static T Get_T (double d, T t) {
56                         return Foo2<T>.Get_T (d, t);
57                 }
58         }
59
60         static int test_0_arm64_dyncall_double () {
61                 double arg1 = 1.0f;
62                 double s = 2.0f;
63                 var res = (double)typeof (Foo<double>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
64                 if (res != 2.0f)
65                         return 1;
66                 return 0;
67         }
68
69         static int test_0_arm64_dyncall_float () {
70                 double arg1 = 1.0f;
71                 float s = 2.0f;
72                 var res = (float)typeof (Foo<float>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
73                 if (res != 2.0f)
74                         return 1;
75                 return 0;
76         }
77
78         static int test_0_arm64_dyncall_hfa_double () {
79                 double arg1 = 1.0f;
80                 // HFA with double members
81                 var s = new Struct1 ();
82                 s.a = 1.0f;
83                 s.b = 2.0f;
84                 var s_res = (Struct1)typeof (Foo<Struct1>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
85                 if (s_res.a != 1.0f || s_res.b != 2.0f)
86                         return 1;
87                 return 0;
88         }
89
90         static int test_0_arm64_dyncall_hfa_float () {
91                 double arg1 = 1.0f;
92                 var s = new Struct2 ();
93                 s.a = 1.0f;
94                 s.b = 2.0f;
95                 var s_res = (Struct2)typeof (Foo<Struct2>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
96                 if (s_res.a != 1.0f || s_res.b != 2.0f)
97                         return 1;
98                 return 0;
99         }
100
101         static int test_0_arm64_dyncall_gsharedvt_out_hfa_double () {
102                 /* gsharedvt out trampoline with double hfa argument */
103                 double arg1 = 1.0f;
104
105                 var s = new Struct1 ();
106                 s.a = 1.0f;
107                 s.b = 2.0f;
108                 // Call Foo2.Get_T directly, so its gets an instance
109                 Foo2<Struct1>.Get_T (arg1, s);
110                 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct1) });
111                 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
112                 var s_res = (Struct1)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
113                 if (s_res.a != 1.0f || s_res.b != 2.0f)
114                         return 1;
115                 return 0;
116         }
117
118         static int test_0_arm64_dyncall_gsharedvt_out_hfa_float () {
119                 /* gsharedvt out trampoline with double hfa argument */
120                 double arg1 = 1.0f;
121
122                 var s = new Struct2 ();
123                 s.a = 1.0f;
124                 s.b = 2.0f;
125                 // Call Foo2.Get_T directly, so its gets an instance
126                 Foo2<Struct2>.Get_T (arg1, s);
127                 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct2) });
128                 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
129                 var s_res = (Struct2)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
130                 if (s_res.a != 1.0f || s_res.b != 2.0f)
131                         return 1;
132                 return 0;
133         }
134
135         interface IFaceFoo4<T> {
136                 T Get_T (double d, T t);
137         }
138
139         class Foo4<T> : IFaceFoo4<T> {
140                 public T Get_T (double d, T t) {
141                         return Foo2<T>.Get_T (d, t);
142                 }
143         }
144
145         struct VTypeByRefStruct {
146                 public long o1, o2, o3;
147         }
148
149         public static int test_0_arm64_gsharedvt_out_vtypebyref () {
150                 /* gsharedvt out trampoline with vtypebyref argument */
151                 var s = new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 };
152
153                 // Call Foo2.Get_T directly, so its gets an instance
154                 Foo2<VTypeByRefStruct>.Get_T (1.0f, s);
155                 var o = (IFaceFoo4<VTypeByRefStruct>)Activator.CreateInstance (typeof (Foo4<>).MakeGenericType (new Type [] { typeof (VTypeByRefStruct) }));
156                 // Call Foo4.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
157                 var s_res = o.Get_T (1.0f, s);
158                 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
159                         return 1;
160                 return 0;
161         }
162 }