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_10_simple_cast () {
37 public static int test_1_bigmul1 () {
43 c = (long)a * (long)b;
49 public static int test_1_bigmul2 () {
50 int a = System.Int32.MaxValue, b = System.Int32.MaxValue;
51 long s = System.Int64.MinValue;
53 c = s + (long) a * (long) b;
54 if (c == -4611686022722355199)
59 public static int test_1_bigmul3 () {
62 c = (ulong) a * (ulong) b;
68 public static int test_1_bigmul4 () {
69 int a = System.Int32.MaxValue, b = System.Int32.MaxValue;
71 c = (ulong) a * (ulong) b;
72 if (c == 4611686014132420609)
77 public static int test_1_bigmul5 () {
78 int a = System.Int32.MaxValue, b = System.Int32.MinValue;
80 c = (long) a * (long) b;
81 if (c == -4611686016279904256)
86 public static int test_1_bigmul6 () {
87 uint a = System.UInt32.MaxValue, b = System.UInt32.MaxValue/(uint)2;
89 c = (ulong) a * (ulong) b;
90 if (c == 9223372030412324865)
95 public static int test_0_beq () {
96 long a = 0xffffffffff;
97 if (a != 0xffffffffff)
102 public static int test_0_bne_un () {
103 long a = 0xffffffffff;
104 if (a == 0xfffffffffe)
109 public static int test_0_ble () {
110 long a = 0xffffffffff;
111 if (a > 0xffffffffff)
116 public static int test_0_ble_un () {
117 ulong a = 0xffffffffff;
118 if (a > 0xffffffffff)
123 public static int test_0_bge () {
124 long a = 0xffffffffff;
125 if (a < 0xffffffffff)
130 public static int test_0_bge_un () {
131 ulong a = 0xffffffffff;
132 if (a < 0xffffffffff)
137 public static int test_0_blt () {
138 long a = 0xfffffffffe;
139 if (a >= 0xffffffffff)
144 public static int test_0_blt_un () {
145 ulong a = 0xfffffffffe;
146 if (a >= 0xffffffffff)
151 public static int test_0_bgt () {
152 long a = 0xffffffffff;
153 if (a <= 0xfffffffffe)
158 public static int test_0_conv_to_i4 () {
164 public static int test_32_conv_to_u4 () {
170 public static int test_15_conv_to_u4_2 () {
171 long a = 0x10000000f;
176 public static int test_0_conv_from_i4 () {
188 public static int test_0_conv_from_i4_negative () {
200 public static int test_0_conv_to_r8 () {
202 double b = (double) a;
209 public static int test_0_conv_to_r4 () {
218 public static int test_0_conv_from_r8 () {
227 public static int test_0_conv_from_r4 () {
237 public static int test_8_and () {
238 long a = 0xffffffffff;
243 public static int test_8_and_imm () {
244 long a = 0xffffffffff;
248 public static int test_10_or () {
254 public static int test_10_or_imm () {
259 public static int test_5_xor () {
265 public static int test_5_xor_imm () {
270 public static int test_5_add () {
276 public static int test_5_add_imm () {
281 public static int test_0_add_imm_carry () {
286 public static int test_0_add_imm_no_inc () {
287 // we can't blindly convert an add x, 1 to an inc x
288 long a = 0x1ffffffff;
291 if (c == ((a + 1) + 1))
296 public static int test_4_addcc_imm () {
299 return (int)(a - b + 1);
302 public static int test_5_sub () {
308 public static int test_5_sub_imm () {
313 public static int test_0_sub_imm_carry () {
315 return (int)((a - 1) + 1);
318 public static int test_0_add_ovf () {
322 i = System.Int64.MinValue;
327 if (k != System.Int64.MinValue)
331 i = System.Int64.MaxValue;
336 if (k != System.Int64.MaxValue)
340 i = System.Int64.MinValue;
341 j = System.Int64.MaxValue;
349 i = System.Int64.MaxValue;
350 j = System.Int64.MinValue;
358 i = System.Int64.MinValue + 1234;
363 if (k != System.Int64.MinValue)
367 i = System.Int64.MaxValue - 1234;
372 if (k != System.Int64.MaxValue)
378 public static int test_0_add_un_ovf () {
379 ulong n = (ulong)134217728 * 16;
380 ulong number = checked (n + (uint)0);
382 return number == n ? 0 : 1;
385 public static int test_0_sub_ovf () {
389 i = System.Int64.MinValue;
394 if (k != System.Int64.MinValue)
398 i = System.Int64.MaxValue;
403 if (k != System.Int64.MaxValue)
407 i = System.Int64.MinValue;
408 j = System.Int64.MinValue + 1234;
416 i = System.Int64.MaxValue;
421 if (k != System.Int64.MaxValue - 1234)
425 i = System.Int64.MaxValue - 1234;
430 if (k != System.Int64.MaxValue)
434 i = System.Int64.MinValue + 1234;
439 if (k != System.Int64.MinValue)
445 public static int test_0_sub_ovf_un () {
449 i = System.UInt64.MaxValue;
454 if (k != System.UInt64.MaxValue)
458 i = System.UInt64.MaxValue;
459 j = System.UInt64.MaxValue;
469 public static int test_2_neg () {
474 public static int test_0_neg_large () {
475 long min = -9223372036854775808;
477 ulong ul = (ulong)min;
478 return (min == -(long)ul) ? 0 : 1;
482 public static int test_5_shift ()
512 public static int test_1_shift_u ()
517 // The JIT optimizes this
526 public static int test_1_shift_u_32 ()
532 // Avoid constant folding
533 for (int i = 0; i < 32; ++i)
536 if ((a >> count) != 0xFFFFFFFFUL)
542 public static int test_1_simple_neg () {
550 public static int test_2_compare () {
559 public static int test_9_alu ()
604 public static int test_24_mul () {
610 public static int test_24_mul_ovf () {
621 public static int test_24_mul_un () {
627 public static int test_24_mul_ovf_un () {
638 public static int test_0_mul_imm () {
649 if ((i * 1234) != 4936)
657 if ((i * -1234) != -4936)
663 public static int test_0_mul_imm_opt ()
716 if ((i * 100) != 100)
719 if ((i * 100) != -100)
725 public static int test_4_divun () {
731 public static int test_1431655764_bigdivun_imm () {
738 public static int test_1431655764_bigdivun () {
746 public static int test_1_remun () {
752 public static int test_2_bigremun () {
760 public static int test_0_ceq () {
764 long d = 0xff00000002;
766 bool val = (a == b); // this should produce a ceq
770 val = (a == c); // this should produce a ceq
774 val = (a == d); // this should produce a ceq
781 public static int test_0_ceq_complex () {
790 public static int test_0_clt () {
794 long d = 0xff00000002L;
797 bool val = (a < b); // this should produce a clt
801 val = (a < c); // this should produce a clt
805 val = (c < a); // this should produce a clt
809 val = (e < d); // this should produce a clt
813 val = (d < e); // this should produce a clt
820 public static int test_0_clt_un () {
824 ulong d = 0xff00000002;
825 ulong e = 0xffffffffffffffff;
827 bool val = (a < b); // this should produce a clt_un
831 val = (a < c); // this should produce a clt_un
835 val = (d < e); // this should produce a clt_un
839 val = (e < d); // this should produce a clt_un
846 public static int test_0_cgt () {
850 long d = 0xff00000002L;
853 bool val = (a > b); // this should produce a cgt
857 val = (a > c); // this should produce a cgt
861 val = (c > a); // this should produce a cgt
865 val = (e > d); // this should produce a cgt
869 val = (d > e); // this should produce a cgt
876 public static int test_0_cgt_un () {
880 ulong d = 0xff00000002;
881 ulong e = 0xffffffffffffffff;
883 bool val = (a > b); // this should produce a cgt_un
887 val = (a > c); // this should produce a cgt_un
891 val = (d > e); // this should produce a cgt_un
895 val = (e > d); // this should produce a cgt_un
902 static long return_5low () {
906 static long return_5high () {
910 public static int test_3_long_ret () {
911 long val = return_5low ();
912 return (int) (val - 2);
915 public static int test_1_long_ret2 () {
916 long val = return_5high ();
917 if (val > 0xffffffff)
922 public static int test_3_byte_cast () {
923 ulong val = 0xff00ff00f0f0f0f0;
925 b = (byte) (val & 0xFF);
932 public static int test_4_ushort_cast () {
933 ulong val = 0xff00ff00f0f0f0f0;
935 b = (ushort) (val & 0xFFFF);
941 public static int test_500_mul_div () {
945 long res = val * exp / maxexp;
950 static void doit (double value, out long m) {
954 public static int test_3_checked_cast_un () {
958 checked { j = (long)i; }
965 public static int test_4_checked_cast () {
969 checked { j = (ulong)i; }
976 public static int test_12_checked_i1_cast () {
984 public static int test_127_checked_i1_cast_un () {
992 public static int test_1234_checked_i2_cast () {
1000 public static int test_32767_checked_i2_cast_un () {
1008 public static int test_1234_checked_i4_cast () {
1016 public static int test_10_int_uint_compare () {
1019 for (int i = 0; i < size; ++i) {
1025 public static int test_0_ftol_clobber () {
1033 public static int test_0_ulong_regress () {
1034 ulong u = 4257145737;
1036 return (u == 4257145736) ? 0 : 1;
1039 public static int test_0_assemble_long ()
1042 ulong x = 0x12345678;
1046 ulong z = ((x - y) << 32) | a;
1048 if (z != 0x1234567700000005)
1054 public static int test_0_hash ()
1056 ulong x = 0x1234567887654321;
1057 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
1058 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
1064 public static int test_0_shift_regress () {
1069 return ((a >> (b - c)) == 0) ? 0 : 1;
1072 public static int test_1234_conv_ovf_u8 () {
1081 public static int test_0_regress_cprop_80738 () {
1082 int hours = Int32.MinValue;
1083 int hrssec = (hours * 3600);
1084 long t = ((long)(hrssec) * 1000L);
1086 return t == 0 ? 0 : 1;