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) {
1068 ulong ul = (long)(System.Int32.MaxValue) + 1;
1074 catch (OverflowException) {
1092 static int test_0_uint_cast () {
1098 double d = System.UInt32.MaxValue;
1103 } catch (OverflowException) {
1110 double d = System.UInt32.MaxValue + 1.0;
1115 } catch (OverflowException) {
1122 double d = System.UInt32.MinValue;
1127 } catch (OverflowException) {
1134 double d = System.UInt32.MinValue - 1.0;
1139 } catch (OverflowException) {
1146 l = System.UInt32.MaxValue;
1151 } catch (OverflowException) {
1158 l = System.UInt32.MaxValue + (long)1;
1163 } catch (OverflowException) {
1170 l = System.UInt32.MinValue;
1175 } catch (OverflowException) {
1182 l = System.UInt32.MinValue - (long)1;
1187 } catch (OverflowException) {
1200 catch (OverflowException) {
1217 static int test_0_long_cast () {
1222 double d = System.Int64.MaxValue - 512.0;
1227 } catch (OverflowException) {
1234 double d = System.Int64.MaxValue - 513.0;
1239 } catch (OverflowException) {
1246 double d = System.Int64.MinValue - 1024.0;
1251 } catch (OverflowException) {
1258 double d = System.Int64.MinValue - 1025.0;
1263 } catch (OverflowException) {
1280 static int test_0_ulong_cast () {
1285 * These tests depend on properties of x86 fp arithmetic so they won't work
1286 * on other platforms.
1291 double d = System.UInt64.MaxValue - 1024.0;
1296 } catch (OverflowException) {
1303 double d = System.UInt64.MaxValue - 1025.0;
1308 } catch (OverflowException) {
1321 } catch (OverflowException) {
1333 } catch (OverflowException) {
1354 catch (OverflowException) {
1361 int i = Int32.MinValue;
1367 catch (OverflowException) {
1376 static int test_0_simple_double_casts () {
1378 double d = 0xffffffff;
1380 if ((uint)d != 4294967295)
1384 * These tests depend on properties of x86 fp arithmetic so they won't work
1385 * on other platforms.
1388 d = 0xffffffffffffffff;
1402 if ((ushort)d != 0xffff)
1405 if ((byte)d != 0xff)
1411 static int test_0_div_zero () {
1420 } catch (DivideByZeroException) {
1429 } catch (DivideByZeroException) {
1440 } catch (DivideByZeroException) {
1441 /* wrong exception */
1442 } catch (ArithmeticException) {
1453 } catch (DivideByZeroException) {
1454 /* wrong exception */
1455 } catch (ArithmeticException) {
1464 static int return_55 () {
1468 static int test_0_cfold_div_zero () {
1469 // Test that constant folding doesn't cause division by zero exceptions
1470 if (return_55 () != return_55 ()) {
1489 static int test_0_udiv_zero () {
1498 } catch (DivideByZeroException) {
1507 } catch (DivideByZeroException) {
1516 static int test_0_long_div_zero () {
1525 } catch (DivideByZeroException) {
1534 } catch (DivideByZeroException) {
1545 } catch (DivideByZeroException) {
1546 /* wrong exception */
1547 } catch (ArithmeticException) {
1558 } catch (DivideByZeroException) {
1559 /* wrong exception */
1560 } catch (ArithmeticException) {
1569 static int test_0_ulong_div_zero () {
1578 } catch (DivideByZeroException) {
1587 } catch (DivideByZeroException) {
1596 static int test_0_float_div_zero () {
1605 } catch (DivideByZeroException) {
1614 } catch (DivideByZeroException) {
1623 static int test_0_invalid_unbox () {
1626 object o = "Some string";
1630 // Illegal conversion; o contains a string not an int
1632 } catch (Exception e) {
1640 // Test that double[] can't be cast to double (bug #46027)
1641 static int test_0_invalid_unbox_arrays () {
1642 double[] d1 = { 1.0 };
1643 double[][] d2 = { d1 };
1647 foreach (double d in a) {
1651 catch (InvalidCastException e) {
1656 /* bug# 42190, at least mcs generates a leave for the return that
1657 * jumps out of multiple exception clauses: we used to execute just
1658 * one enclosing finally block.
1660 static int finally_level;
1661 static void do_something () {
1674 static int test_2_multiple_finally_clauses () {
1677 if (finally_level == 1)
1682 static int test_3_checked_cast_un () {
1683 ulong i = 0x8000000034000000;
1687 checked { j = (long)i; }
1688 } catch (OverflowException) {
1697 static int test_4_checked_cast () {
1701 unchecked { i = (long)0x8000000034000000;};
1703 checked { j = (ulong)i; }
1704 } catch (OverflowException) {
1713 static readonly int[] mul_dim_results = new int[] {
1714 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1715 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1719 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1720 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1721 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1724 static int test_0_multi_dim_array_access () {
1725 int [,] a = System.Array.CreateInstance (typeof (int),
1726 new int [] {3,6}, new int [] {2,2 }) as int[,];
1729 for (x = 0; x < 8; ++x) {
1730 for (y = 0; y < 9; ++y) {
1731 bool got_ex = false;
1738 if (result_idx >= mul_dim_results.Length)
1740 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1741 return result_idx + 1;
1747 if (result_idx == mul_dim_results.Length)
1752 static void helper_out_obj (out object o) {
1753 o = (object)"buddy";
1756 static void helper_out_string (out string o) {
1760 static int test_2_array_mismatch () {
1761 string[] a = { "hello", "world" };
1763 bool passed = false;
1766 helper_out_obj (out b [1]);
1767 } catch (ArrayTypeMismatchException) {
1772 helper_out_string (out a [1]);
1773 if (a [1] != "buddy")
1778 static int test_0_ovf () {
1785 ulong a = UInt64.MaxValue - 1;
1795 ulong a = UInt64.MaxValue;
1805 long a = Int64.MaxValue - 1;
1814 long a = Int64.MaxValue;
1824 ulong a = UInt64.MaxValue - 1;
1833 ulong a = UInt64.MaxValue;
1843 long a = Int64.MinValue + 1;
1853 long a = Int64.MinValue;
1863 ulong a = UInt64.MinValue + 1;
1873 ulong a = UInt64.MinValue;
1883 int a = Int32.MinValue + 1;
1893 int a = Int32.MinValue;
1971 ulong a = 0xffffffffff;
1972 ulong t = a*0x0ffffff;
1981 ulong a = 0xffffffffff;
1982 ulong t = a*0x0fffffff;
1991 long a = Int64.MinValue;
2003 long b = Int64.MinValue;
2019 throw new Exception ("Ugh!");
2022 public static int DoSomething () {
2027 static int test_0_exception_in_cctor () {
2029 Broken.DoSomething ();
2031 catch (TypeInitializationException) {
2032 // This will only happen once even if --regression is used
2037 static int test_5_regalloc () {
2041 for (i = 0; i < 10; ++i) {
2043 throw new Exception ();
2051 // Check that variables written in catch clauses are volatile
2054 throw new Exception ();
2065 throw new Exception ();
2079 /* MarshalByRefObject prevents the methods from being inlined */
2080 class ThrowClass : MarshalByRefObject {
2081 public static void rethrow1 () {
2082 throw new Exception ();
2085 public static void rethrow2 () {
2090 static int test_0_rethrow_stacktrace () {
2091 // Check that rethrowing an exception preserves the original stack trace
2094 ThrowClass.rethrow2 ();
2096 catch (Exception ex) {
2097 // Check that each catch clause has its own exception variable
2098 // If not, the throw below will overwrite the exception used
2101 throw new DivideByZeroException ();
2103 catch (Exception foo) {
2109 catch (Exception ex) {
2110 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2118 class Face : IFace {}
2120 static int test_1_array_mismatch_2 () {
2122 object [] o = new Face [1];
2125 } catch (ArrayTypeMismatchException) {
2130 static int test_1_array_mismatch_3 () {
2132 object [] o = new IFace [1];
2135 } catch (ArrayTypeMismatchException) {
2140 static int test_1_array_mismatch_4 () {
2142 object [][] o = new Face [5] [];
2143 o [0] = new object [5];
2146 } catch (ArrayTypeMismatchException) {
2151 static int test_0_array_size () {
2156 int[] mem1 = new int [Int32.MaxValue];
2158 catch (OutOfMemoryException e) {
2166 int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2168 catch (OutOfMemoryException e) {
2178 int i, j, k, l, m, n;
2181 static IntPtr[] addr;
2183 static unsafe void throw_func (int i, S s) {
2184 addr [i] = new IntPtr (&i);
2185 throw new Exception ();
2188 /* Test that arguments are correctly popped off the stack during unwinding */
2189 static int test_0_stack_unwind () {
2190 addr = new IntPtr [1000];
2192 for (int j = 0; j < 1000; j++) {
2199 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;