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) {
1108 ulong ul = UInt64.MaxValue;
1114 catch (OverflowException) {
1131 public static int test_0_uint_cast () {
1137 double d = System.UInt32.MaxValue;
1142 } catch (OverflowException) {
1149 double d = System.UInt32.MaxValue + 1.0;
1154 } catch (OverflowException) {
1161 double d = System.UInt32.MinValue;
1166 } catch (OverflowException) {
1173 double d = System.UInt32.MinValue - 1.0;
1178 } catch (OverflowException) {
1185 l = System.UInt32.MaxValue;
1190 } catch (OverflowException) {
1197 l = System.UInt32.MaxValue + (long)1;
1202 } catch (OverflowException) {
1209 l = System.UInt32.MinValue;
1214 } catch (OverflowException) {
1221 l = System.UInt32.MinValue - (long)1;
1226 } catch (OverflowException) {
1239 catch (OverflowException) {
1256 public static int test_0_long_cast () {
1259 * These tests depend on properties of x86 fp arithmetic so they won't work
1260 * on other platforms.
1267 double d = System.Int64.MaxValue - 512.0;
1272 } catch (OverflowException) {
1279 double d = System.Int64.MaxValue - 513.0;
1284 } catch (OverflowException) {
1291 double d = System.Int64.MinValue - 1024.0;
1296 } catch (OverflowException) {
1303 double d = System.Int64.MinValue - 1025.0;
1308 } catch (OverflowException) {
1326 public static int test_0_ulong_cast () {
1331 * These tests depend on properties of x86 fp arithmetic so they won't work
1332 * on other platforms.
1337 double d = System.UInt64.MaxValue - 1024.0;
1342 } catch (OverflowException) {
1349 double d = System.UInt64.MaxValue - 1025.0;
1354 } catch (OverflowException) {
1367 } catch (OverflowException) {
1379 } catch (OverflowException) {
1400 catch (OverflowException) {
1407 int i = Int32.MinValue;
1413 catch (OverflowException) {
1422 public static int test_0_simple_double_casts () {
1424 double d = 0xffffffff;
1426 if ((uint)d != 4294967295)
1430 * These tests depend on properties of x86 fp arithmetic so they won't work
1431 * on other platforms.
1434 d = 0xffffffffffffffff;
1448 if ((ushort)d != 0xffff)
1451 if ((byte)d != 0xff)
1457 public static int test_0_div_zero () {
1466 } catch (DivideByZeroException) {
1475 } catch (DivideByZeroException) {
1486 } catch (DivideByZeroException) {
1487 /* wrong exception */
1488 } catch (ArithmeticException) {
1499 } catch (DivideByZeroException) {
1500 /* wrong exception */
1501 } catch (ArithmeticException) {
1510 public static int return_55 () {
1514 public static int test_0_cfold_div_zero () {
1515 // Test that constant folding doesn't cause division by zero exceptions
1516 if (return_55 () != return_55 ()) {
1535 public static int test_0_udiv_zero () {
1544 } catch (DivideByZeroException) {
1553 } catch (DivideByZeroException) {
1562 public static int test_0_long_div_zero () {
1571 } catch (DivideByZeroException) {
1580 } catch (DivideByZeroException) {
1591 } catch (DivideByZeroException) {
1592 /* wrong exception */
1593 } catch (ArithmeticException) {
1604 } catch (DivideByZeroException) {
1605 /* wrong exception */
1606 } catch (ArithmeticException) {
1615 public static int test_0_ulong_div_zero () {
1624 } catch (DivideByZeroException) {
1633 } catch (DivideByZeroException) {
1642 public static int test_0_float_div_zero () {
1651 } catch (DivideByZeroException) {
1660 } catch (DivideByZeroException) {
1669 public static int test_0_invalid_unbox () {
1672 object o = "Some string";
1676 // Illegal conversion; o contains a string not an int
1678 } catch (Exception e) {
1686 // Test that double[] can't be cast to double (bug #46027)
1687 public static int test_0_invalid_unbox_arrays () {
1688 double[] d1 = { 1.0 };
1689 double[][] d2 = { d1 };
1693 foreach (double d in a) {
1697 catch (InvalidCastException e) {
1702 /* bug# 42190, at least mcs generates a leave for the return that
1703 * jumps out of multiple exception clauses: we used to execute just
1704 * one enclosing finally block.
1706 public static int finally_level;
1707 static void do_something () {
1720 public static int test_2_multiple_finally_clauses () {
1723 if (finally_level == 1)
1728 public static int test_3_checked_cast_un () {
1729 ulong i = 0x8000000034000000;
1733 checked { j = (long)i; }
1734 } catch (OverflowException) {
1743 public static int test_4_checked_cast () {
1747 unchecked { i = (long)0x8000000034000000;};
1749 checked { j = (ulong)i; }
1750 } catch (OverflowException) {
1759 static readonly int[] mul_dim_results = new int[] {
1760 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1761 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1765 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1766 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1767 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1770 public static int test_0_multi_dim_array_access () {
1771 int [,] a = System.Array.CreateInstance (typeof (int),
1772 new int [] {3,6}, new int [] {2,2 }) as int[,];
1775 for (x = 0; x < 8; ++x) {
1776 for (y = 0; y < 9; ++y) {
1777 bool got_ex = false;
1784 if (result_idx >= mul_dim_results.Length)
1786 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1787 return result_idx + 1;
1793 if (result_idx == mul_dim_results.Length)
1798 static void helper_out_obj (out object o) {
1799 o = (object)"buddy";
1802 static void helper_out_string (out string o) {
1806 public static int test_2_array_mismatch () {
1807 string[] a = { "hello", "world" };
1809 bool passed = false;
1812 helper_out_obj (out b [1]);
1813 } catch (ArrayTypeMismatchException) {
1818 helper_out_string (out a [1]);
1819 if (a [1] != "buddy")
1824 public static int test_0_ovf1 () {
1829 ulong a = UInt64.MaxValue - 1;
1838 public static int test_1_ovf2 () {
1843 ulong a = UInt64.MaxValue;
1852 public static int test_0_ovf3 () {
1855 long a = Int64.MaxValue - 1;
1866 public static int test_1_ovf4 () {
1869 long a = Int64.MaxValue;
1880 public static int test_0_ovf5 () {
1883 ulong a = UInt64.MaxValue - 1;
1894 public static int test_1_ovf6 () {
1897 ulong a = UInt64.MaxValue;
1908 public static int test_0_ovf7 () {
1911 long a = Int64.MinValue + 1;
1922 public static int test_1_ovf8 () {
1925 long a = Int64.MinValue;
1936 public static int test_0_ovf9 () {
1939 ulong a = UInt64.MinValue + 1;
1950 public static int test_1_ovf10 () {
1953 ulong a = UInt64.MinValue;
1964 public static int test_0_ovf11 () {
1967 int a = Int32.MinValue + 1;
1978 public static int test_1_ovf12 () {
1981 int a = Int32.MinValue;
1992 public static int test_0_ovf13 () {
2006 public static int test_1_ovf14 () {
2020 public static int test_0_ovf15 () {
2034 public static int test_1_ovf16 () {
2048 public static int test_0_ovf17 () {
2060 public static int test_0_ovf18 () {
2074 public static int test_1_ovf19 () {
2088 public static int test_0_ovf20 () {
2093 ulong a = 0xffffffffff;
2094 ulong t = a*0x0ffffff;
2102 public static int test_1_ovf21 () {
2105 ulong a = 0xffffffffff;
2108 ulong t = a*0x0fffffff;
2116 public static int test_1_ovf22 () {
2119 long a = Int64.MinValue;
2131 public static int test_1_ovf23 () {
2135 long b = Int64.MinValue;
2147 public static int i;
2150 throw new Exception ("Ugh!");
2153 public static int DoSomething () {
2158 public static int test_0_exception_in_cctor () {
2160 Broken.DoSomething ();
2162 catch (TypeInitializationException) {
2163 // This will only happen once even if --regression is used
2168 public static int test_5_regalloc () {
2172 for (i = 0; i < 10; ++i) {
2174 throw new Exception ();
2182 // Check that variables written in catch clauses are volatile
2185 throw new Exception ();
2196 throw new Exception ();
2210 /* MarshalByRefObject prevents the methods from being inlined */
2211 class ThrowClass : MarshalByRefObject {
2212 public static void rethrow1 () {
2213 throw new Exception ();
2216 public static void rethrow2 () {
2221 public static int test_0_rethrow_stacktrace () {
2222 // Check that rethrowing an exception preserves the original stack trace
2225 ThrowClass.rethrow2 ();
2227 catch (Exception ex) {
2228 // Check that each catch clause has its own exception variable
2229 // If not, the throw below will overwrite the exception used
2232 throw new DivideByZeroException ();
2234 catch (Exception foo) {
2240 catch (Exception ex) {
2241 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2249 class Face : IFace {}
2251 public static int test_1_array_mismatch_2 () {
2253 object [] o = new Face [1];
2256 } catch (ArrayTypeMismatchException) {
2261 public static int test_1_array_mismatch_3 () {
2263 object [] o = new IFace [1];
2266 } catch (ArrayTypeMismatchException) {
2271 public static int test_1_array_mismatch_4 () {
2273 object [][] o = new Face [5] [];
2274 o [0] = new object [5];
2277 } catch (ArrayTypeMismatchException) {
2282 public static int test_0_array_size () {
2287 int[] mem1 = new int [Int32.MaxValue];
2289 catch (OutOfMemoryException e) {
2297 int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2299 catch (OutOfMemoryException e) {
2309 int i, j, k, l, m, n;
2312 static IntPtr[] addr;
2314 static unsafe void throw_func (int i, S s) {
2315 addr [i] = new IntPtr (&i);
2316 throw new Exception ();
2319 /* Test that arguments are correctly popped off the stack during unwinding */
2320 public static int test_0_stack_unwind () {
2321 addr = new IntPtr [1000];
2323 for (int j = 0; j < 1000; j++) {
2330 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
2333 public static int test_0_regress_73242 () {
2334 int [] arr = new int [10];
2335 for (int i = 0; i < 10; ++i)
2338 throw new Exception ();
2345 public static int test_0_nullref () {
2349 } catch (NullReferenceException e) {
2356 public static int test_0_throw_to_branch_opt_outer_clause () {
2361 string [] files = new string[1];
2363 string s = files[2];
2370 return (i == 1) ? 0 : 1;