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) {
567 l = 0x00000000ffffffff;
572 } catch (OverflowException) {
583 static int test_0_ushort_cast () {
591 a = System.UInt16.MaxValue;
596 } catch (OverflowException) {
608 } catch (OverflowException) {
615 a = System.UInt16.MaxValue + 1;
620 } catch (OverflowException) {
632 } catch (OverflowException) {
644 } catch (OverflowException) {
651 double d = System.UInt16.MaxValue;
656 } catch (OverflowException) {
668 } catch (OverflowException) {
675 double d = System.UInt16.MaxValue + 1.0;
680 } catch (OverflowException) {
687 l = System.UInt16.MaxValue;
692 } catch (OverflowException) {
704 } catch (OverflowException) {
711 l = System.UInt16.MaxValue + 1;
716 } catch (OverflowException) {
728 } catch (OverflowException) {
740 } catch (OverflowException) {
749 static int test_0_short_cast () {
756 a = System.UInt16.MaxValue;
761 } catch (OverflowException) {
773 } catch (OverflowException) {
780 a = System.Int16.MaxValue + 1;
785 } catch (OverflowException) {
792 a = System.Int16.MinValue - 1;
797 } catch (OverflowException) {
809 } catch (OverflowException) {
816 a = System.Int16.MinValue;
821 } catch (OverflowException) {
828 a = System.Int16.MaxValue;
833 } catch (OverflowException) {
840 a = System.Int16.MaxValue + 1;
845 } catch (OverflowException) {
852 double d = System.Int16.MaxValue;
857 } catch (OverflowException) {
864 double d = System.Int16.MinValue;
869 } catch (OverflowException) {
876 double d = System.Int16.MaxValue + 1.0;
881 } catch (OverflowException) {
888 double d = System.Int16.MinValue - 1.0;
893 } catch (OverflowException) {
900 l = System.Int16.MaxValue + 1;
905 } catch (OverflowException) {
912 l = System.Int16.MaxValue;
917 } catch (OverflowException) {
924 l = System.Int16.MinValue - 1;
929 } catch (OverflowException) {
937 l = System.Int16.MinValue;
942 } catch (OverflowException) {
951 static int test_0_int_cast () {
957 double d = System.Int32.MaxValue + 1.0;
962 } catch (OverflowException) {
969 double d = System.Int32.MaxValue;
974 } catch (OverflowException) {
982 double d = System.Int32.MinValue;
987 } catch (OverflowException) {
995 double d = System.Int32.MinValue - 1.0;
1000 } catch (OverflowException) {
1007 l = System.Int32.MaxValue + (long)1;
1012 } catch (OverflowException) {
1019 l = System.Int32.MaxValue;
1024 } catch (OverflowException) {
1032 l = System.Int32.MinValue;
1037 } catch (OverflowException) {
1045 l = System.Int32.MinValue - (long)1;
1050 } catch (OverflowException) {
1057 uint ui = System.UInt32.MaxValue;
1063 catch (OverflowException) {
1080 static int test_0_uint_cast () {
1086 double d = System.UInt32.MaxValue;
1091 } catch (OverflowException) {
1098 double d = System.UInt32.MaxValue + 1.0;
1103 } catch (OverflowException) {
1110 double d = System.UInt32.MinValue;
1115 } catch (OverflowException) {
1122 double d = System.UInt32.MinValue - 1.0;
1127 } catch (OverflowException) {
1134 l = System.UInt32.MaxValue;
1139 } catch (OverflowException) {
1146 l = System.UInt32.MaxValue + (long)1;
1151 } catch (OverflowException) {
1158 l = System.UInt32.MinValue;
1163 } catch (OverflowException) {
1170 l = System.UInt32.MinValue - (long)1;
1175 } catch (OverflowException) {
1188 catch (OverflowException) {
1205 static int test_0_long_cast () {
1210 double d = System.Int64.MaxValue - 512.0;
1215 } catch (OverflowException) {
1222 double d = System.Int64.MaxValue - 513.0;
1227 } catch (OverflowException) {
1235 double d = System.Int64.MinValue - 1024.0;
1240 } catch (OverflowException) {
1247 double d = System.Int64.MinValue - 1025.0;
1252 } catch (OverflowException) {
1269 static int test_0_ulong_cast () {
1274 double d = System.UInt64.MaxValue - 1024.0;
1279 } catch (OverflowException) {
1286 double d = System.UInt64.MaxValue - 1025.0;
1291 } catch (OverflowException) {
1304 } catch (OverflowException) {
1316 } catch (OverflowException) {
1337 catch (OverflowException) {
1344 int i = Int32.MinValue;
1350 catch (OverflowException) {
1359 static int test_0_simple_double_casts () {
1361 double d = 0xffffffff;
1363 if ((uint)d != 4294967295)
1366 d = 0xffffffffffffffff;
1379 if ((ushort)d != 0xffff)
1382 if ((byte)d != 0xff)
1388 static int test_0_div_zero () {
1397 } catch (DivideByZeroException) {
1406 } catch (DivideByZeroException) {
1417 } catch (DivideByZeroException) {
1418 /* wrong exception */
1419 } catch (ArithmeticException) {
1430 } catch (DivideByZeroException) {
1431 /* wrong exception */
1432 } catch (ArithmeticException) {
1441 static int return_55 () {
1445 static int test_0_cfold_div_zero () {
1446 // Test that constant folding doesn't cause division by zero exceptions
1447 if (return_55 () != return_55 ()) {
1466 static int test_0_udiv_zero () {
1475 } catch (DivideByZeroException) {
1484 } catch (DivideByZeroException) {
1493 static int test_0_long_div_zero () {
1502 } catch (DivideByZeroException) {
1511 } catch (DivideByZeroException) {
1522 } catch (DivideByZeroException) {
1523 /* wrong exception */
1524 } catch (ArithmeticException) {
1535 } catch (DivideByZeroException) {
1536 /* wrong exception */
1537 } catch (ArithmeticException) {
1546 static int test_0_ulong_div_zero () {
1555 } catch (DivideByZeroException) {
1564 } catch (DivideByZeroException) {
1573 static int test_0_float_div_zero () {
1582 } catch (DivideByZeroException) {
1591 } catch (DivideByZeroException) {
1600 static int test_0_invalid_unbox () {
1603 object o = "Some string";
1607 // Illegal conversion; o contains a string not an int
1609 } catch (Exception e) {
1617 // Test that double[] can't be cast to double (bug #46027)
1618 static int test_0_invalid_unbox_arrays () {
1619 double[] d1 = { 1.0 };
1620 double[][] d2 = { d1 };
1624 foreach (double d in a) {
1628 catch (InvalidCastException e) {
1633 /* bug# 42190, at least mcs generates a leave for the return that
1634 * jumps out of multiple exception clauses: we used to execute just
1635 * one enclosing finally block.
1637 static int finally_level;
1638 static void do_something () {
1651 static int test_2_multiple_finally_clauses () {
1654 if (finally_level == 1)
1659 static int test_3_checked_cast_un () {
1660 ulong i = 0x8000000034000000;
1664 checked { j = (long)i; }
1665 } catch (OverflowException) {
1674 static int test_4_checked_cast () {
1678 unchecked { i = (long)0x8000000034000000;};
1680 checked { j = (ulong)i; }
1681 } catch (OverflowException) {
1690 static readonly int[] mul_dim_results = new int[] {
1691 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1692 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1696 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1697 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1698 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1701 static int test_0_multi_dim_array_access () {
1702 int [,] a = System.Array.CreateInstance (typeof (int),
1703 new int [] {3,6}, new int [] {2,2 }) as int[,];
1706 for (x = 0; x < 8; ++x) {
1707 for (y = 0; y < 9; ++y) {
1708 bool got_ex = false;
1715 if (result_idx >= mul_dim_results.Length)
1717 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1718 return result_idx + 1;
1724 if (result_idx == mul_dim_results.Length)
1729 static void helper_out_obj (out object o) {
1730 o = (object)"buddy";
1733 static void helper_out_string (out string o) {
1737 static int test_2_array_mismatch () {
1738 string[] a = { "hello", "world" };
1740 bool passed = false;
1743 helper_out_obj (out b [1]);
1744 } catch (ArrayTypeMismatchException) {
1749 helper_out_string (out a [1]);
1750 if (a [1] != "buddy")
1755 static int test_0_ovf () {
1762 ulong a = UInt64.MaxValue - 1;
1772 ulong a = UInt64.MaxValue;
1782 long a = Int64.MaxValue - 1;
1791 long a = Int64.MaxValue;
1801 ulong a = UInt64.MaxValue - 1;
1810 ulong a = UInt64.MaxValue;
1820 long a = Int64.MinValue + 1;
1830 long a = Int64.MinValue;
1840 ulong a = UInt64.MinValue + 1;
1850 ulong a = UInt64.MinValue;
1860 int a = Int32.MinValue + 1;
1870 int a = Int32.MinValue;
1948 ulong a = 0xffffffffff;
1949 ulong t = a*0x0ffffff;
1958 ulong a = 0xffffffffff;
1959 ulong t = a*0x0fffffff;
1968 long a = Int64.MinValue;
1980 long b = Int64.MinValue;
1996 throw new Exception ("Ugh!");
1999 public static int DoSomething () {
2004 static int test_0_exception_in_cctor () {
2006 Broken.DoSomething ();
2008 catch (TypeInitializationException) {
2009 // This will only happen once even if --regression is used
2014 static int test_5_regalloc () {
2018 for (i = 0; i < 10; ++i) {
2020 throw new Exception ();
2028 // Check that variables written in catch clauses are volatile
2031 throw new Exception ();
2042 throw new Exception ();
2056 /* MarshalByRefObject prevents the methods from being inlined */
2057 class ThrowClass : MarshalByRefObject {
2058 public static void rethrow1 () {
2059 throw new Exception ();
2062 public static void rethrow2 () {
2067 static int test_0_rethrow_stacktrace () {
2068 // Check that rethrowing an exception preserves the original stack trace
2071 ThrowClass.rethrow2 ();
2073 catch (Exception ex) {
2077 catch (Exception ex) {
2078 if (ex.StackTrace.IndexOf ("rethrow2") != -1)
2086 class Face : IFace {}
2088 static int test_1_array_mismatch_2 () {
2090 object [] o = new Face [1];
2093 } catch (ArrayTypeMismatchException) {
2098 static int test_1_array_mismatch_3 () {
2100 object [] o = new IFace [1];
2103 } catch (ArrayTypeMismatchException) {
2108 static int test_1_array_mismatch_4 () {
2110 object [][] o = new Face [5] [];
2111 o [0] = new object [5];
2114 } catch (ArrayTypeMismatchException) {
2119 static int test_0_array_size () {
2124 int[] mem1 = new int [Int32.MaxValue];
2126 catch (OutOfMemoryException e) {
2134 int[,] mem2 = new int [Int32.MaxValue, Int32.MaxValue];
2136 catch (OutOfMemoryException e) {