2005-02-05 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mono / mini / s390-abi.cs
1 using System;
2 using System.Reflection;
3
4 /*
5  * Regression tests for the mono JIT.
6  *
7  * Each test needs to be of the form:
8  *
9  * static int test_<result>_<name> ();
10  *
11  * where <result> is an integer (the value that needs to be returned by
12  * the method to make it pass.
13  * <name> is a user-displayed name used to identify the test.
14  *
15  * The tests can be driven in two ways:
16  * *) running the program directly: Main() uses reflection to find and invoke
17  *      the test methods (this is useful mostly to check that the tests are correct)
18  * *) with the --regression switch of the jit (this is the preferred way since
19  *      all the tests will be run with optimizations on and off)
20  *
21  * The reflection logic could be moved to a .dll since we need at least another
22  * regression test file written in IL code to have better control on how
23  * the IL code looks.
24  */
25
26 class Tests {
27
28         public struct TestStruct1 
29         {
30                 public int a;
31         }
32         
33         public struct TestStruct2
34         {       
35                 public int a;
36                 public int b;
37         }
38
39         public struct TestStruct3
40         {
41                 public int a;
42                 public int b;
43                 public int c;
44         }
45
46         static int Main () {
47                 return TestDriver.RunTests (typeof (Tests));
48         }
49
50         static void reg_struct(TestStruct1 regStruct) 
51         {
52                 regStruct.a = 1;
53         }
54
55         static int test_0_regstruct () 
56         {
57                 TestStruct1 myStruct;
58                 myStruct.a = 1;
59                 reg_struct(myStruct);
60                 if (myStruct.a == 1)
61                         return 0;
62                 else
63                         return 1;
64         }
65
66         static int reg_struct_ret(TestStruct2 regStruct) 
67         {
68                 return regStruct.b;
69         }
70
71         static int test_0_reg_return () 
72         {
73                 TestStruct2 myStruct;
74                 myStruct.a = 0;
75                 myStruct.b = 42;
76                 if (reg_struct_ret(myStruct) == 42)
77                         return 0;
78                 return 2;
79         }
80
81         static int spill_regs (int a, int b, int c, int d, int e, int f)
82         {
83                 return f;
84         }
85
86         static int test_0_spill_regs ()
87         {
88                 if (spill_regs (1, 2, 3, 4, 5, 6) == 6)
89                         return 0;
90                 else
91                         return 3;
92         }
93
94         static TestStruct3 spill_struct (TestStruct3 regStruct)
95         {
96                 regStruct.c = 99;
97                 return(regStruct);
98         }
99
100         static int spill_struct_void (TestStruct3 regStruct)
101         {
102                 if (regStruct.c == 255)
103                         return 0;
104                 else
105                         return 7;
106         }
107
108         static int receive_spill_struct (TestStruct2 regStruct)
109         {
110                 if (regStruct.b == 181)
111                         return 0;
112                 else
113                         return 8;
114         }
115
116         static int pass_spill_struct_big (int a, int b, int c, int d, int e, TestStruct3 regStruct)
117         {
118                 int retVal;
119                 retVal = receive_spill_struct_big(regStruct);
120                 return retVal;
121         }
122
123         static int receive_spill_struct_big (TestStruct3 regStruct)
124         {
125                 if (regStruct.c == 999)
126                         return 0;
127                 else
128                         return 9;
129         }
130
131         static int receive_struct_spill (int a, int b, int c, int d, int e, TestStruct2 regStruct)
132         {
133                 if (regStruct.b == 181)
134                         return 0;
135                 else
136                         return 10;
137         }
138
139         static int receive_struct_spill_big (int a, int b, int c, int d, int e, TestStruct3 regStruct)
140         {
141                 if (regStruct.c == 999)
142                         return 0;
143                 else
144                         return 11;
145         }
146
147         static int pass_spill_struct (int a, int b, int c, int d, int e, TestStruct2 regStruct)
148         {
149                 int retVal;
150                 retVal = receive_spill_struct(regStruct);
151                 return retVal;
152         }
153
154         static int pass_struct_spill (TestStruct2 regStruct)
155         {
156                 int retVal;
157                 retVal = receive_struct_spill(1,2,3,4,5,regStruct);
158                 return retVal;
159         }
160
161         static int pass_struct_spill_big(TestStruct3 regStruct)
162         {
163                 int retVal;
164                 retVal = receive_struct_spill_big(1,2,3,4,5,regStruct);
165                 return retVal;
166         }
167
168         static int pass_spill_struct_spill (int a, int b, int c, int d, int e, TestStruct2 regStruct)
169         {
170                 int retVal;
171                 retVal = receive_struct_spill(a,b,c,d,e,regStruct);
172                 return retVal;
173         }
174
175         static int pass_spill_struct_spill_big(int a, int b, int c, int d, int e, TestStruct3 regStruct)
176         {
177                 int retVal;
178                 retVal = receive_struct_spill_big(a,b,c,d,e,regStruct);
179                 return retVal;
180         }
181
182         static int test_0_spill () 
183         {
184                 TestStruct3 myStruct;
185                 myStruct.a = 64;        
186                 myStruct.b = 255;
187                 myStruct.c = 127;
188                 myStruct = spill_struct(myStruct);
189                 if (myStruct.c == 99)
190                         return 0;
191                 return myStruct.c;
192         }
193
194         static int test_0_spill_void ()
195         {
196                 TestStruct3 myStruct;
197                 myStruct.a = 0;
198                 myStruct.b = 127;
199                 myStruct.c = 255;
200                 return (spill_struct_void(myStruct));
201         }
202
203         static int spill_struct_ret (TestStruct3 regStruct)
204         {
205                 return (regStruct.c);
206                 
207         }
208
209         static int test_0_spill_ret ()
210         {
211                 TestStruct3 myStruct;
212                 myStruct.a = 0; 
213                 myStruct.b = 0;
214                 myStruct.c = 69;
215                 if (spill_struct_ret(myStruct) == 69)
216                         return 0;
217                 return 5;
218         }
219
220         static TestStruct2 struct_ret(TestStruct2 regStruct)
221         {
222                 regStruct.a = -1;
223                 regStruct.b = 72;
224                 return(regStruct);
225         }
226
227         static int test_0_struct_ret ()
228         {
229                 TestStruct2 myStruct;
230                 myStruct.a = 99;
231                 myStruct.b = 14;
232                 myStruct = struct_ret(myStruct);
233                 if (myStruct.b == 72)
234                         return 0;
235                 else
236                         return myStruct.b;
237         }
238
239         static float TestSingle (float a, float b, float c)
240         {
241                 return b;
242         }
243
244         static int test_0_TestSingle ()
245         {
246                 float a = 3F; float b = 4.5F; float c = 900F;
247                 if (TestSingle(a, b, c) == b)
248                         return 0;
249                 else
250                         return 6;
251         }
252
253         static int test_0_pass_spill ()
254         {
255                 TestStruct2 myStruct;
256                 myStruct.a = 32;
257                 myStruct.b = 181;
258                 return (pass_spill_struct (1, 2, 3, 4, 5, myStruct));
259         }
260                 
261         static int test_0_pass_spill_big ()
262         {
263                 TestStruct3 myStruct;
264                 myStruct.a = 32;
265                 myStruct.b = 181;
266                 myStruct.c = 999;
267                 return (pass_spill_struct_big (1, 2, 3, 4, 5, myStruct));
268         }
269                 
270         static int test_0_pass_struct_spill ()
271         {
272                 TestStruct2 myStruct;
273                 myStruct.a = 32;
274                 myStruct.b = 181;
275                 return (pass_struct_spill (myStruct));
276         }
277                 
278         static int test_0_pass_struct_spill_big ()
279         {
280                 TestStruct3 myStruct;
281                 myStruct.a = 32;
282                 myStruct.b = 181;
283                 myStruct.c = 999;
284                 return (pass_struct_spill_big (myStruct));
285         }
286                 
287         static int test_0_pass_spill_struct_spill ()
288         {
289                 TestStruct2 myStruct;
290                 myStruct.a = 32;
291                 myStruct.b = 181;
292                 return (pass_spill_struct_spill (1,2,3,4,5,myStruct));
293         }
294                 
295         static int test_0_pass_spill_struct_spill_big ()
296         {
297                 TestStruct3 myStruct;
298                 myStruct.a = 32;
299                 myStruct.b = 181;
300                 myStruct.c = 999;
301                 return (pass_spill_struct_spill_big (1,2,3,4,5,myStruct));
302         }
303
304         static long pass_long_odd (int a, long b)
305         {
306                 return (b);
307         }
308                 
309         static int test_0_pass_long_odd ()
310         {
311                 int a = 5;
312                 long b = 9000;
313                 if (pass_long_odd(a,b) == 9000)
314                         return 0;
315                 else
316                         return 9;
317         }
318
319 }