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) {
1232 double d = System.Int64.MinValue - 1024.0;
1237 } catch (OverflowException) {
1244 double d = System.Int64.MinValue - 1025.0;
1249 } catch (OverflowException) {
1266 static int test_0_ulong_cast () {
1271 * These tests depend on properties of x86 fp arithmetic so they won't work
1272 * on other platforms.
1277 double d = System.UInt64.MaxValue - 1024.0;
1282 } catch (OverflowException) {
1289 double d = System.UInt64.MaxValue - 1025.0;
1294 } catch (OverflowException) {
1307 } catch (OverflowException) {
1319 } catch (OverflowException) {
1340 catch (OverflowException) {
1347 int i = Int32.MinValue;
1353 catch (OverflowException) {
1362 static int test_0_simple_double_casts () {
1364 double d = 0xffffffff;
1366 if ((uint)d != 4294967295)
1370 * These tests depend on properties of x86 fp arithmetic so they won't work
1371 * on other platforms.
1374 d = 0xffffffffffffffff;
1388 if ((ushort)d != 0xffff)
1391 if ((byte)d != 0xff)
1397 static int test_0_div_zero () {
1406 } catch (DivideByZeroException) {
1415 } catch (DivideByZeroException) {
1426 } catch (DivideByZeroException) {
1427 /* wrong exception */
1428 } catch (ArithmeticException) {
1439 } catch (DivideByZeroException) {
1440 /* wrong exception */
1441 } catch (ArithmeticException) {
1450 static int return_55 () {
1454 static int test_0_cfold_div_zero () {
1455 // Test that constant folding doesn't cause division by zero exceptions
1456 if (return_55 () != return_55 ()) {
1475 static int test_0_udiv_zero () {
1484 } catch (DivideByZeroException) {
1493 } catch (DivideByZeroException) {
1502 static int test_0_long_div_zero () {
1511 } catch (DivideByZeroException) {
1520 } catch (DivideByZeroException) {
1531 } catch (DivideByZeroException) {
1532 /* wrong exception */
1533 } catch (ArithmeticException) {
1544 } catch (DivideByZeroException) {
1545 /* wrong exception */
1546 } catch (ArithmeticException) {
1555 static int test_0_ulong_div_zero () {
1564 } catch (DivideByZeroException) {
1573 } catch (DivideByZeroException) {
1582 static int test_0_float_div_zero () {
1591 } catch (DivideByZeroException) {
1600 } catch (DivideByZeroException) {
1609 static int test_0_invalid_unbox () {
1612 object o = "Some string";
1616 // Illegal conversion; o contains a string not an int
1618 } catch (Exception e) {
1626 // Test that double[] can't be cast to double (bug #46027)
1627 static int test_0_invalid_unbox_arrays () {
1628 double[] d1 = { 1.0 };
1629 double[][] d2 = { d1 };
1633 foreach (double d in a) {
1637 catch (InvalidCastException e) {
1642 /* bug# 42190, at least mcs generates a leave for the return that
1643 * jumps out of multiple exception clauses: we used to execute just
1644 * one enclosing finally block.
1646 static int finally_level;
1647 static void do_something () {
1660 static int test_2_multiple_finally_clauses () {
1663 if (finally_level == 1)
1668 static int test_3_checked_cast_un () {
1669 ulong i = 0x8000000034000000;
1673 checked { j = (long)i; }
1674 } catch (OverflowException) {
1683 static int test_4_checked_cast () {
1687 unchecked { i = (long)0x8000000034000000;};
1689 checked { j = (ulong)i; }
1690 } catch (OverflowException) {
1699 static readonly int[] mul_dim_results = new int[] {
1700 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1701 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1705 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1706 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1707 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1710 static int test_0_multi_dim_array_access () {
1711 int [,] a = System.Array.CreateInstance (typeof (int),
1712 new int [] {3,6}, new int [] {2,2 }) as int[,];
1715 for (x = 0; x < 8; ++x) {
1716 for (y = 0; y < 9; ++y) {
1717 bool got_ex = false;
1724 if (result_idx >= mul_dim_results.Length)
1726 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1727 return result_idx + 1;
1733 if (result_idx == mul_dim_results.Length)
1738 static void helper_out_obj (out object o) {
1739 o = (object)"buddy";
1742 static void helper_out_string (out string o) {
1746 static int test_2_array_mismatch () {
1747 string[] a = { "hello", "world" };
1749 bool passed = false;
1752 helper_out_obj (out b [1]);
1753 } catch (ArrayTypeMismatchException) {
1758 helper_out_string (out a [1]);
1759 if (a [1] != "buddy")
1764 static int test_0_ovf () {
1771 ulong a = UInt64.MaxValue - 1;
1781 ulong a = UInt64.MaxValue;
1791 long a = Int64.MaxValue - 1;
1800 long a = Int64.MaxValue;
1810 ulong a = UInt64.MaxValue - 1;
1819 ulong a = UInt64.MaxValue;
1829 long a = Int64.MinValue + 1;
1839 long a = Int64.MinValue;
1849 ulong a = UInt64.MinValue + 1;
1859 ulong a = UInt64.MinValue;
1869 int a = Int32.MinValue + 1;
1879 int a = Int32.MinValue;
1957 ulong a = 0xffffffffff;
1958 ulong t = a*0x0ffffff;
1967 ulong a = 0xffffffffff;
1968 ulong t = a*0x0fffffff;
1977 long a = Int64.MinValue;
1989 long b = Int64.MinValue;
2005 throw new Exception ("Ugh!");
2008 public static int DoSomething () {
2013 static int test_0_exception_in_cctor () {
2015 Broken.DoSomething ();
2017 catch (TypeInitializationException) {
2018 // This will only happen once even if --regression is used
2023 static int test_5_regalloc () {
2027 for (i = 0; i < 10; ++i) {
2029 throw new Exception ();
2037 // Check that variables written in catch clauses are volatile
2040 throw new Exception ();
2051 throw new Exception ();
2065 /* MarshalByRefObject prevents the methods from being inlined */
2066 class ThrowClass : MarshalByRefObject {
2067 public static void rethrow1 () {
2068 throw new Exception ();
2071 public static void rethrow2 () {
2076 static int test_0_rethrow_stacktrace () {
2077 // Check that rethrowing an exception preserves the original stack trace
2080 ThrowClass.rethrow2 ();
2082 catch (Exception ex) {
2086 catch (Exception ex) {
2087 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2095 class Face : IFace {}
2097 static int test_1_array_mismatch_2 () {
2099 object [] o = new Face [1];
2102 } catch (ArrayTypeMismatchException) {
2107 static int test_1_array_mismatch_3 () {
2109 object [] o = new IFace [1];
2112 } catch (ArrayTypeMismatchException) {
2117 static int test_1_array_mismatch_4 () {
2119 object [][] o = new Face [5] [];
2120 o [0] = new object [5];
2123 } catch (ArrayTypeMismatchException) {
2128 static int test_0_array_size () {
2133 int[] mem1 = new int [Int32.MaxValue];
2135 catch (OutOfMemoryException e) {
2143 int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2145 catch (OutOfMemoryException e) {
2155 int i, j, k, l, m, n;
2158 static IntPtr[] addr;
2160 static unsafe void throw_func (int i, S s) {
2161 addr [i] = new IntPtr (&i);
2162 throw new Exception ();
2165 /* Test that arguments are correctly popped off the stack during unwinding */
2166 static int test_0_stack_unwind () {
2167 addr = new IntPtr [1000];
2169 for (int j = 0; j < 1000; j++) {
2176 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;