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) {
1015 static int test_0_uint_cast () {
1021 double d = System.UInt32.MaxValue;
1026 } catch (OverflowException) {
1033 double d = System.UInt32.MaxValue + 1.0;
1038 } catch (OverflowException) {
1045 double d = System.UInt32.MinValue;
1050 } catch (OverflowException) {
1057 double d = System.UInt32.MinValue - 1.0;
1062 } catch (OverflowException) {
1069 l = System.UInt32.MaxValue;
1074 } catch (OverflowException) {
1081 l = System.UInt32.MaxValue + (long)1;
1086 } catch (OverflowException) {
1093 l = System.UInt32.MinValue;
1098 } catch (OverflowException) {
1105 l = System.UInt32.MinValue - (long)1;
1110 } catch (OverflowException) {
1119 static int test_0_long_cast () {
1124 double d = System.Int64.MaxValue - 512.0;
1129 } catch (OverflowException) {
1136 double d = System.Int64.MaxValue - 513.0;
1141 } catch (OverflowException) {
1149 double d = System.Int64.MinValue - 1024.0;
1154 } catch (OverflowException) {
1161 double d = System.Int64.MinValue - 1025.0;
1166 } catch (OverflowException) {
1175 static int test_0_ulong_cast () {
1180 double d = System.UInt64.MaxValue - 1024.0;
1185 } catch (OverflowException) {
1192 double d = System.UInt64.MaxValue - 1025.0;
1197 } catch (OverflowException) {
1210 } catch (OverflowException) {
1222 } catch (OverflowException) {
1231 static int test_0_simple_double_casts () {
1233 double d = 0xffffffff;
1235 if ((uint)d != 4294967295)
1238 d = 0xffffffffffffffff;
1251 if ((ushort)d != 0xffff)
1254 if ((byte)d != 0xff)
1260 static int test_0_div_zero () {
1269 } catch (DivideByZeroException) {
1278 } catch (DivideByZeroException) {
1287 static int test_0_udiv_zero () {
1296 } catch (DivideByZeroException) {
1305 } catch (DivideByZeroException) {
1314 static int test_0_long_div_zero () {
1323 } catch (DivideByZeroException) {
1332 } catch (DivideByZeroException) {
1341 static int test_0_ulong_div_zero () {
1350 } catch (DivideByZeroException) {
1359 } catch (DivideByZeroException) {
1368 static int test_0_float_div_zero () {
1377 } catch (DivideByZeroException) {
1386 } catch (DivideByZeroException) {
1395 static int test_0_invalid_unbox () {
1398 object o = "Some string";
1402 // Illegal conversion; o contains a string not an int
1404 } catch (Exception e) {
1412 // Test that double[] can't be cast to double (bug #46027)
1413 static int test_0_invalid_unbox_arrays () {
1414 double[] d1 = { 1.0 };
1415 double[][] d2 = { d1 };
1419 foreach (double d in a) {
1423 catch (InvalidCastException e) {
1428 /* bug# 42190, at least mcs generates a leave for the return that
1429 * jumps out of multiple exception clauses: we used to execute just
1430 * one enclosing finally block.
1432 static int finally_level;
1433 static void do_something () {
1446 static int test_2_multiple_finally_clauses () {
1449 if (finally_level == 1)
1454 static int test_3_checked_cast_un () {
1455 ulong i = 0x8000000034000000;
1459 checked { j = (long)i; }
1460 } catch (OverflowException) {
1469 static int test_4_checked_cast () {
1473 unchecked { i = (long)0x8000000034000000;};
1475 checked { j = (ulong)i; }
1476 } catch (OverflowException) {
1485 static readonly int[] mul_dim_results = new int[] {
1486 0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
1487 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8,
1491 5, 0, 5, 1, 5, 2, 5, 3, 5, 4, 5, 5, 5, 6, 5, 7, 5, 8,
1492 6, 0, 6, 1, 6, 2, 6, 3, 6, 4, 6, 5, 6, 6, 6, 7, 6, 8,
1493 7, 0, 7, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 7, 7, 7, 8,
1496 static int test_0_multi_dim_array_access () {
1497 int [,] a = System.Array.CreateInstance (typeof (int),
1498 new int [] {3,6}, new int [] {2,2 }) as int[,];
1501 for (x = 0; x < 8; ++x) {
1502 for (y = 0; y < 9; ++y) {
1503 bool got_ex = false;
1510 if (result_idx >= mul_dim_results.Length)
1512 if (mul_dim_results [result_idx] != x || mul_dim_results [result_idx + 1] != y) {
1513 return result_idx + 1;
1519 if (result_idx == mul_dim_results.Length)
1524 static void helper_out_obj (out object o) {
1525 o = (object)"buddy";
1528 static void helper_out_string (out string o) {
1532 static int test_2_array_mismatch () {
1533 string[] a = { "hello", "world" };
1535 bool passed = false;
1538 helper_out_obj (out b [1]);
1539 } catch (ArrayTypeMismatchException) {
1544 helper_out_string (out a [1]);
1545 if (a [1] != "buddy")
1550 static int test_0_long_add_ovf () {
1555 l = 999999999999999999;
1561 } catch (OverflowException) {