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 () {
99 } catch (OverflowException) {
113 } catch (OverflowException) {
128 } catch (OverflowException) {
142 } catch (OverflowException) {
156 } catch (OverflowException) {
170 } catch (OverflowException) {
184 } catch (OverflowException) {
198 } catch (OverflowException) {
212 } catch (OverflowException) {
226 } catch (OverflowException) {
240 } catch (OverflowException) {
254 } catch (OverflowException) {
269 catch (OverflowException) {
280 static int test_0_sbyte_cast () {
292 } catch (OverflowException) {
306 } catch (OverflowException) {
320 } catch (OverflowException) {
334 } catch (OverflowException) {
348 } catch (OverflowException) {
362 } catch (OverflowException) {
376 } catch (OverflowException) {
390 } catch (OverflowException) {
404 } catch (OverflowException) {
418 } catch (OverflowException) {
432 } catch (OverflowException) {
446 } catch (OverflowException) {
460 } catch (OverflowException) {
474 } catch (OverflowException) {
488 } catch (OverflowException) {
502 } catch (OverflowException) {
516 } catch (OverflowException) {
530 } catch (OverflowException) {
544 } catch (OverflowException) {
558 } catch (OverflowException) {
569 static int test_0_ushort_cast () {
577 a = System.UInt16.MaxValue;
582 } catch (OverflowException) {
594 } catch (OverflowException) {
601 a = System.UInt16.MaxValue + 1;
606 } catch (OverflowException) {
618 } catch (OverflowException) {
630 } catch (OverflowException) {
637 double d = System.UInt16.MaxValue;
642 } catch (OverflowException) {
654 } catch (OverflowException) {
661 double d = System.UInt16.MaxValue + 1.0;
666 } catch (OverflowException) {
673 l = System.UInt16.MaxValue;
678 } catch (OverflowException) {
690 } catch (OverflowException) {
697 l = System.UInt16.MaxValue + 1;
702 } catch (OverflowException) {
714 } catch (OverflowException) {
726 } catch (OverflowException) {
735 static int test_0_short_cast () {
742 a = System.UInt16.MaxValue;
747 } catch (OverflowException) {
759 } catch (OverflowException) {
766 a = System.Int16.MaxValue + 1;
771 } catch (OverflowException) {
778 a = System.Int16.MinValue - 1;
783 } catch (OverflowException) {
795 } catch (OverflowException) {
802 a = System.Int16.MinValue;
807 } catch (OverflowException) {
814 a = System.Int16.MaxValue;
819 } catch (OverflowException) {
826 a = System.Int16.MaxValue + 1;
831 } catch (OverflowException) {
838 double d = System.Int16.MaxValue;
843 } catch (OverflowException) {
850 double d = System.Int16.MinValue;
855 } catch (OverflowException) {
862 double d = System.Int16.MaxValue + 1.0;
867 } catch (OverflowException) {
874 double d = System.Int16.MinValue - 1.0;
879 } catch (OverflowException) {
886 l = System.Int16.MaxValue + 1;
891 } catch (OverflowException) {
898 l = System.Int16.MaxValue;
903 } catch (OverflowException) {
910 l = System.Int16.MinValue - 1;
915 } catch (OverflowException) {
923 l = System.Int16.MinValue;
928 } catch (OverflowException) {
937 static int test_0_int_cast () {
943 double d = System.Int32.MaxValue + 1.0;
948 } catch (OverflowException) {
955 double d = System.Int32.MaxValue;
960 } catch (OverflowException) {
968 double d = System.Int32.MinValue;
973 } catch (OverflowException) {
981 double d = System.Int32.MinValue - 1.0;
986 } catch (OverflowException) {
993 l = System.Int32.MaxValue + (long)1;
998 } catch (OverflowException) {
1005 l = System.Int32.MaxValue;
1010 } catch (OverflowException) {
1018 l = System.Int32.MinValue;
1023 } catch (OverflowException) {
1031 l = System.Int32.MinValue - (long)1;
1036 } catch (OverflowException) {
1053 static int test_0_uint_cast () {
1059 double d = System.UInt32.MaxValue;
1064 } catch (OverflowException) {
1071 double d = System.UInt32.MaxValue + 1.0;
1076 } catch (OverflowException) {
1083 double d = System.UInt32.MinValue;
1088 } catch (OverflowException) {
1095 double d = System.UInt32.MinValue - 1.0;
1100 } catch (OverflowException) {
1107 l = System.UInt32.MaxValue;
1112 } catch (OverflowException) {
1119 l = System.UInt32.MaxValue + (long)1;
1124 } catch (OverflowException) {
1131 l = System.UInt32.MinValue;
1136 } catch (OverflowException) {
1143 l = System.UInt32.MinValue - (long)1;
1148 } catch (OverflowException) {
1165 static int test_0_long_cast () {
1170 double d = System.Int64.MaxValue - 512.0;
1175 } catch (OverflowException) {
1182 double d = System.Int64.MaxValue - 513.0;
1187 } catch (OverflowException) {
1195 double d = System.Int64.MinValue - 1024.0;
1200 } catch (OverflowException) {
1207 double d = System.Int64.MinValue - 1025.0;
1212 } catch (OverflowException) {
1229 static int test_0_ulong_cast () {
1234 double d = System.UInt64.MaxValue - 1024.0;
1239 } catch (OverflowException) {
1246 double d = System.UInt64.MaxValue - 1025.0;
1251 } catch (OverflowException) {
1264 } catch (OverflowException) {
1276 } catch (OverflowException) {
1297 catch (OverflowException) {
1304 int i = Int32.MinValue;
1310 catch (OverflowException) {
1319 static int test_0_simple_double_casts () {
1321 double d = 0xffffffff;
1323 if ((uint)d != 4294967295)
1326 d = 0xffffffffffffffff;
1339 if ((ushort)d != 0xffff)
1342 if ((byte)d != 0xff)
1348 static int test_0_div_zero () {
1357 } catch (DivideByZeroException) {
1366 } catch (DivideByZeroException) {
1377 } catch (DivideByZeroException) {
1378 /* wrong exception */
1379 } catch (ArithmeticException) {
1390 } catch (DivideByZeroException) {
1391 /* wrong exception */
1392 } catch (ArithmeticException) {
1401 static int return_55 () {
1405 static int test_0_cfold_div_zero () {
1406 // Test that constant folding doesn't cause division by zero exceptions
1407 if (return_55 () != return_55 ()) {
1426 static int test_0_udiv_zero () {
1435 } catch (DivideByZeroException) {
1444 } catch (DivideByZeroException) {
1453 static int test_0_long_div_zero () {
1462 } catch (DivideByZeroException) {
1471 } catch (DivideByZeroException) {
1482 } catch (DivideByZeroException) {
1483 /* wrong exception */
1484 } catch (ArithmeticException) {
1495 } catch (DivideByZeroException) {
1496 /* wrong exception */
1497 } catch (ArithmeticException) {
1506 static int test_0_ulong_div_zero () {
1515 } catch (DivideByZeroException) {
1524 } catch (DivideByZeroException) {
1533 static int test_0_float_div_zero () {
1542 } catch (DivideByZeroException) {
1551 } catch (DivideByZeroException) {
1560 static int test_0_invalid_unbox () {
1563 object o = "Some string";
1567 // Illegal conversion; o contains a string not an int
1569 } catch (Exception e) {
1577 // Test that double[] can't be cast to double (bug #46027)
1578 static int test_0_invalid_unbox_arrays () {
1579 double[] d1 = { 1.0 };
1580 double[][] d2 = { d1 };
1584 foreach (double d in a) {
1588 catch (InvalidCastException e) {
1593 /* bug# 42190, at least mcs generates a leave for the return that
1594 * jumps out of multiple exception clauses: we used to execute just
1595 * one enclosing finally block.
1597 static int finally_level;
1598 static void do_something () {
1611 static int test_2_multiple_finally_clauses () {
1614 if (finally_level == 1)
1619 static int test_3_checked_cast_un () {
1620 ulong i = 0x8000000034000000;
1624 checked { j = (long)i; }
1625 } catch (OverflowException) {
1634 static int test_4_checked_cast () {
1638 unchecked { i = (long)0x8000000034000000;};
1640 checked { j = (ulong)i; }
1641 } catch (OverflowException) {
1650 static readonly int[] mul_dim_results = new int[] {
1651 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1652 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1656 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1657 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1658 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1661 static int test_0_multi_dim_array_access () {
1662 int [,] a = System.Array.CreateInstance (typeof (int),
1663 new int [] {3,6}, new int [] {2,2 }) as int[,];
1666 for (x = 0; x < 8; ++x) {
1667 for (y = 0; y < 9; ++y) {
1668 bool got_ex = false;
1675 if (result_idx >= mul_dim_results.Length)
1677 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1678 return result_idx + 1;
1684 if (result_idx == mul_dim_results.Length)
1689 static void helper_out_obj (out object o) {
1690 o = (object)"buddy";
1693 static void helper_out_string (out string o) {
1697 static int test_2_array_mismatch () {
1698 string[] a = { "hello", "world" };
1700 bool passed = false;
1703 helper_out_obj (out b [1]);
1704 } catch (ArrayTypeMismatchException) {
1709 helper_out_string (out a [1]);
1710 if (a [1] != "buddy")
1715 static int test_0_ovf () {
1722 ulong a = UInt64.MaxValue - 1;
1732 ulong a = UInt64.MaxValue;
1742 long a = Int64.MaxValue - 1;
1751 long a = Int64.MaxValue;
1761 ulong a = UInt64.MaxValue - 1;
1770 ulong a = UInt64.MaxValue;
1780 long a = Int64.MinValue + 1;
1790 long a = Int64.MinValue;
1800 ulong a = UInt64.MinValue + 1;
1810 ulong a = UInt64.MinValue;
1820 int a = Int32.MinValue + 1;
1830 int a = Int32.MinValue;
1908 ulong a = 0xffffffffff;
1909 ulong t = a*0x0ffffff;
1918 ulong a = 0xffffffffff;
1919 ulong t = a*0x0fffffff;
1928 long a = Int64.MinValue;
1940 long b = Int64.MinValue;
1956 throw new Exception ("Ugh!");
1959 public static int DoSomething () {
1964 static int test_0_exception_in_cctor () {
1966 Broken.DoSomething ();
1968 catch (TypeInitializationException) {
1969 // This will only happen once even if --regression is used
1974 static int test_5_regalloc () {
1978 for (i = 0; i < 10; ++i) {
1980 throw new Exception ();
1988 // Check that variables written in catch clauses are volatile
1991 throw new Exception ();
2002 throw new Exception ();
2016 /* MarshalByRefObject prevents the methods from being inlined */
2017 class ThrowClass : MarshalByRefObject {
2018 public static void rethrow1 () {
2019 throw new Exception ();
2022 public static void rethrow2 () {
2027 static int test_0_rethrow_stacktrace () {
2028 // Check that rethrowing an exception preserves the original stack trace
2031 ThrowClass.rethrow2 ();
2033 catch (Exception ex) {
2037 catch (Exception ex) {
2038 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2046 class Face : IFace {}
2048 static int test_1_array_mismatch_2 () {
2050 object [] o = new Face [1];
2053 } catch (ArrayTypeMismatchException) {
2058 static int test_1_array_mismatch_3 () {
2060 object [] o = new IFace [1];
2063 } catch (ArrayTypeMismatchException) {
2068 static int test_1_array_mismatch_4 () {
2070 object [][] o = new Face [5] [];
2071 o [0] = new object [5];
2074 } catch (ArrayTypeMismatchException) {