Merge pull request #1542 from ninjarobot/UriTemplateMatchException
[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 (String[] args) {
19                 return TestDriver.RunTests (typeof (Tests), args);
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         [Category ("!AMD64")]
61         static int test_0_arm64_dyncall_double () {
62                 double arg1 = 1.0f;
63                 double s = 2.0f;
64                 var res = (double)typeof (Foo<double>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
65                 if (res != 2.0f)
66                         return 1;
67                 return 0;
68         }
69
70         [Category ("!AMD64")]
71         static int test_0_arm64_dyncall_float () {
72                 double arg1 = 1.0f;
73                 float s = 2.0f;
74                 var res = (float)typeof (Foo<float>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
75                 if (res != 2.0f)
76                         return 1;
77                 return 0;
78         }
79
80         [Category ("!AMD64")]
81         static int test_0_arm64_dyncall_hfa_double () {
82                 double arg1 = 1.0f;
83                 // HFA with double members
84                 var s = new Struct1 ();
85                 s.a = 1.0f;
86                 s.b = 2.0f;
87                 var s_res = (Struct1)typeof (Foo<Struct1>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
88                 if (s_res.a != 1.0f || s_res.b != 2.0f)
89                         return 1;
90                 return 0;
91         }
92
93         [Category ("!AMD64")]
94         static int test_0_arm64_dyncall_hfa_float () {
95                 double arg1 = 1.0f;
96                 var s = new Struct2 ();
97                 s.a = 1.0f;
98                 s.b = 2.0f;
99                 var s_res = (Struct2)typeof (Foo<Struct2>).GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
100                 if (s_res.a != 1.0f || s_res.b != 2.0f)
101                         return 1;
102                 return 0;
103         }
104
105         [Category ("GSHAREDVT")]
106         static int test_0_arm64_dyncall_gsharedvt_out_hfa_double () {
107                 /* gsharedvt out trampoline with double hfa argument */
108                 double arg1 = 1.0f;
109
110                 var s = new Struct1 ();
111                 s.a = 1.0f;
112                 s.b = 2.0f;
113                 // Call Foo2.Get_T directly, so its gets an instance
114                 Foo2<Struct1>.Get_T (arg1, s);
115                 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct1) });
116                 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
117                 var s_res = (Struct1)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
118                 if (s_res.a != 1.0f || s_res.b != 2.0f)
119                         return 1;
120                 return 0;
121         }
122
123         [Category ("GSHAREDVT")]
124         static int test_0_arm64_dyncall_gsharedvt_out_hfa_float () {
125                 /* gsharedvt out trampoline with double hfa argument */
126                 double arg1 = 1.0f;
127
128                 var s = new Struct2 ();
129                 s.a = 1.0f;
130                 s.b = 2.0f;
131                 // Call Foo2.Get_T directly, so its gets an instance
132                 Foo2<Struct2>.Get_T (arg1, s);
133                 Type t = typeof (Foo3<>).MakeGenericType (new Type [] { typeof (Struct2) });
134                 // Call Foo3.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
135                 var s_res = (Struct2)t.GetMethod ("Get_T").Invoke (null, new object [] { arg1, s });
136                 if (s_res.a != 1.0f || s_res.b != 2.0f)
137                         return 1;
138                 return 0;
139         }
140
141         interface IFaceFoo4<T> {
142                 T Get_T (double d, T t);
143         }
144
145         class Foo4<T> : IFaceFoo4<T> {
146                 public T Get_T (double d, T t) {
147                         return Foo2<T>.Get_T (d, t);
148                 }
149         }
150
151         struct VTypeByRefStruct {
152                 public long o1, o2, o3;
153         }
154
155 #if FALSE
156         [Category ("GSHAREDVT")]
157         public static int test_0_arm64_gsharedvt_out_vtypebyref () {
158                 /* gsharedvt out trampoline with vtypebyref argument */
159                 var s = new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 };
160
161                 // Call Foo2.Get_T directly, so its gets an instance
162                 Foo2<VTypeByRefStruct>.Get_T (1.0f, s);
163                 var o = (IFaceFoo4<VTypeByRefStruct>)Activator.CreateInstance (typeof (Foo4<>).MakeGenericType (new Type [] { typeof (VTypeByRefStruct) }));
164                 // Call Foo4.Get_T, this will call the gsharedvt instance, which will call the non-gsharedvt instance
165                 var s_res = o.Get_T (1.0f, s);
166                 if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
167                         return 1;
168                 return 0;
169         }
170 #endif
171
172         class Foo5<T> {
173                 public static T Get_T (object o) {
174                         return (T)o;
175                 }
176         }
177
178         [Category ("!AMD64")]
179         static int test_0_arm64_dyncall_vtypebyref_ret () {
180                 var s = new VTypeByRefStruct () { o1 = 1, o2 = 2, o3 = 3 };
181                 Type t = typeof (Foo5<>).MakeGenericType (new Type [] { typeof (VTypeByRefStruct) });
182                 var o = Activator.CreateInstance (t);
183                 try {
184                         var s_res = (VTypeByRefStruct)t.GetMethod ("Get_T").Invoke (o, new object [] { s });
185                         if (s_res.o1 != 1 || s_res.o2 != 2 || s_res.o3 != 3)
186                                 return 1;
187                 } catch (TargetInvocationException) {
188                         return 2;
189                 }
190                 return 0;
191         }
192
193 }