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 (ArithmeticException) {
1323 } catch (DivideByZeroException) {
1324 /* wrong exception */
1334 } catch (ArithmeticException) {
1336 } catch (DivideByZeroException) {
1337 /* wrong exception */
1345 static int test_0_udiv_zero () {
1354 } catch (DivideByZeroException) {
1363 } catch (DivideByZeroException) {
1372 static int test_0_long_div_zero () {
1381 } catch (DivideByZeroException) {
1390 } catch (DivideByZeroException) {
1401 } catch (ArithmeticException) {
1403 } catch (DivideByZeroException) {
1404 /* wrong exception */
1414 } catch (ArithmeticException) {
1416 } catch (DivideByZeroException) {
1417 /* wrong exception */
1425 static int test_0_ulong_div_zero () {
1434 } catch (DivideByZeroException) {
1443 } catch (DivideByZeroException) {
1452 static int test_0_float_div_zero () {
1461 } catch (DivideByZeroException) {
1470 } catch (DivideByZeroException) {
1479 static int test_0_invalid_unbox () {
1482 object o = "Some string";
1486 // Illegal conversion; o contains a string not an int
1488 } catch (Exception e) {
1496 // Test that double[] can't be cast to double (bug #46027)
1497 static int test_0_invalid_unbox_arrays () {
1498 double[] d1 = { 1.0 };
1499 double[][] d2 = { d1 };
1503 foreach (double d in a) {
1507 catch (InvalidCastException e) {
1512 /* bug# 42190, at least mcs generates a leave for the return that
1513 * jumps out of multiple exception clauses: we used to execute just
1514 * one enclosing finally block.
1516 static int finally_level;
1517 static void do_something () {
1530 static int test_2_multiple_finally_clauses () {
1533 if (finally_level == 1)
1538 static int test_3_checked_cast_un () {
1539 ulong i = 0x8000000034000000;
1543 checked { j = (long)i; }
1544 } catch (OverflowException) {
1553 static int test_4_checked_cast () {
1557 unchecked { i = (long)0x8000000034000000;};
1559 checked { j = (ulong)i; }
1560 } catch (OverflowException) {
1569 static readonly int[] mul_dim_results = new int[] {
1570 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1571 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1575 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1576 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1577 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1580 static int test_0_multi_dim_array_access () {
1581 int [,] a = System.Array.CreateInstance (typeof (int),
1582 new int [] {3,6}, new int [] {2,2 }) as int[,];
1585 for (x = 0; x < 8; ++x) {
1586 for (y = 0; y < 9; ++y) {
1587 bool got_ex = false;
1594 if (result_idx >= mul_dim_results.Length)
1596 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1597 return result_idx + 1;
1603 if (result_idx == mul_dim_results.Length)
1608 static void helper_out_obj (out object o) {
1609 o = (object)"buddy";
1612 static void helper_out_string (out string o) {
1616 static int test_2_array_mismatch () {
1617 string[] a = { "hello", "world" };
1619 bool passed = false;
1622 helper_out_obj (out b [1]);
1623 } catch (ArrayTypeMismatchException) {
1628 helper_out_string (out a [1]);
1629 if (a [1] != "buddy")
1634 static int test_0_ovf () {
1641 ulong a = UInt64.MaxValue - 1;
1651 ulong a = UInt64.MaxValue;
1661 long a = Int64.MaxValue - 1;
1670 long a = Int64.MaxValue;
1680 ulong a = UInt64.MaxValue - 1;
1689 ulong a = UInt64.MaxValue;
1699 long a = Int64.MinValue + 1;
1709 long a = Int64.MinValue;
1719 ulong a = UInt64.MinValue + 1;
1729 ulong a = UInt64.MinValue;
1739 int a = Int32.MinValue + 1;
1749 int a = Int32.MinValue;
1827 ulong a = 0xffffffffff;
1828 ulong t = a*0x0ffffff;
1837 ulong a = 0xffffffffff;
1838 ulong t = a*0x0fffffff;
1853 throw new Exception ("Ugh!");
1856 public static int DoSomething () {
1861 static int test_0_exception_in_cctor () {
1863 Broken.DoSomething ();
1865 catch (TypeInitializationException) {
1866 // This will only happen once even if --regression is used
1871 static int test_5_regalloc () {
1875 for (i = 0; i < 10; ++i) {
1877 throw new Exception ();
1885 // Check that variables written in catch clauses are volatile
1888 throw new Exception ();
1899 throw new Exception ();
1913 /* MarshalByRefObject prevents the methods from being inlined */
1914 class ThrowClass : MarshalByRefObject {
1915 public static void rethrow1 () {
1916 throw new Exception ();
1919 public static void rethrow2 () {
1924 static int test_0_rethrow_stacktrace () {
1925 // Check that rethrowing an exception preserves the original stack trace
1928 ThrowClass.rethrow2 ();
1930 catch (Exception ex) {
1934 catch (Exception ex) {
1935 if (ex.StackTrace.IndexOf ("rethrow2") != -1)