2 using System.Reflection;
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * static int test_<result>_<name> ();
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.
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)
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
29 return TestDriver.RunTests (typeof (Tests));
32 static int test_0_catch () {
33 Exception x = new Exception ();
37 } catch (Exception e) {
44 static int test_0_finally_without_exc () {
49 } catch (Exception e) {
58 static int test_0_finally () {
62 throw new Exception ();
63 } catch (Exception e) {
71 static int test_0_byte_cast () {
83 } catch (OverflowException) {
97 } catch (OverflowException) {
111 } catch (OverflowException) {
125 } catch (OverflowException) {
139 } catch (OverflowException) {
153 } catch (OverflowException) {
167 } catch (OverflowException) {
181 } catch (OverflowException) {
195 } catch (OverflowException) {
209 } catch (OverflowException) {
223 } catch (OverflowException) {
237 } catch (OverflowException) {
248 static int test_0_sbyte_cast () {
260 } catch (OverflowException) {
274 } catch (OverflowException) {
288 } catch (OverflowException) {
302 } catch (OverflowException) {
316 } catch (OverflowException) {
330 } catch (OverflowException) {
344 } catch (OverflowException) {
358 } catch (OverflowException) {
372 } catch (OverflowException) {
386 } catch (OverflowException) {
400 } catch (OverflowException) {
414 } catch (OverflowException) {
428 } catch (OverflowException) {
442 } catch (OverflowException) {
456 } catch (OverflowException) {
470 } catch (OverflowException) {
484 } catch (OverflowException) {
498 } catch (OverflowException) {
512 } catch (OverflowException) {
526 } catch (OverflowException) {
537 static int test_0_ushort_cast () {
544 a = System.UInt16.MaxValue;
549 } catch (OverflowException) {
561 } catch (OverflowException) {
568 a = System.UInt16.MaxValue + 1;
573 } catch (OverflowException) {
585 } catch (OverflowException) {
597 } catch (OverflowException) {
604 double d = System.UInt16.MaxValue;
609 } catch (OverflowException) {
621 } catch (OverflowException) {
628 double d = System.UInt16.MaxValue + 1.0;
633 } catch (OverflowException) {
640 l = System.UInt16.MaxValue;
645 } catch (OverflowException) {
657 } catch (OverflowException) {
664 l = System.UInt16.MaxValue + 1;
669 } catch (OverflowException) {
681 } catch (OverflowException) {
690 static int test_0_short_cast () {
697 a = System.UInt16.MaxValue;
702 } catch (OverflowException) {
714 } catch (OverflowException) {
721 a = System.Int16.MaxValue + 1;
726 } catch (OverflowException) {
733 a = System.Int16.MinValue - 1;
738 } catch (OverflowException) {
750 } catch (OverflowException) {
757 a = System.Int16.MinValue;
762 } catch (OverflowException) {
769 a = System.Int16.MaxValue;
774 } catch (OverflowException) {
781 a = System.Int16.MaxValue + 1;
786 } catch (OverflowException) {
793 double d = System.Int16.MaxValue;
798 } catch (OverflowException) {
805 double d = System.Int16.MinValue;
810 } catch (OverflowException) {
817 double d = System.Int16.MaxValue + 1.0;
822 } catch (OverflowException) {
829 double d = System.Int16.MinValue - 1.0;
834 } catch (OverflowException) {
841 l = System.Int16.MaxValue + 1;
846 } catch (OverflowException) {
853 l = System.Int16.MaxValue;
858 } catch (OverflowException) {
865 l = System.Int16.MinValue - 1;
870 } catch (OverflowException) {
878 l = System.Int16.MinValue;
883 } catch (OverflowException) {
892 static int test_0_int_cast () {
898 double d = System.Int32.MaxValue + 1.0;
903 } catch (OverflowException) {
910 double d = System.Int32.MaxValue;
915 } catch (OverflowException) {
923 double d = System.Int32.MinValue;
928 } catch (OverflowException) {
936 double d = System.Int32.MinValue - 1.0;
941 } catch (OverflowException) {
948 l = System.Int32.MaxValue + (long)1;
953 } catch (OverflowException) {
960 l = System.Int32.MaxValue;
965 } catch (OverflowException) {
973 l = System.Int32.MinValue;
978 } catch (OverflowException) {
986 l = System.Int32.MinValue - (long)1;
991 } catch (OverflowException) {
1000 static int test_0_uint_cast () {
1006 double d = System.UInt32.MaxValue;
1011 } catch (OverflowException) {
1018 double d = System.UInt32.MaxValue + 1.0;
1023 } catch (OverflowException) {
1030 double d = System.UInt32.MinValue;
1035 } catch (OverflowException) {
1042 double d = System.UInt32.MinValue - 1.0;
1047 } catch (OverflowException) {
1054 l = System.UInt32.MaxValue;
1059 } catch (OverflowException) {
1066 l = System.UInt32.MaxValue + (long)1;
1071 } catch (OverflowException) {
1078 l = System.UInt32.MinValue;
1083 } catch (OverflowException) {
1090 l = System.UInt32.MinValue - (long)1;
1095 } catch (OverflowException) {
1104 static int test_0_long_cast () {
1109 double d = System.Int64.MaxValue - 512.0;
1114 } catch (OverflowException) {
1121 double d = System.Int64.MaxValue - 513.0;
1126 } catch (OverflowException) {
1134 double d = System.Int64.MinValue - 1024.0;
1139 } catch (OverflowException) {
1146 double d = System.Int64.MinValue - 1025.0;
1151 } catch (OverflowException) {
1160 static int test_0_ulong_cast () {
1165 double d = System.UInt64.MaxValue - 1024.0;
1170 } catch (OverflowException) {
1177 double d = System.UInt64.MaxValue - 1025.0;
1182 } catch (OverflowException) {
1195 } catch (OverflowException) {
1207 } catch (OverflowException) {
1216 static int test_0_simple_double_casts () {
1218 double d = 0xffffffff;
1220 if ((uint)d != 4294967295)
1223 d = 0xffffffffffffffff;
1236 if ((ushort)d != 0xffff)
1239 if ((byte)d != 0xff)
1245 static int test_0_div_zero () {
1254 } catch (DivideByZeroException) {
1263 } catch (DivideByZeroException) {
1272 static int test_0_udiv_zero () {
1281 } catch (DivideByZeroException) {
1290 } catch (DivideByZeroException) {
1299 static int test_0_long_div_zero () {
1308 } catch (DivideByZeroException) {
1317 } catch (DivideByZeroException) {
1326 static int test_0_ulong_div_zero () {
1335 } catch (DivideByZeroException) {
1344 } catch (DivideByZeroException) {
1353 static int test_0_float_div_zero () {
1362 } catch (DivideByZeroException) {
1371 } catch (DivideByZeroException) {
1380 static int test_0_invalid_unbox () {
1383 object o = "Some string";
1387 // Illegal conversion; o contains a string not an int
1389 } catch (Exception e) {
1397 /* bug# 42190, at least mcs generates a leave for the return that
1398 * jumps out of multiple exception clauses: we used to execute just
1399 * one enclosing finally block.
1401 static int finally_level;
1402 static void do_something () {
1415 static int test_2_multiple_finally_clauses () {
1418 if (finally_level == 1)
1423 static int test_3_checked_cast_un () {
1424 ulong i = 0x8000000034000000;
1428 checked { j = (long)i; }
1429 } catch (OverflowException) {
1438 static int test_4_checked_cast () {
1442 unchecked { i = (long)0x8000000034000000;};
1444 checked { j = (ulong)i; }
1445 } catch (OverflowException) {
1454 static readonly int[] mul_dim_results = new int[] {
1455 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1456 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1460 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1461 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1462 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1465 static int test_0_multi_dim_array_access () {
1466 int [,] a = System.Array.CreateInstance (typeof (int),
1467 new int [] {3,6}, new int [] {2,2 }) as int[,];
1470 for (x = 0; x < 8; ++x) {
1471 for (y = 0; y < 9; ++y) {
1472 bool got_ex = false;
1479 if (result_idx >= mul_dim_results.Length)
1481 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1482 return result_idx + 1;
1488 if (result_idx == mul_dim_results.Length)
1493 static void helper_out_obj (out object o) {
1494 o = (object)"buddy";
1497 static void helper_out_string (out string o) {
1501 static int test_2_array_mismatch () {
1502 string[] a = { "hello", "world" };
1504 bool passed = false;
1507 helper_out_obj (out b [1]);
1508 } catch (ArrayTypeMismatchException) {
1513 helper_out_string (out a [1]);
1514 if (a [1] != "buddy")
1519 static int test_0_long_add_ovf () {
1524 l = 999999999999999999;
1530 } catch (OverflowException) {