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) {
1043 uint ui = System.UInt32.MaxValue;
1049 catch (OverflowException) {
1066 static int test_0_uint_cast () {
1072 double d = System.UInt32.MaxValue;
1077 } catch (OverflowException) {
1084 double d = System.UInt32.MaxValue + 1.0;
1089 } catch (OverflowException) {
1096 double d = System.UInt32.MinValue;
1101 } catch (OverflowException) {
1108 double d = System.UInt32.MinValue - 1.0;
1113 } catch (OverflowException) {
1120 l = System.UInt32.MaxValue;
1125 } catch (OverflowException) {
1132 l = System.UInt32.MaxValue + (long)1;
1137 } catch (OverflowException) {
1144 l = System.UInt32.MinValue;
1149 } catch (OverflowException) {
1156 l = System.UInt32.MinValue - (long)1;
1161 } catch (OverflowException) {
1174 catch (OverflowException) {
1191 static int test_0_long_cast () {
1196 double d = System.Int64.MaxValue - 512.0;
1201 } catch (OverflowException) {
1208 double d = System.Int64.MaxValue - 513.0;
1213 } catch (OverflowException) {
1221 double d = System.Int64.MinValue - 1024.0;
1226 } catch (OverflowException) {
1233 double d = System.Int64.MinValue - 1025.0;
1238 } catch (OverflowException) {
1255 static int test_0_ulong_cast () {
1260 double d = System.UInt64.MaxValue - 1024.0;
1265 } catch (OverflowException) {
1272 double d = System.UInt64.MaxValue - 1025.0;
1277 } catch (OverflowException) {
1290 } catch (OverflowException) {
1302 } catch (OverflowException) {
1323 catch (OverflowException) {
1330 int i = Int32.MinValue;
1336 catch (OverflowException) {
1345 static int test_0_simple_double_casts () {
1347 double d = 0xffffffff;
1349 if ((uint)d != 4294967295)
1352 d = 0xffffffffffffffff;
1365 if ((ushort)d != 0xffff)
1368 if ((byte)d != 0xff)
1374 static int test_0_div_zero () {
1383 } catch (DivideByZeroException) {
1392 } catch (DivideByZeroException) {
1403 } catch (DivideByZeroException) {
1404 /* wrong exception */
1405 } catch (ArithmeticException) {
1416 } catch (DivideByZeroException) {
1417 /* wrong exception */
1418 } catch (ArithmeticException) {
1427 static int return_55 () {
1431 static int test_0_cfold_div_zero () {
1432 // Test that constant folding doesn't cause division by zero exceptions
1433 if (return_55 () != return_55 ()) {
1452 static int test_0_udiv_zero () {
1461 } catch (DivideByZeroException) {
1470 } catch (DivideByZeroException) {
1479 static int test_0_long_div_zero () {
1488 } catch (DivideByZeroException) {
1497 } catch (DivideByZeroException) {
1508 } catch (DivideByZeroException) {
1509 /* wrong exception */
1510 } catch (ArithmeticException) {
1521 } catch (DivideByZeroException) {
1522 /* wrong exception */
1523 } catch (ArithmeticException) {
1532 static int test_0_ulong_div_zero () {
1541 } catch (DivideByZeroException) {
1550 } catch (DivideByZeroException) {
1559 static int test_0_float_div_zero () {
1568 } catch (DivideByZeroException) {
1577 } catch (DivideByZeroException) {
1586 static int test_0_invalid_unbox () {
1589 object o = "Some string";
1593 // Illegal conversion; o contains a string not an int
1595 } catch (Exception e) {
1603 // Test that double[] can't be cast to double (bug #46027)
1604 static int test_0_invalid_unbox_arrays () {
1605 double[] d1 = { 1.0 };
1606 double[][] d2 = { d1 };
1610 foreach (double d in a) {
1614 catch (InvalidCastException e) {
1619 /* bug# 42190, at least mcs generates a leave for the return that
1620 * jumps out of multiple exception clauses: we used to execute just
1621 * one enclosing finally block.
1623 static int finally_level;
1624 static void do_something () {
1637 static int test_2_multiple_finally_clauses () {
1640 if (finally_level == 1)
1645 static int test_3_checked_cast_un () {
1646 ulong i = 0x8000000034000000;
1650 checked { j = (long)i; }
1651 } catch (OverflowException) {
1660 static int test_4_checked_cast () {
1664 unchecked { i = (long)0x8000000034000000;};
1666 checked { j = (ulong)i; }
1667 } catch (OverflowException) {
1676 static readonly int[] mul_dim_results = new int[] {
1677 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1678 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1682 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1683 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1684 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1687 static int test_0_multi_dim_array_access () {
1688 int [,] a = System.Array.CreateInstance (typeof (int),
1689 new int [] {3,6}, new int [] {2,2 }) as int[,];
1692 for (x = 0; x < 8; ++x) {
1693 for (y = 0; y < 9; ++y) {
1694 bool got_ex = false;
1701 if (result_idx >= mul_dim_results.Length)
1703 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1704 return result_idx + 1;
1710 if (result_idx == mul_dim_results.Length)
1715 static void helper_out_obj (out object o) {
1716 o = (object)"buddy";
1719 static void helper_out_string (out string o) {
1723 static int test_2_array_mismatch () {
1724 string[] a = { "hello", "world" };
1726 bool passed = false;
1729 helper_out_obj (out b [1]);
1730 } catch (ArrayTypeMismatchException) {
1735 helper_out_string (out a [1]);
1736 if (a [1] != "buddy")
1741 static int test_0_ovf () {
1748 ulong a = UInt64.MaxValue - 1;
1758 ulong a = UInt64.MaxValue;
1768 long a = Int64.MaxValue - 1;
1777 long a = Int64.MaxValue;
1787 ulong a = UInt64.MaxValue - 1;
1796 ulong a = UInt64.MaxValue;
1806 long a = Int64.MinValue + 1;
1816 long a = Int64.MinValue;
1826 ulong a = UInt64.MinValue + 1;
1836 ulong a = UInt64.MinValue;
1846 int a = Int32.MinValue + 1;
1856 int a = Int32.MinValue;
1934 ulong a = 0xffffffffff;
1935 ulong t = a*0x0ffffff;
1944 ulong a = 0xffffffffff;
1945 ulong t = a*0x0fffffff;
1954 long a = Int64.MinValue;
1966 long b = Int64.MinValue;
1982 throw new Exception ("Ugh!");
1985 public static int DoSomething () {
1990 static int test_0_exception_in_cctor () {
1992 Broken.DoSomething ();
1994 catch (TypeInitializationException) {
1995 // This will only happen once even if --regression is used
2000 static int test_5_regalloc () {
2004 for (i = 0; i < 10; ++i) {
2006 throw new Exception ();
2014 // Check that variables written in catch clauses are volatile
2017 throw new Exception ();
2028 throw new Exception ();
2042 /* MarshalByRefObject prevents the methods from being inlined */
2043 class ThrowClass : MarshalByRefObject {
2044 public static void rethrow1 () {
2045 throw new Exception ();
2048 public static void rethrow2 () {
2053 static int test_0_rethrow_stacktrace () {
2054 // Check that rethrowing an exception preserves the original stack trace
2057 ThrowClass.rethrow2 ();
2059 catch (Exception ex) {
2063 catch (Exception ex) {
2064 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2072 class Face : IFace {}
2074 static int test_1_array_mismatch_2 () {
2076 object [] o = new Face [1];
2079 } catch (ArrayTypeMismatchException) {
2084 static int test_1_array_mismatch_3 () {
2086 object [] o = new IFace [1];
2089 } catch (ArrayTypeMismatchException) {
2094 static int test_1_array_mismatch_4 () {
2096 object [][] o = new Face [5] [];
2097 o [0] = new object [5];
2100 } catch (ArrayTypeMismatchException) {