2 using System.Reflection;
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * public 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
28 public static int Main () {
29 return TestDriver.RunTests (typeof (Tests));
32 public static int test_0_catch () {
33 Exception x = new Exception ();
37 } catch (Exception e) {
44 public static int test_0_finally_without_exc () {
49 } catch (Exception e) {
58 public static int test_0_finally () {
62 throw new Exception ();
63 } catch (Exception e) {
71 public static int test_0_nested_finally () {
86 public 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 public 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) {
573 catch (OverflowException) {
584 public static int test_0_ushort_cast () {
592 a = System.UInt16.MaxValue;
597 } catch (OverflowException) {
609 } catch (OverflowException) {
616 a = System.UInt16.MaxValue + 1;
621 } catch (OverflowException) {
633 } catch (OverflowException) {
645 } catch (OverflowException) {
652 double d = System.UInt16.MaxValue;
657 } catch (OverflowException) {
669 } catch (OverflowException) {
676 double d = System.UInt16.MaxValue + 1.0;
681 } catch (OverflowException) {
688 l = System.UInt16.MaxValue;
693 } catch (OverflowException) {
705 } catch (OverflowException) {
712 l = System.UInt16.MaxValue + 1;
717 } catch (OverflowException) {
729 } catch (OverflowException) {
741 } catch (OverflowException) {
750 public static int test_0_short_cast () {
757 a = System.UInt16.MaxValue;
762 } catch (OverflowException) {
774 } catch (OverflowException) {
781 a = System.Int16.MaxValue + 1;
786 } catch (OverflowException) {
793 a = System.Int16.MinValue - 1;
798 } catch (OverflowException) {
810 } catch (OverflowException) {
817 a = System.Int16.MinValue;
822 } catch (OverflowException) {
829 a = System.Int16.MaxValue;
834 } catch (OverflowException) {
841 a = System.Int16.MaxValue + 1;
846 } catch (OverflowException) {
853 double d = System.Int16.MaxValue;
858 } catch (OverflowException) {
865 double d = System.Int16.MinValue;
870 } catch (OverflowException) {
877 double d = System.Int16.MaxValue + 1.0;
882 } catch (OverflowException) {
889 double d = System.Int16.MinValue - 1.0;
894 } catch (OverflowException) {
901 l = System.Int16.MaxValue + 1;
906 } catch (OverflowException) {
913 l = System.Int16.MaxValue;
918 } catch (OverflowException) {
925 l = System.Int16.MinValue - 1;
930 } catch (OverflowException) {
938 l = System.Int16.MinValue;
943 } catch (OverflowException) {
950 l = 0x00000000ffffffff;
955 } catch (OverflowException) {
967 } catch (OverflowException) {
976 public static int test_0_int_cast () {
982 double d = System.Int32.MaxValue + 1.0;
987 } catch (OverflowException) {
994 double d = System.Int32.MaxValue;
999 } catch (OverflowException) {
1007 double d = System.Int32.MinValue;
1012 } catch (OverflowException) {
1020 double d = System.Int32.MinValue - 1.0;
1025 } catch (OverflowException) {
1032 l = System.Int32.MaxValue + (long)1;
1037 } catch (OverflowException) {
1044 l = System.Int32.MaxValue;
1049 } catch (OverflowException) {
1057 l = System.Int32.MinValue;
1062 } catch (OverflowException) {
1070 l = System.Int32.MinValue - (long)1;
1075 } catch (OverflowException) {
1082 uint ui = System.UInt32.MaxValue;
1088 catch (OverflowException) {
1095 ulong ul = (long)(System.Int32.MaxValue) + 1;
1101 catch (OverflowException) {
1119 public static int test_0_uint_cast () {
1125 double d = System.UInt32.MaxValue;
1130 } catch (OverflowException) {
1137 double d = System.UInt32.MaxValue + 1.0;
1142 } catch (OverflowException) {
1149 double d = System.UInt32.MinValue;
1154 } catch (OverflowException) {
1161 double d = System.UInt32.MinValue - 1.0;
1166 } catch (OverflowException) {
1173 l = System.UInt32.MaxValue;
1178 } catch (OverflowException) {
1185 l = System.UInt32.MaxValue + (long)1;
1190 } catch (OverflowException) {
1197 l = System.UInt32.MinValue;
1202 } catch (OverflowException) {
1209 l = System.UInt32.MinValue - (long)1;
1214 } catch (OverflowException) {
1227 catch (OverflowException) {
1244 public static int test_0_long_cast () {
1249 double d = System.Int64.MaxValue - 512.0;
1254 } catch (OverflowException) {
1261 double d = System.Int64.MaxValue - 513.0;
1266 } catch (OverflowException) {
1273 double d = System.Int64.MinValue - 1024.0;
1278 } catch (OverflowException) {
1285 double d = System.Int64.MinValue - 1025.0;
1290 } catch (OverflowException) {
1307 public static int test_0_ulong_cast () {
1312 * These tests depend on properties of x86 fp arithmetic so they won't work
1313 * on other platforms.
1318 double d = System.UInt64.MaxValue - 1024.0;
1323 } catch (OverflowException) {
1330 double d = System.UInt64.MaxValue - 1025.0;
1335 } catch (OverflowException) {
1348 } catch (OverflowException) {
1360 } catch (OverflowException) {
1381 catch (OverflowException) {
1388 int i = Int32.MinValue;
1394 catch (OverflowException) {
1403 public static int test_0_simple_double_casts () {
1405 double d = 0xffffffff;
1407 if ((uint)d != 4294967295)
1411 * These tests depend on properties of x86 fp arithmetic so they won't work
1412 * on other platforms.
1415 d = 0xffffffffffffffff;
1429 if ((ushort)d != 0xffff)
1432 if ((byte)d != 0xff)
1438 public static int test_0_div_zero () {
1447 } catch (DivideByZeroException) {
1456 } catch (DivideByZeroException) {
1467 } catch (DivideByZeroException) {
1468 /* wrong exception */
1469 } catch (ArithmeticException) {
1480 } catch (DivideByZeroException) {
1481 /* wrong exception */
1482 } catch (ArithmeticException) {
1491 public static int return_55 () {
1495 public static int test_0_cfold_div_zero () {
1496 // Test that constant folding doesn't cause division by zero exceptions
1497 if (return_55 () != return_55 ()) {
1516 public static int test_0_udiv_zero () {
1525 } catch (DivideByZeroException) {
1534 } catch (DivideByZeroException) {
1543 public static int test_0_long_div_zero () {
1552 } catch (DivideByZeroException) {
1561 } catch (DivideByZeroException) {
1572 } catch (DivideByZeroException) {
1573 /* wrong exception */
1574 } catch (ArithmeticException) {
1585 } catch (DivideByZeroException) {
1586 /* wrong exception */
1587 } catch (ArithmeticException) {
1596 public static int test_0_ulong_div_zero () {
1605 } catch (DivideByZeroException) {
1614 } catch (DivideByZeroException) {
1623 public static int test_0_float_div_zero () {
1632 } catch (DivideByZeroException) {
1641 } catch (DivideByZeroException) {
1650 public static int test_0_invalid_unbox () {
1653 object o = "Some string";
1657 // Illegal conversion; o contains a string not an int
1659 } catch (Exception e) {
1667 // Test that double[] can't be cast to double (bug #46027)
1668 public static int test_0_invalid_unbox_arrays () {
1669 double[] d1 = { 1.0 };
1670 double[][] d2 = { d1 };
1674 foreach (double d in a) {
1678 catch (InvalidCastException e) {
1683 /* bug# 42190, at least mcs generates a leave for the return that
1684 * jumps out of multiple exception clauses: we used to execute just
1685 * one enclosing finally block.
1687 public static int finally_level;
1688 static void do_something () {
1701 public static int test_2_multiple_finally_clauses () {
1704 if (finally_level == 1)
1709 public static int test_3_checked_cast_un () {
1710 ulong i = 0x8000000034000000;
1714 checked { j = (long)i; }
1715 } catch (OverflowException) {
1724 public static int test_4_checked_cast () {
1728 unchecked { i = (long)0x8000000034000000;};
1730 checked { j = (ulong)i; }
1731 } catch (OverflowException) {
1740 static readonly int[] mul_dim_results = new int[] {
1741 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1742 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1746 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1747 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1748 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1751 public static int test_0_multi_dim_array_access () {
1752 int [,] a = System.Array.CreateInstance (typeof (int),
1753 new int [] {3,6}, new int [] {2,2 }) as int[,];
1756 for (x = 0; x < 8; ++x) {
1757 for (y = 0; y < 9; ++y) {
1758 bool got_ex = false;
1765 if (result_idx >= mul_dim_results.Length)
1767 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1768 return result_idx + 1;
1774 if (result_idx == mul_dim_results.Length)
1779 static void helper_out_obj (out object o) {
1780 o = (object)"buddy";
1783 static void helper_out_string (out string o) {
1787 public static int test_2_array_mismatch () {
1788 string[] a = { "hello", "world" };
1790 bool passed = false;
1793 helper_out_obj (out b [1]);
1794 } catch (ArrayTypeMismatchException) {
1799 helper_out_string (out a [1]);
1800 if (a [1] != "buddy")
1805 public static int test_0_ovf () {
1812 ulong a = UInt64.MaxValue - 1;
1822 ulong a = UInt64.MaxValue;
1832 long a = Int64.MaxValue - 1;
1841 long a = Int64.MaxValue;
1851 ulong a = UInt64.MaxValue - 1;
1860 ulong a = UInt64.MaxValue;
1870 long a = Int64.MinValue + 1;
1880 long a = Int64.MinValue;
1890 ulong a = UInt64.MinValue + 1;
1900 ulong a = UInt64.MinValue;
1910 int a = Int32.MinValue + 1;
1920 int a = Int32.MinValue;
1998 ulong a = 0xffffffffff;
1999 ulong t = a*0x0ffffff;
2008 ulong a = 0xffffffffff;
2009 ulong t = a*0x0fffffff;
2018 long a = Int64.MinValue;
2030 long b = Int64.MinValue;
2043 public static int i;
2046 throw new Exception ("Ugh!");
2049 public static int DoSomething () {
2054 public static int test_0_exception_in_cctor () {
2056 Broken.DoSomething ();
2058 catch (TypeInitializationException) {
2059 // This will only happen once even if --regression is used
2064 public static int test_5_regalloc () {
2068 for (i = 0; i < 10; ++i) {
2070 throw new Exception ();
2078 // Check that variables written in catch clauses are volatile
2081 throw new Exception ();
2092 throw new Exception ();
2106 /* MarshalByRefObject prevents the methods from being inlined */
2107 class ThrowClass : MarshalByRefObject {
2108 public static void rethrow1 () {
2109 throw new Exception ();
2112 public static void rethrow2 () {
2117 public static int test_0_rethrow_stacktrace () {
2118 // Check that rethrowing an exception preserves the original stack trace
2121 ThrowClass.rethrow2 ();
2123 catch (Exception ex) {
2124 // Check that each catch clause has its own exception variable
2125 // If not, the throw below will overwrite the exception used
2128 throw new DivideByZeroException ();
2130 catch (Exception foo) {
2136 catch (Exception ex) {
2137 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2145 class Face : IFace {}
2147 public static int test_1_array_mismatch_2 () {
2149 object [] o = new Face [1];
2152 } catch (ArrayTypeMismatchException) {
2157 public static int test_1_array_mismatch_3 () {
2159 object [] o = new IFace [1];
2162 } catch (ArrayTypeMismatchException) {
2167 public static int test_1_array_mismatch_4 () {
2169 object [][] o = new Face [5] [];
2170 o [0] = new object [5];
2173 } catch (ArrayTypeMismatchException) {
2178 public static int test_0_array_size () {
2183 int[] mem1 = new int [Int32.MaxValue];
2185 catch (OutOfMemoryException e) {
2193 int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2195 catch (OutOfMemoryException e) {
2205 int i, j, k, l, m, n;
2208 static IntPtr[] addr;
2210 static unsafe void throw_func (int i, S s) {
2211 addr [i] = new IntPtr (&i);
2212 throw new Exception ();
2215 /* Test that arguments are correctly popped off the stack during unwinding */
2216 public static int test_0_stack_unwind () {
2217 addr = new IntPtr [1000];
2219 for (int j = 0; j < 1000; j++) {
2226 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
2229 public static int test_0_regress_73242 () {
2230 int [] arr = new int [10];
2231 for (int i = 0; i < 10; ++i)
2234 throw new Exception ();
2241 public static int test_0_nullref () {
2245 } catch (NullReferenceException e) {