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 () {
1247 * These tests depend on properties of x86 fp arithmetic so they won't work
1248 * on other platforms.
1255 double d = System.Int64.MaxValue - 512.0;
1260 } catch (OverflowException) {
1267 double d = System.Int64.MaxValue - 513.0;
1272 } catch (OverflowException) {
1279 double d = System.Int64.MinValue - 1024.0;
1284 } catch (OverflowException) {
1291 double d = System.Int64.MinValue - 1025.0;
1296 } catch (OverflowException) {
1314 public static int test_0_ulong_cast () {
1319 * These tests depend on properties of x86 fp arithmetic so they won't work
1320 * on other platforms.
1325 double d = System.UInt64.MaxValue - 1024.0;
1330 } catch (OverflowException) {
1337 double d = System.UInt64.MaxValue - 1025.0;
1342 } catch (OverflowException) {
1355 } catch (OverflowException) {
1367 } catch (OverflowException) {
1388 catch (OverflowException) {
1395 int i = Int32.MinValue;
1401 catch (OverflowException) {
1410 public static int test_0_simple_double_casts () {
1412 double d = 0xffffffff;
1414 if ((uint)d != 4294967295)
1418 * These tests depend on properties of x86 fp arithmetic so they won't work
1419 * on other platforms.
1422 d = 0xffffffffffffffff;
1436 if ((ushort)d != 0xffff)
1439 if ((byte)d != 0xff)
1445 public static int test_0_div_zero () {
1454 } catch (DivideByZeroException) {
1463 } catch (DivideByZeroException) {
1474 } catch (DivideByZeroException) {
1475 /* wrong exception */
1476 } catch (ArithmeticException) {
1487 } catch (DivideByZeroException) {
1488 /* wrong exception */
1489 } catch (ArithmeticException) {
1498 public static int return_55 () {
1502 public static int test_0_cfold_div_zero () {
1503 // Test that constant folding doesn't cause division by zero exceptions
1504 if (return_55 () != return_55 ()) {
1523 public static int test_0_udiv_zero () {
1532 } catch (DivideByZeroException) {
1541 } catch (DivideByZeroException) {
1550 public static int test_0_long_div_zero () {
1559 } catch (DivideByZeroException) {
1568 } catch (DivideByZeroException) {
1579 } catch (DivideByZeroException) {
1580 /* wrong exception */
1581 } catch (ArithmeticException) {
1592 } catch (DivideByZeroException) {
1593 /* wrong exception */
1594 } catch (ArithmeticException) {
1603 public static int test_0_ulong_div_zero () {
1612 } catch (DivideByZeroException) {
1621 } catch (DivideByZeroException) {
1630 public static int test_0_float_div_zero () {
1639 } catch (DivideByZeroException) {
1648 } catch (DivideByZeroException) {
1657 public static int test_0_invalid_unbox () {
1660 object o = "Some string";
1664 // Illegal conversion; o contains a string not an int
1666 } catch (Exception e) {
1674 // Test that double[] can't be cast to double (bug #46027)
1675 public static int test_0_invalid_unbox_arrays () {
1676 double[] d1 = { 1.0 };
1677 double[][] d2 = { d1 };
1681 foreach (double d in a) {
1685 catch (InvalidCastException e) {
1690 /* bug# 42190, at least mcs generates a leave for the return that
1691 * jumps out of multiple exception clauses: we used to execute just
1692 * one enclosing finally block.
1694 public static int finally_level;
1695 static void do_something () {
1708 public static int test_2_multiple_finally_clauses () {
1711 if (finally_level == 1)
1716 public static int test_3_checked_cast_un () {
1717 ulong i = 0x8000000034000000;
1721 checked { j = (long)i; }
1722 } catch (OverflowException) {
1731 public static int test_4_checked_cast () {
1735 unchecked { i = (long)0x8000000034000000;};
1737 checked { j = (ulong)i; }
1738 } catch (OverflowException) {
1747 static readonly int[] mul_dim_results = new int[] {
1748 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1749 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1753 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1754 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1755 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1758 public static int test_0_multi_dim_array_access () {
1759 int [,] a = System.Array.CreateInstance (typeof (int),
1760 new int [] {3,6}, new int [] {2,2 }) as int[,];
1763 for (x = 0; x < 8; ++x) {
1764 for (y = 0; y < 9; ++y) {
1765 bool got_ex = false;
1772 if (result_idx >= mul_dim_results.Length)
1774 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1775 return result_idx + 1;
1781 if (result_idx == mul_dim_results.Length)
1786 static void helper_out_obj (out object o) {
1787 o = (object)"buddy";
1790 static void helper_out_string (out string o) {
1794 public static int test_2_array_mismatch () {
1795 string[] a = { "hello", "world" };
1797 bool passed = false;
1800 helper_out_obj (out b [1]);
1801 } catch (ArrayTypeMismatchException) {
1806 helper_out_string (out a [1]);
1807 if (a [1] != "buddy")
1812 public static int test_0_ovf () {
1819 ulong a = UInt64.MaxValue - 1;
1829 ulong a = UInt64.MaxValue;
1839 long a = Int64.MaxValue - 1;
1848 long a = Int64.MaxValue;
1858 ulong a = UInt64.MaxValue - 1;
1867 ulong a = UInt64.MaxValue;
1877 long a = Int64.MinValue + 1;
1887 long a = Int64.MinValue;
1897 ulong a = UInt64.MinValue + 1;
1907 ulong a = UInt64.MinValue;
1917 int a = Int32.MinValue + 1;
1927 int a = Int32.MinValue;
2005 ulong a = 0xffffffffff;
2006 ulong t = a*0x0ffffff;
2015 ulong a = 0xffffffffff;
2016 ulong t = a*0x0fffffff;
2025 long a = Int64.MinValue;
2037 long b = Int64.MinValue;
2050 public static int i;
2053 throw new Exception ("Ugh!");
2056 public static int DoSomething () {
2061 public static int test_0_exception_in_cctor () {
2063 Broken.DoSomething ();
2065 catch (TypeInitializationException) {
2066 // This will only happen once even if --regression is used
2071 public static int test_5_regalloc () {
2075 for (i = 0; i < 10; ++i) {
2077 throw new Exception ();
2085 // Check that variables written in catch clauses are volatile
2088 throw new Exception ();
2099 throw new Exception ();
2113 /* MarshalByRefObject prevents the methods from being inlined */
2114 class ThrowClass : MarshalByRefObject {
2115 public static void rethrow1 () {
2116 throw new Exception ();
2119 public static void rethrow2 () {
2124 public static int test_0_rethrow_stacktrace () {
2125 // Check that rethrowing an exception preserves the original stack trace
2128 ThrowClass.rethrow2 ();
2130 catch (Exception ex) {
2131 // Check that each catch clause has its own exception variable
2132 // If not, the throw below will overwrite the exception used
2135 throw new DivideByZeroException ();
2137 catch (Exception foo) {
2143 catch (Exception ex) {
2144 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2152 class Face : IFace {}
2154 public static int test_1_array_mismatch_2 () {
2156 object [] o = new Face [1];
2159 } catch (ArrayTypeMismatchException) {
2164 public static int test_1_array_mismatch_3 () {
2166 object [] o = new IFace [1];
2169 } catch (ArrayTypeMismatchException) {
2174 public static int test_1_array_mismatch_4 () {
2176 object [][] o = new Face [5] [];
2177 o [0] = new object [5];
2180 } catch (ArrayTypeMismatchException) {
2185 public static int test_0_array_size () {
2190 int[] mem1 = new int [Int32.MaxValue];
2192 catch (OutOfMemoryException e) {
2200 int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2202 catch (OutOfMemoryException e) {
2212 int i, j, k, l, m, n;
2215 static IntPtr[] addr;
2217 static unsafe void throw_func (int i, S s) {
2218 addr [i] = new IntPtr (&i);
2219 throw new Exception ();
2222 /* Test that arguments are correctly popped off the stack during unwinding */
2223 public static int test_0_stack_unwind () {
2224 addr = new IntPtr [1000];
2226 for (int j = 0; j < 1000; j++) {
2233 return (addr [0].ToInt64 () - addr [100].ToInt64 () < 100) ? 0 : 1;
2236 public static int test_0_regress_73242 () {
2237 int [] arr = new int [10];
2238 for (int i = 0; i < 10; ++i)
2241 throw new Exception ();
2248 public static int test_0_nullref () {
2252 } catch (NullReferenceException e) {