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) {
935 l = 0x00000000ffffffff;
940 } catch (OverflowException) {
949 static int test_0_int_cast () {
955 double d = System.Int32.MaxValue + 1.0;
960 } catch (OverflowException) {
967 double d = System.Int32.MaxValue;
972 } catch (OverflowException) {
980 double d = System.Int32.MinValue;
985 } catch (OverflowException) {
993 double d = System.Int32.MinValue - 1.0;
998 } catch (OverflowException) {
1005 l = System.Int32.MaxValue + (long)1;
1010 } catch (OverflowException) {
1017 l = System.Int32.MaxValue;
1022 } catch (OverflowException) {
1030 l = System.Int32.MinValue;
1035 } catch (OverflowException) {
1043 l = System.Int32.MinValue - (long)1;
1048 } catch (OverflowException) {
1055 uint ui = System.UInt32.MaxValue;
1061 catch (OverflowException) {
1078 static int test_0_uint_cast () {
1084 double d = System.UInt32.MaxValue;
1089 } catch (OverflowException) {
1096 double d = System.UInt32.MaxValue + 1.0;
1101 } catch (OverflowException) {
1108 double d = System.UInt32.MinValue;
1113 } catch (OverflowException) {
1120 double d = System.UInt32.MinValue - 1.0;
1125 } catch (OverflowException) {
1132 l = System.UInt32.MaxValue;
1137 } catch (OverflowException) {
1144 l = System.UInt32.MaxValue + (long)1;
1149 } catch (OverflowException) {
1156 l = System.UInt32.MinValue;
1161 } catch (OverflowException) {
1168 l = System.UInt32.MinValue - (long)1;
1173 } catch (OverflowException) {
1186 catch (OverflowException) {
1203 static int test_0_long_cast () {
1208 double d = System.Int64.MaxValue - 512.0;
1213 } catch (OverflowException) {
1220 double d = System.Int64.MaxValue - 513.0;
1225 } catch (OverflowException) {
1233 double d = System.Int64.MinValue - 1024.0;
1238 } catch (OverflowException) {
1245 double d = System.Int64.MinValue - 1025.0;
1250 } catch (OverflowException) {
1267 static int test_0_ulong_cast () {
1272 double d = System.UInt64.MaxValue - 1024.0;
1277 } catch (OverflowException) {
1284 double d = System.UInt64.MaxValue - 1025.0;
1289 } catch (OverflowException) {
1302 } catch (OverflowException) {
1314 } catch (OverflowException) {
1335 catch (OverflowException) {
1342 int i = Int32.MinValue;
1348 catch (OverflowException) {
1357 static int test_0_simple_double_casts () {
1359 double d = 0xffffffff;
1361 if ((uint)d != 4294967295)
1364 d = 0xffffffffffffffff;
1377 if ((ushort)d != 0xffff)
1380 if ((byte)d != 0xff)
1386 static int test_0_div_zero () {
1395 } catch (DivideByZeroException) {
1404 } catch (DivideByZeroException) {
1415 } catch (DivideByZeroException) {
1416 /* wrong exception */
1417 } catch (ArithmeticException) {
1428 } catch (DivideByZeroException) {
1429 /* wrong exception */
1430 } catch (ArithmeticException) {
1439 static int return_55 () {
1443 static int test_0_cfold_div_zero () {
1444 // Test that constant folding doesn't cause division by zero exceptions
1445 if (return_55 () != return_55 ()) {
1464 static int test_0_udiv_zero () {
1473 } catch (DivideByZeroException) {
1482 } catch (DivideByZeroException) {
1491 static int test_0_long_div_zero () {
1500 } catch (DivideByZeroException) {
1509 } catch (DivideByZeroException) {
1520 } catch (DivideByZeroException) {
1521 /* wrong exception */
1522 } catch (ArithmeticException) {
1533 } catch (DivideByZeroException) {
1534 /* wrong exception */
1535 } catch (ArithmeticException) {
1544 static int test_0_ulong_div_zero () {
1553 } catch (DivideByZeroException) {
1562 } catch (DivideByZeroException) {
1571 static int test_0_float_div_zero () {
1580 } catch (DivideByZeroException) {
1589 } catch (DivideByZeroException) {
1598 static int test_0_invalid_unbox () {
1601 object o = "Some string";
1605 // Illegal conversion; o contains a string not an int
1607 } catch (Exception e) {
1615 // Test that double[] can't be cast to double (bug #46027)
1616 static int test_0_invalid_unbox_arrays () {
1617 double[] d1 = { 1.0 };
1618 double[][] d2 = { d1 };
1622 foreach (double d in a) {
1626 catch (InvalidCastException e) {
1631 /* bug# 42190, at least mcs generates a leave for the return that
1632 * jumps out of multiple exception clauses: we used to execute just
1633 * one enclosing finally block.
1635 static int finally_level;
1636 static void do_something () {
1649 static int test_2_multiple_finally_clauses () {
1652 if (finally_level == 1)
1657 static int test_3_checked_cast_un () {
1658 ulong i = 0x8000000034000000;
1662 checked { j = (long)i; }
1663 } catch (OverflowException) {
1672 static int test_4_checked_cast () {
1676 unchecked { i = (long)0x8000000034000000;};
1678 checked { j = (ulong)i; }
1679 } catch (OverflowException) {
1688 static readonly int[] mul_dim_results = new int[] {
1689 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1690 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1694 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1695 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1696 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1699 static int test_0_multi_dim_array_access () {
1700 int [,] a = System.Array.CreateInstance (typeof (int),
1701 new int [] {3,6}, new int [] {2,2 }) as int[,];
1704 for (x = 0; x < 8; ++x) {
1705 for (y = 0; y < 9; ++y) {
1706 bool got_ex = false;
1713 if (result_idx >= mul_dim_results.Length)
1715 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1716 return result_idx + 1;
1722 if (result_idx == mul_dim_results.Length)
1727 static void helper_out_obj (out object o) {
1728 o = (object)"buddy";
1731 static void helper_out_string (out string o) {
1735 static int test_2_array_mismatch () {
1736 string[] a = { "hello", "world" };
1738 bool passed = false;
1741 helper_out_obj (out b [1]);
1742 } catch (ArrayTypeMismatchException) {
1747 helper_out_string (out a [1]);
1748 if (a [1] != "buddy")
1753 static int test_0_ovf () {
1760 ulong a = UInt64.MaxValue - 1;
1770 ulong a = UInt64.MaxValue;
1780 long a = Int64.MaxValue - 1;
1789 long a = Int64.MaxValue;
1799 ulong a = UInt64.MaxValue - 1;
1808 ulong a = UInt64.MaxValue;
1818 long a = Int64.MinValue + 1;
1828 long a = Int64.MinValue;
1838 ulong a = UInt64.MinValue + 1;
1848 ulong a = UInt64.MinValue;
1858 int a = Int32.MinValue + 1;
1868 int a = Int32.MinValue;
1946 ulong a = 0xffffffffff;
1947 ulong t = a*0x0ffffff;
1956 ulong a = 0xffffffffff;
1957 ulong t = a*0x0fffffff;
1966 long a = Int64.MinValue;
1978 long b = Int64.MinValue;
1994 throw new Exception ("Ugh!");
1997 public static int DoSomething () {
2002 static int test_0_exception_in_cctor () {
2004 Broken.DoSomething ();
2006 catch (TypeInitializationException) {
2007 // This will only happen once even if --regression is used
2012 static int test_5_regalloc () {
2016 for (i = 0; i < 10; ++i) {
2018 throw new Exception ();
2026 // Check that variables written in catch clauses are volatile
2029 throw new Exception ();
2040 throw new Exception ();
2054 /* MarshalByRefObject prevents the methods from being inlined */
2055 class ThrowClass : MarshalByRefObject {
2056 public static void rethrow1 () {
2057 throw new Exception ();
2060 public static void rethrow2 () {
2065 static int test_0_rethrow_stacktrace () {
2066 // Check that rethrowing an exception preserves the original stack trace
2069 ThrowClass.rethrow2 ();
2071 catch (Exception ex) {
2075 catch (Exception ex) {
2076 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2084 class Face : IFace {}
2086 static int test_1_array_mismatch_2 () {
2088 object [] o = new Face [1];
2091 } catch (ArrayTypeMismatchException) {
2096 static int test_1_array_mismatch_3 () {
2098 object [] o = new IFace [1];
2101 } catch (ArrayTypeMismatchException) {
2106 static int test_1_array_mismatch_4 () {
2108 object [][] o = new Face [5] [];
2109 o [0] = new object [5];
2112 } catch (ArrayTypeMismatchException) {
2117 static int test_0_array_size () {
2122 int[] mem1 = new int [Int32.MaxValue];
2124 catch (OutOfMemoryException e) {
2132 int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2134 catch (OutOfMemoryException e) {
2144 int i, j, k, l, m, n;
2147 static IntPtr[] addr;
2149 static unsafe void throw_func (int i, S s) {
2150 addr [i] = new IntPtr (&i);
2151 throw new Exception ();
2154 /* Test that arguments are correctly popped off the stack during unwinding */
2155 static int test_0_stack_unwind () {
2156 addr = new IntPtr [1000];
2158 for (int j = 0; j < 1000; j++) {
2165 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;