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_nested_finally () {
86 static int test_0_byte_cast () {
98 } catch (OverflowException) {
112 } catch (OverflowException) {
126 } catch (OverflowException) {
140 } catch (OverflowException) {
154 } catch (OverflowException) {
168 } catch (OverflowException) {
182 } catch (OverflowException) {
196 } catch (OverflowException) {
210 } catch (OverflowException) {
224 } catch (OverflowException) {
238 } catch (OverflowException) {
252 } catch (OverflowException) {
263 static int test_0_sbyte_cast () {
275 } catch (OverflowException) {
289 } catch (OverflowException) {
303 } catch (OverflowException) {
317 } catch (OverflowException) {
331 } catch (OverflowException) {
345 } catch (OverflowException) {
359 } catch (OverflowException) {
373 } catch (OverflowException) {
387 } catch (OverflowException) {
401 } catch (OverflowException) {
415 } catch (OverflowException) {
429 } catch (OverflowException) {
443 } catch (OverflowException) {
457 } catch (OverflowException) {
471 } catch (OverflowException) {
485 } catch (OverflowException) {
499 } catch (OverflowException) {
513 } catch (OverflowException) {
527 } catch (OverflowException) {
541 } catch (OverflowException) {
552 static int test_0_ushort_cast () {
559 a = System.UInt16.MaxValue;
564 } catch (OverflowException) {
576 } catch (OverflowException) {
583 a = System.UInt16.MaxValue + 1;
588 } catch (OverflowException) {
600 } catch (OverflowException) {
612 } catch (OverflowException) {
619 double d = System.UInt16.MaxValue;
624 } catch (OverflowException) {
636 } catch (OverflowException) {
643 double d = System.UInt16.MaxValue + 1.0;
648 } catch (OverflowException) {
655 l = System.UInt16.MaxValue;
660 } catch (OverflowException) {
672 } catch (OverflowException) {
679 l = System.UInt16.MaxValue + 1;
684 } catch (OverflowException) {
696 } catch (OverflowException) {
705 static int test_0_short_cast () {
712 a = System.UInt16.MaxValue;
717 } catch (OverflowException) {
729 } catch (OverflowException) {
736 a = System.Int16.MaxValue + 1;
741 } catch (OverflowException) {
748 a = System.Int16.MinValue - 1;
753 } catch (OverflowException) {
765 } catch (OverflowException) {
772 a = System.Int16.MinValue;
777 } catch (OverflowException) {
784 a = System.Int16.MaxValue;
789 } catch (OverflowException) {
796 a = System.Int16.MaxValue + 1;
801 } catch (OverflowException) {
808 double d = System.Int16.MaxValue;
813 } catch (OverflowException) {
820 double d = System.Int16.MinValue;
825 } catch (OverflowException) {
832 double d = System.Int16.MaxValue + 1.0;
837 } catch (OverflowException) {
844 double d = System.Int16.MinValue - 1.0;
849 } catch (OverflowException) {
856 l = System.Int16.MaxValue + 1;
861 } catch (OverflowException) {
868 l = System.Int16.MaxValue;
873 } catch (OverflowException) {
880 l = System.Int16.MinValue - 1;
885 } catch (OverflowException) {
893 l = System.Int16.MinValue;
898 } catch (OverflowException) {
907 static int test_0_int_cast () {
913 double d = System.Int32.MaxValue + 1.0;
918 } catch (OverflowException) {
925 double d = System.Int32.MaxValue;
930 } catch (OverflowException) {
938 double d = System.Int32.MinValue;
943 } catch (OverflowException) {
951 double d = System.Int32.MinValue - 1.0;
956 } catch (OverflowException) {
963 l = System.Int32.MaxValue + (long)1;
968 } catch (OverflowException) {
975 l = System.Int32.MaxValue;
980 } catch (OverflowException) {
988 l = System.Int32.MinValue;
993 } catch (OverflowException) {
1001 l = System.Int32.MinValue - (long)1;
1006 } catch (OverflowException) {
1023 static int test_0_uint_cast () {
1029 double d = System.UInt32.MaxValue;
1034 } catch (OverflowException) {
1041 double d = System.UInt32.MaxValue + 1.0;
1046 } catch (OverflowException) {
1053 double d = System.UInt32.MinValue;
1058 } catch (OverflowException) {
1065 double d = System.UInt32.MinValue - 1.0;
1070 } catch (OverflowException) {
1077 l = System.UInt32.MaxValue;
1082 } catch (OverflowException) {
1089 l = System.UInt32.MaxValue + (long)1;
1094 } catch (OverflowException) {
1101 l = System.UInt32.MinValue;
1106 } catch (OverflowException) {
1113 l = System.UInt32.MinValue - (long)1;
1118 } catch (OverflowException) {
1135 static int test_0_long_cast () {
1140 double d = System.Int64.MaxValue - 512.0;
1145 } catch (OverflowException) {
1152 double d = System.Int64.MaxValue - 513.0;
1157 } catch (OverflowException) {
1165 double d = System.Int64.MinValue - 1024.0;
1170 } catch (OverflowException) {
1177 double d = System.Int64.MinValue - 1025.0;
1182 } catch (OverflowException) {
1199 static int test_0_ulong_cast () {
1204 double d = System.UInt64.MaxValue - 1024.0;
1209 } catch (OverflowException) {
1216 double d = System.UInt64.MaxValue - 1025.0;
1221 } catch (OverflowException) {
1234 } catch (OverflowException) {
1246 } catch (OverflowException) {
1263 static int test_0_simple_double_casts () {
1265 double d = 0xffffffff;
1267 if ((uint)d != 4294967295)
1270 d = 0xffffffffffffffff;
1283 if ((ushort)d != 0xffff)
1286 if ((byte)d != 0xff)
1292 static int test_0_div_zero () {
1301 } catch (DivideByZeroException) {
1310 } catch (DivideByZeroException) {
1319 static int test_0_udiv_zero () {
1328 } catch (DivideByZeroException) {
1337 } catch (DivideByZeroException) {
1346 static int test_0_long_div_zero () {
1355 } catch (DivideByZeroException) {
1364 } catch (DivideByZeroException) {
1373 static int test_0_ulong_div_zero () {
1382 } catch (DivideByZeroException) {
1391 } catch (DivideByZeroException) {
1400 static int test_0_float_div_zero () {
1409 } catch (DivideByZeroException) {
1418 } catch (DivideByZeroException) {
1427 static int test_0_invalid_unbox () {
1430 object o = "Some string";
1434 // Illegal conversion; o contains a string not an int
1436 } catch (Exception e) {
1444 // Test that double[] can't be cast to double (bug #46027)
1445 static int test_0_invalid_unbox_arrays () {
1446 double[] d1 = { 1.0 };
1447 double[][] d2 = { d1 };
1451 foreach (double d in a) {
1455 catch (InvalidCastException e) {
1460 /* bug# 42190, at least mcs generates a leave for the return that
1461 * jumps out of multiple exception clauses: we used to execute just
1462 * one enclosing finally block.
1464 static int finally_level;
1465 static void do_something () {
1478 static int test_2_multiple_finally_clauses () {
1481 if (finally_level == 1)
1486 static int test_3_checked_cast_un () {
1487 ulong i = 0x8000000034000000;
1491 checked { j = (long)i; }
1492 } catch (OverflowException) {
1501 static int test_4_checked_cast () {
1505 unchecked { i = (long)0x8000000034000000;};
1507 checked { j = (ulong)i; }
1508 } catch (OverflowException) {
1517 static readonly int[] mul_dim_results = new int[] {
1518 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1519 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1523 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1524 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1525 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1528 static int test_0_multi_dim_array_access () {
1529 int [,] a = System.Array.CreateInstance (typeof (int),
1530 new int [] {3,6}, new int [] {2,2 }) as int[,];
1533 for (x = 0; x < 8; ++x) {
1534 for (y = 0; y < 9; ++y) {
1535 bool got_ex = false;
1542 if (result_idx >= mul_dim_results.Length)
1544 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1545 return result_idx + 1;
1551 if (result_idx == mul_dim_results.Length)
1556 static void helper_out_obj (out object o) {
1557 o = (object)"buddy";
1560 static void helper_out_string (out string o) {
1564 static int test_2_array_mismatch () {
1565 string[] a = { "hello", "world" };
1567 bool passed = false;
1570 helper_out_obj (out b [1]);
1571 } catch (ArrayTypeMismatchException) {
1576 helper_out_string (out a [1]);
1577 if (a [1] != "buddy")
1582 static int test_0_long_add_ovf () {
1587 l = 999999999999999999;
1593 } catch (OverflowException) {