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_ovf () {
1831 ulong a
= UInt64
.MaxValue
- 1;
1841 ulong a
= UInt64
.MaxValue
;
1851 long a
= Int64
.MaxValue
- 1;
1860 long a
= Int64
.MaxValue
;
1870 ulong a
= UInt64
.MaxValue
- 1;
1879 ulong a
= UInt64
.MaxValue
;
1889 long a
= Int64
.MinValue
+ 1;
1899 long a
= Int64
.MinValue
;
1909 ulong a
= UInt64
.MinValue
+ 1;
1919 ulong a
= UInt64
.MinValue
;
1929 int a
= Int32
.MinValue
+ 1;
1939 int a
= Int32
.MinValue
;
2017 ulong a
= 0xffffffffff;
2018 ulong t
= a
*0x0ffffff;
2027 ulong a
= 0xffffffffff;
2028 ulong t
= a
*0x0fffffff;
2037 long a
= Int64
.MinValue
;
2049 long b
= Int64
.MinValue
;
2062 public static int i
;
2065 throw new Exception ("Ugh!");
2068 public static int DoSomething () {
2073 public static int test_0_exception_in_cctor () {
2075 Broken
.DoSomething ();
2077 catch (TypeInitializationException
) {
2078 // This will only happen once even if --regression is used
2083 public static int test_5_regalloc () {
2087 for (i
= 0; i
< 10; ++i
) {
2089 throw new Exception ();
2097 // Check that variables written in catch clauses are volatile
2100 throw new Exception ();
2111 throw new Exception ();
2125 /* MarshalByRefObject prevents the methods from being inlined */
2126 class ThrowClass
: MarshalByRefObject
{
2127 public static void rethrow1 () {
2128 throw new Exception ();
2131 public static void rethrow2 () {
2136 public static int test_0_rethrow_stacktrace () {
2137 // Check that rethrowing an exception preserves the original stack trace
2140 ThrowClass
.rethrow2 ();
2142 catch (Exception ex
) {
2143 // Check that each catch clause has its own exception variable
2144 // If not, the throw below will overwrite the exception used
2147 throw new DivideByZeroException ();
2149 catch (Exception foo
) {
2155 catch (Exception ex
) {
2156 if (ex
.StackTrace
.IndexOf ("rethrow2") != -1)
2164 class Face
: IFace
{}
2166 public static int test_1_array_mismatch_2 () {
2168 object [] o
= new Face
[1];
2171 } catch (ArrayTypeMismatchException
) {
2176 public static int test_1_array_mismatch_3 () {
2178 object [] o
= new IFace
[1];
2181 } catch (ArrayTypeMismatchException
) {
2186 public static int test_1_array_mismatch_4 () {
2188 object [][] o
= new Face
[5] [];
2189 o
[0] = new object [5];
2192 } catch (ArrayTypeMismatchException
) {
2197 public static int test_0_array_size () {
2202 int[] mem1
= new int [Int32
.MaxValue
];
2204 catch (OutOfMemoryException e
) {
2212 int[,] mem2
= new int [Int32
.MaxValue
, Int32
.MaxValue
];
2214 catch (OutOfMemoryException e
) {
2224 int i
, j
, k
, l
, m
, n
;
2227 static IntPtr
[] addr
;
2229 static unsafe void throw_func (int i
, S s
) {
2230 addr
[i
] = new IntPtr (&i
);
2231 throw new Exception ();
2234 /* Test that arguments are correctly popped off the stack during unwinding */
2235 public static int test_0_stack_unwind () {
2236 addr
= new IntPtr
[1000];
2238 for (int j
= 0; j
< 1000; j
++) {
2245 return (addr
[0].ToInt64 () - addr
[100].ToInt64 () < 100) ? 0 : 1;
2248 public static int test_0_regress_73242 () {
2249 int [] arr
= new int [10];
2250 for (int i
= 0; i
< 10; ++i
)
2253 throw new Exception ();
2260 public static int test_0_nullref () {
2264 } catch (NullReferenceException e
) {
2271 public static int test_0_throw_to_branch_opt_outer_clause () {
2276 string [] files
= new string[1];
2278 string s
= files
[2];
2285 return (i
== 1) ? 0 : 1;