Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-233.cs
1 using System;
2 using System.Reflection;
3
4 class Tests {
5
6         public static int Main () {
7                 return TestDriver.RunTests (typeof (Tests));
8         }
9         
10         static int test_0_beq () {
11                 double a = 2.0;
12                 if (a != 2.0)
13                         return 1;
14                 return 0;
15         }
16
17         static int test_0_bne_un () {
18                 double a = 2.0;
19                 if (a == 1.0)
20                         return 1;
21                 return 0;
22         }
23
24         static int test_0_conv_r8 () {
25                 double a = 2;
26                 if (a != 2.0)
27                         return 1;
28                 return 0;
29         }
30
31         static int test_0_conv_i () {
32                 double a = 2.0;
33                 int i = (int)a;
34                 if (i != 2)
35                         return 1;
36                 uint ui = (uint)a;
37                 if (ui != 2)
38                         return 2;
39                 short s = (short)a;
40                 if (s != 2)
41                         return 3;
42                 ushort us = (ushort)a;
43                 if (us != 2)
44                         return 4;
45                 byte b = (byte)a;
46                 if (b != 2)
47                         return 5;
48                 return 0;
49         }
50
51         static int test_5_conv_r4 () {
52                 int i = 5;
53                 float f = (float)i;
54                 return (int)f;
55         }
56
57         static int test_5_double_conv_r4 () {
58                 double d = 5.0;
59                 float f = (float)d;
60                 return (int)f;
61         }
62
63         static int test_5_float_conv_r8 () {
64                 float f = 5.0F;
65                 double d = (double)f;
66                 return (int)d;
67         }
68
69         static int test_5_conv_r8 () {
70                 int i = 5;
71                 double f = (double)i;
72                 return (int)f;
73         }
74
75         static int test_5_add () {
76                 double a = 2.0;
77                 double b = 3.0;         
78                 return (int)(a + b);
79         }
80
81         static int test_5_sub () {
82                 double a = 8.0;
83                 double b = 3.0;         
84                 return (int)(a - b);
85         }       
86
87         static int test_24_mul () {
88                 double a = 8.0;
89                 double b = 3.0;         
90                 return (int)(a * b);
91         }       
92
93         static int test_4_div () {
94                 double a = 8.0;
95                 double b = 2.0;         
96                 return (int)(a / b);
97         }       
98
99         static int test_2_rem () {
100                 double a = 8.0;
101                 double b = 3.0;         
102                 return (int)(a % b);
103         }       
104
105         static int test_2_neg () {
106                 double a = -2.0;                
107                 return (int)(-a);
108         }
109         
110         static int test_46_float_add_spill () {
111                 // we overflow the FP stack
112                 double a = 1;
113                 double b = 2;
114                 double c = 3;
115                 double d = 4;
116                 double e = 5;
117                 double f = 6;
118                 double g = 7;
119                 double h = 8;
120                 double i = 9;
121
122                 return (int)(1.0 + (a + (b + (c + (d + (e + (f + (g + (h + i)))))))));
123         }
124
125         static int test_362880_float_mul_spill () {
126                 // we overflow the FP stack
127                 double a = 1;
128                 double b = 2;
129                 double c = 3;
130                 double d = 4;
131                 double e = 5;
132                 double f = 6;
133                 double g = 7;
134                 double h = 8;
135                 double i = 9;
136
137                 return (int)(1.0 * (a * (b * (c * (d * (e * (f * (g * (h * i)))))))));
138         }
139
140         static int test_4_long_cast () {
141                 long a = 1000;
142                 double d = (double)a;
143                 long b = (long)d;
144                 if (b != 1000)
145                         return 0;
146                 return 4;
147         }
148
149         /* FIXME: This only works on little-endian machines */
150         /*
151         static unsafe int test_2_negative_zero () {
152                 int result = 0;
153                 double d = -0.0;
154                 float f = -0.0f;
155
156                 byte *ptr = (byte*)&d;
157                 if (ptr [7] == 0)
158                         return result;
159                 result ++;
160
161                 ptr = (byte*)&f;
162                 if (ptr [3] == 0)
163                         return result;
164                 result ++;
165
166                 return result;
167         }
168         */
169
170         static int test_16_float_cmp () {
171                 double a = 2.0;
172                 double b = 1.0;
173                 int result = 0;
174                 bool val;
175                 
176                 val = a == a;
177                 if (!val)
178                         return result;
179                 result++;
180
181                 val = (a != a);
182                 if (val)
183                         return result;
184                 result++;
185
186                 val = a < a;
187                 if (val)
188                         return result;
189                 result++;
190
191                 val = a > a;
192                 if (val)
193                         return result;
194                 result++;
195
196                 val = a <= a;
197                 if (!val)
198                         return result;
199                 result++;
200
201                 val = a >= a;
202                 if (!val)
203                         return result;
204                 result++;
205
206                 val = b == a;
207                 if (val)
208                         return result;
209                 result++;
210
211                 val = b < a;
212                 if (!val)
213                         return result;
214                 result++;
215
216                 val = b > a;
217                 if (val)
218                         return result;
219                 result++;
220
221                 val = b <= a;
222                 if (!val)
223                         return result;
224                 result++;
225
226                 val = b >= a;
227                 if (val)
228                         return result;
229                 result++;
230
231                 val = a == b;
232                 if (val)
233                         return result;
234                 result++;
235
236                 val = a < b;
237                 if (val)
238                         return result;
239                 result++;
240
241                 val = a > b;
242                 if (!val)
243                         return result;
244                 result++;
245
246                 val = a <= b;
247                 if (val)
248                         return result;
249                 result++;
250
251                 val = a >= b;
252                 if (!val)
253                         return result;
254                 result++;
255
256                 return result;
257         }
258
259         static int test_15_float_cmp_un () {
260                 double a = Double.NaN;
261                 double b = 1.0;
262                 int result = 0;
263                 bool val;
264                 
265                 val = a == a;
266                 if (val)
267                         return result;
268                 result++;
269
270                 val = a < a;
271                 if (val)
272                         return result;
273                 result++;
274
275                 val = a > a;
276                 if (val)
277                         return result;
278                 result++;
279
280                 val = a <= a;
281                 if (val)
282                         return result;
283                 result++;
284
285                 val = a >= a;
286                 if (val)
287                         return result;
288                 result++;
289
290                 val = b == a;
291                 if (val)
292                         return result;
293                 result++;
294
295                 val = b < a;
296                 if (val)
297                         return result;
298                 result++;
299
300                 val = b > a;
301                 if (val)
302                         return result;
303                 result++;
304
305                 val = b <= a;
306                 if (val)
307                         return result;
308                 result++;
309
310                 val = b >= a;
311                 if (val)
312                         return result;
313                 result++;
314
315                 val = a == b;
316                 if (val)
317                         return result;
318                 result++;
319
320                 val = a < b;
321                 if (val)
322                         return result;
323                 result++;
324
325                 val = a > b;
326                 if (val)
327                         return result;
328                 result++;
329
330                 val = a <= b;
331                 if (val)
332                         return result;
333                 result++;
334
335                 val = a >= b;
336                 if (val)
337                         return result;
338                 result++;
339
340                 return result;
341         }
342
343         static int test_15_float_branch () {
344                 double a = 2.0;
345                 double b = 1.0;
346                 int result = 0;
347                 
348                 if (!(a == a))
349                         return result;
350                 result++;
351
352                 if (a < a)
353                         return result;
354                 result++;
355
356                 if (a > a)
357                         return result;
358                 result++;
359
360                 if (!(a <= a))
361                         return result;
362                 result++;
363
364                 if (!(a >= a))
365                         return result;
366                 result++;
367
368                 if (b == a)
369                         return result;
370                 result++;
371
372                 if (!(b < a))
373                         return result;
374                 result++;
375
376                 if (b > a)
377                         return result;
378                 result++;
379
380                 if (!(b <= a))
381                         return result;
382                 result++;
383
384                 if (b >= a)
385                         return result;
386                 result++;
387
388                 if (a == b)
389                         return result;
390                 result++;
391
392                 if (a < b)
393                         return result;
394                 result++;
395
396                 if (!(a > b))
397                         return result;
398                 result++;
399
400                 if (a <= b)
401                         return result;
402                 result++;
403
404                 if (!(a >= b))
405                         return result;
406                 result++;
407
408                 return result;
409         }
410
411         static int test_15_float_branch_un () {
412                 double a = Double.NaN;
413                 double b = 1.0;
414                 int result = 0;
415                 
416                 if (a == a)
417                         return result;
418                 result++;
419
420                 if (a < a)
421                         return result;
422                 result++;
423
424                 if (a > a)
425                         return result;
426                 result++;
427
428                 if (a <= a)
429                         return result;
430                 result++;
431
432                 if (a >= a)
433                         return result;
434                 result++;
435
436                 if (b == a)
437                         return result;
438                 result++;
439
440                 if (b < a)
441                         return result;
442                 result++;
443
444                 if (b > a)
445                         return result;
446                 result++;
447
448                 if (b <= a)
449                         return result;
450                 result++;
451
452                 if (b >= a)
453                         return result;
454                 result++;
455
456                 if (a == b)
457                         return result;
458                 result++;
459
460                 if (a < b)
461                         return result;
462                 result++;
463
464                 if (a > b)
465                         return result;
466                 result++;
467
468                 if (a <= b)
469                         return result;
470                 result++;
471
472                 if (a >= b)
473                         return result;
474                 result++;
475
476                 return result;
477         }
478
479 }
480
481 public class TestDriver {
482
483         static public int RunTests (Type type, string[] args) {
484                 int failed = 0, ran = 0;
485                 int result, expected, elen;
486                 int i, j;
487                 string name;
488                 MethodInfo[] methods;
489                 bool do_timings = false;
490                 int tms = 0;
491                 DateTime start, end = DateTime.Now;
492
493                 if (args != null && args.Length > 0) {
494                         for (j = 0; j < args.Length; j++) {
495                                 if (args [j] == "--time") {
496                                         do_timings = true;
497                                         string[] new_args = new string [args.Length - 1];
498                                         for (i = 0; i < j; ++i)
499                                                 new_args [i] = args [i];
500                                         j++;
501                                         for (; j < args.Length; ++i, ++j)
502                                                 new_args [i] = args [j];
503                                         args = new_args;
504                                         break;
505                                 }
506                         }
507                 }
508                 methods = type.GetMethods (BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Static);
509                 for (i = 0; i < methods.Length; ++i) {
510                         name = methods [i].Name;
511                         if (!name.StartsWith ("test_"))
512                                 continue;
513                         if (args != null && args.Length > 0) {
514                                 bool found = false;
515                                 for (j = 0; j < args.Length; j++) {
516                                         if (name.EndsWith (args [j])) {
517                                                 found = true;
518                                                 break;
519                                         }
520                                 }
521                                 if (!found)
522                                         continue;
523                         }
524                         for (j = 5; j < name.Length; ++j)
525                                 if (!Char.IsDigit (name [j]))
526                                         break;
527                         expected = Int32.Parse (name.Substring (5, j - 5));
528                         start = DateTime.Now;
529                         result = (int)methods [i].Invoke (null, null);
530                         if (do_timings) {
531                                 end = DateTime.Now;
532                                 long tdiff = end.Ticks - start.Ticks;
533                                 int mdiff = (int)tdiff/10000;
534                                 tms += mdiff;
535                                 Console.WriteLine ("{0} took {1} ms", name, mdiff);
536                         }
537                         ran++;
538                         if (result != expected) {
539                                 failed++;
540                                 Console.WriteLine ("{0} failed: got {1}, expected {2}", name, result, expected);
541                         }
542                 }
543                 
544                 if (do_timings) {
545                         Console.WriteLine ("Total ms: {0}", tms);
546                 }
547                 Console.WriteLine ("Regression tests: {0} ran, {1} failed in {2}", ran, failed, type);
548                 //Console.WriteLine ("Regression tests: {0} ran, {1} failed in [{2}]{3}", ran, failed, type.Assembly.GetName().Name, type);
549                 return failed;
550         }
551         static public int RunTests (Type type) {
552                 return RunTests (type, null);
553         }
554 }
555