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 () {
98 } catch (OverflowException) {
112 } catch (OverflowException) {
126 } catch (OverflowException) {
140 } catch (OverflowException) {
154 } catch (OverflowException) {
168 } catch (OverflowException) {
182 } catch (OverflowException) {
196 } catch (OverflowException) {
210 } catch (OverflowException) {
224 } catch (OverflowException) {
238 } catch (OverflowException) {
252 } catch (OverflowException) {
263 static int test_0_sbyte_cast () {
275 } catch (OverflowException) {
289 } catch (OverflowException) {
303 } catch (OverflowException) {
317 } catch (OverflowException) {
331 } catch (OverflowException) {
345 } catch (OverflowException) {
359 } catch (OverflowException) {
373 } catch (OverflowException) {
387 } catch (OverflowException) {
401 } catch (OverflowException) {
415 } catch (OverflowException) {
429 } catch (OverflowException) {
443 } catch (OverflowException) {
457 } catch (OverflowException) {
471 } catch (OverflowException) {
485 } catch (OverflowException) {
499 } catch (OverflowException) {
513 } catch (OverflowException) {
527 } catch (OverflowException) {
541 } catch (OverflowException) {
552 static int test_0_ushort_cast () {
559 a = System.UInt16.MaxValue;
564 } catch (OverflowException) {
576 } catch (OverflowException) {
583 a = System.UInt16.MaxValue + 1;
588 } catch (OverflowException) {
600 } catch (OverflowException) {
612 } catch (OverflowException) {
619 double d = System.UInt16.MaxValue;
624 } catch (OverflowException) {
636 } catch (OverflowException) {
643 double d = System.UInt16.MaxValue + 1.0;
648 } catch (OverflowException) {
655 l = System.UInt16.MaxValue;
660 } catch (OverflowException) {
672 } catch (OverflowException) {
679 l = System.UInt16.MaxValue + 1;
684 } catch (OverflowException) {
696 } catch (OverflowException) {
705 static int test_0_short_cast () {
712 a = System.UInt16.MaxValue;
717 } catch (OverflowException) {
729 } catch (OverflowException) {
736 a = System.Int16.MaxValue + 1;
741 } catch (OverflowException) {
748 a = System.Int16.MinValue - 1;
753 } catch (OverflowException) {
765 } catch (OverflowException) {
772 a = System.Int16.MinValue;
777 } catch (OverflowException) {
784 a = System.Int16.MaxValue;
789 } catch (OverflowException) {
796 a = System.Int16.MaxValue + 1;
801 } catch (OverflowException) {
808 double d = System.Int16.MaxValue;
813 } catch (OverflowException) {
820 double d = System.Int16.MinValue;
825 } catch (OverflowException) {
832 double d = System.Int16.MaxValue + 1.0;
837 } catch (OverflowException) {
844 double d = System.Int16.MinValue - 1.0;
849 } catch (OverflowException) {
856 l = System.Int16.MaxValue + 1;
861 } catch (OverflowException) {
868 l = System.Int16.MaxValue;
873 } catch (OverflowException) {
880 l = System.Int16.MinValue - 1;
885 } catch (OverflowException) {
893 l = System.Int16.MinValue;
898 } catch (OverflowException) {
907 static int test_0_int_cast () {
913 double d = System.Int32.MaxValue + 1.0;
918 } catch (OverflowException) {
925 double d = System.Int32.MaxValue;
930 } catch (OverflowException) {
938 double d = System.Int32.MinValue;
943 } catch (OverflowException) {
951 double d = System.Int32.MinValue - 1.0;
956 } catch (OverflowException) {
963 l = System.Int32.MaxValue + (long)1;
968 } catch (OverflowException) {
975 l = System.Int32.MaxValue;
980 } catch (OverflowException) {
988 l = System.Int32.MinValue;
993 } catch (OverflowException) {
1001 l = System.Int32.MinValue - (long)1;
1006 } catch (OverflowException) {
1023 static int test_0_uint_cast () {
1029 double d = System.UInt32.MaxValue;
1034 } catch (OverflowException) {
1041 double d = System.UInt32.MaxValue + 1.0;
1046 } catch (OverflowException) {
1053 double d = System.UInt32.MinValue;
1058 } catch (OverflowException) {
1065 double d = System.UInt32.MinValue - 1.0;
1070 } catch (OverflowException) {
1077 l = System.UInt32.MaxValue;
1082 } catch (OverflowException) {
1089 l = System.UInt32.MaxValue + (long)1;
1094 } catch (OverflowException) {
1101 l = System.UInt32.MinValue;
1106 } catch (OverflowException) {
1113 l = System.UInt32.MinValue - (long)1;
1118 } catch (OverflowException) {
1135 static int test_0_long_cast () {
1140 double d = System.Int64.MaxValue - 512.0;
1145 } catch (OverflowException) {
1152 double d = System.Int64.MaxValue - 513.0;
1157 } catch (OverflowException) {
1165 double d = System.Int64.MinValue - 1024.0;
1170 } catch (OverflowException) {
1177 double d = System.Int64.MinValue - 1025.0;
1182 } catch (OverflowException) {
1199 static int test_0_ulong_cast () {
1204 double d = System.UInt64.MaxValue - 1024.0;
1209 } catch (OverflowException) {
1216 double d = System.UInt64.MaxValue - 1025.0;
1221 } catch (OverflowException) {
1234 } catch (OverflowException) {
1246 } catch (OverflowException) {
1263 static int test_0_simple_double_casts () {
1265 double d = 0xffffffff;
1267 if ((uint)d != 4294967295)
1270 d = 0xffffffffffffffff;
1283 if ((ushort)d != 0xffff)
1286 if ((byte)d != 0xff)
1292 static int test_0_div_zero () {
1301 } catch (DivideByZeroException) {
1310 } catch (DivideByZeroException) {
1321 } catch (DivideByZeroException) {
1322 /* wrong exception */
1323 } catch (ArithmeticException) {
1334 } catch (DivideByZeroException) {
1335 /* wrong exception */
1336 } catch (ArithmeticException) {
1345 static int return_55 () {
1349 static int test_0_cfold_div_zero () {
1350 // Test that constant folding doesn't cause division by zero exceptions
1351 if (return_55 () != return_55 ()) {
1370 static int test_0_udiv_zero () {
1379 } catch (DivideByZeroException) {
1388 } catch (DivideByZeroException) {
1397 static int test_0_long_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 test_0_ulong_div_zero () {
1459 } catch (DivideByZeroException) {
1468 } catch (DivideByZeroException) {
1477 static int test_0_float_div_zero () {
1486 } catch (DivideByZeroException) {
1495 } catch (DivideByZeroException) {
1504 static int test_0_invalid_unbox () {
1507 object o = "Some string";
1511 // Illegal conversion; o contains a string not an int
1513 } catch (Exception e) {
1521 // Test that double[] can't be cast to double (bug #46027)
1522 static int test_0_invalid_unbox_arrays () {
1523 double[] d1 = { 1.0 };
1524 double[][] d2 = { d1 };
1528 foreach (double d in a) {
1532 catch (InvalidCastException e) {
1537 /* bug# 42190, at least mcs generates a leave for the return that
1538 * jumps out of multiple exception clauses: we used to execute just
1539 * one enclosing finally block.
1541 static int finally_level;
1542 static void do_something () {
1555 static int test_2_multiple_finally_clauses () {
1558 if (finally_level == 1)
1563 static int test_3_checked_cast_un () {
1564 ulong i = 0x8000000034000000;
1568 checked { j = (long)i; }
1569 } catch (OverflowException) {
1578 static int test_4_checked_cast () {
1582 unchecked { i = (long)0x8000000034000000;};
1584 checked { j = (ulong)i; }
1585 } catch (OverflowException) {
1594 static readonly int[] mul_dim_results = new int[] {
1595 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1596 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1600 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1601 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1602 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1605 static int test_0_multi_dim_array_access () {
1606 int [,] a = System.Array.CreateInstance (typeof (int),
1607 new int [] {3,6}, new int [] {2,2 }) as int[,];
1610 for (x = 0; x < 8; ++x) {
1611 for (y = 0; y < 9; ++y) {
1612 bool got_ex = false;
1619 if (result_idx >= mul_dim_results.Length)
1621 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1622 return result_idx + 1;
1628 if (result_idx == mul_dim_results.Length)
1633 static void helper_out_obj (out object o) {
1634 o = (object)"buddy";
1637 static void helper_out_string (out string o) {
1641 static int test_2_array_mismatch () {
1642 string[] a = { "hello", "world" };
1644 bool passed = false;
1647 helper_out_obj (out b [1]);
1648 } catch (ArrayTypeMismatchException) {
1653 helper_out_string (out a [1]);
1654 if (a [1] != "buddy")
1659 static int test_0_ovf () {
1666 ulong a = UInt64.MaxValue - 1;
1676 ulong a = UInt64.MaxValue;
1686 long a = Int64.MaxValue - 1;
1695 long a = Int64.MaxValue;
1705 ulong a = UInt64.MaxValue - 1;
1714 ulong a = UInt64.MaxValue;
1724 long a = Int64.MinValue + 1;
1734 long a = Int64.MinValue;
1744 ulong a = UInt64.MinValue + 1;
1754 ulong a = UInt64.MinValue;
1764 int a = Int32.MinValue + 1;
1774 int a = Int32.MinValue;
1852 ulong a = 0xffffffffff;
1853 ulong t = a*0x0ffffff;
1862 ulong a = 0xffffffffff;
1863 ulong t = a*0x0fffffff;
1872 long a = Int64.MinValue;
1884 long b = Int64.MinValue;
1900 throw new Exception ("Ugh!");
1903 public static int DoSomething () {
1908 static int test_0_exception_in_cctor () {
1910 Broken.DoSomething ();
1912 catch (TypeInitializationException) {
1913 // This will only happen once even if --regression is used
1918 static int test_5_regalloc () {
1922 for (i = 0; i < 10; ++i) {
1924 throw new Exception ();
1932 // Check that variables written in catch clauses are volatile
1935 throw new Exception ();
1946 throw new Exception ();
1960 /* MarshalByRefObject prevents the methods from being inlined */
1961 class ThrowClass : MarshalByRefObject {
1962 public static void rethrow1 () {
1963 throw new Exception ();
1966 public static void rethrow2 () {
1971 static int test_0_rethrow_stacktrace () {
1972 // Check that rethrowing an exception preserves the original stack trace
1975 ThrowClass.rethrow2 ();
1977 catch (Exception ex) {
1981 catch (Exception ex) {
1982 if (ex.StackTrace.IndexOf ("rethrow2") != -1)