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)
106 if (a == 0xfeffffffff)
111 public static int test_0_ble () {
112 long a = 0xffffffffff;
113 if (a > 0xffffffffff)
116 if (a > 0x1ffffffffff)
119 if (a > 0xff00000000) {} else
122 if (a > 0xfeffffffff) {} else
126 if (a > 0xffffffffff)
132 public static int test_0_ble_un () {
133 ulong a = 0xffffffffff;
134 if (a > 0xffffffffff)
137 if (a > 0x1ffffffffff)
140 if (a > 0xff00000000) {} else
143 if (a > 0xfeffffffff) {} else
147 if (a > 0xffffffffff)
153 public static int test_0_bge () {
154 long a = 0xffffffffff;
155 if (a < 0xffffffffff)
158 if (a < 0x1ffffffffff) {} else
161 if (a < 0xff00000000)
164 if (a < 0xfeffffffff)
168 if (a < 0xffffffffff) {} else
174 public static int test_0_bge_un () {
175 ulong a = 0xffffffffff;
176 if (a < 0xffffffffff)
179 if (a < 0x1ffffffffff) {} else
182 if (a < 0xff00000000)
185 if (a < 0xfeffffffff)
189 if (a < 0xffffffffff) {} else
195 public static int test_0_blt () {
196 long a = 0xfffffffffe;
197 if (a >= 0xffffffffff)
200 if (a >= 0x1fffffffffe)
203 if (a >= 0xff00000000) {} else
206 if (a >= 0xfefffffffe) {} else
210 if (a >= 0xffffffffff)
216 public static int test_0_blt_un () {
217 ulong a = 0xfffffffffe;
218 if (a >= 0xffffffffff)
221 if (a >= 0x1fffffffffe)
224 if (a >= 0xff00000000) {} else
227 if (a >= 0xfefffffffe) {} else
231 if (a >= 0xffffffffff)
237 public static int test_0_bgt () {
238 long a = 0xffffffffff;
239 if (a <= 0xfffffffffe)
242 if (a <= 0x1ffffffffff) {} else
245 if (a <= 0xff00000000)
248 if (a <= 0xfeffffffff)
252 if (a <= 0xffffffffff) {} else
258 public static int test_0_bgt_un () {
259 ulong a = 0xffffffffff;
260 if (a <= 0xfffffffffe)
263 if (a <= 0x1ffffffffff) {} else
266 if (a <= 0xff00000000)
269 if (a <= 0xfeffffffff)
273 if (a <= 0xffffffffff) {} else
279 public static int test_0_conv_to_i4 () {
285 public static int test_32_conv_to_u4 () {
291 public static int test_15_conv_to_u4_2 () {
292 long a = 0x10000000f;
297 public static int test_0_conv_from_i4 () {
309 public static int test_0_conv_from_i4_negative () {
322 public static int test_0_conv_from_r8 () {
331 public static int test_0_conv_from_r4 () {
341 public static int test_8_and () {
342 long a = 0xffffffffff;
347 public static int test_8_and_imm () {
348 long a = 0xffffffffff;
352 public static int test_10_or () {
358 public static int test_10_or_imm () {
363 public static int test_5_xor () {
369 public static int test_5_xor_imm () {
374 public static int test_5_add () {
380 public static int test_5_add_imm () {
385 public static int test_0_add_imm_carry () {
390 public static int test_0_add_imm_no_inc () {
391 // we can't blindly convert an add x, 1 to an inc x
392 long a = 0x1ffffffff;
395 if (c == ((a + 1) + 1))
400 public static int test_4_addcc_imm () {
403 return (int)(a - b + 1);
406 public static int test_5_sub () {
412 public static int test_5_sub_imm () {
417 public static int test_0_sub_imm_carry () {
419 return (int)((a - 1) + 1);
422 public static int test_0_add_ovf () {
426 i = System.Int64.MinValue;
431 if (k != System.Int64.MinValue)
435 i = System.Int64.MaxValue;
440 if (k != System.Int64.MaxValue)
444 i = System.Int64.MinValue;
445 j = System.Int64.MaxValue;
453 i = System.Int64.MaxValue;
454 j = System.Int64.MinValue;
462 i = System.Int64.MinValue + 1234;
467 if (k != System.Int64.MinValue)
471 i = System.Int64.MaxValue - 1234;
476 if (k != System.Int64.MaxValue)
482 public static int test_0_add_un_ovf () {
483 ulong n = (ulong)134217728 * 16;
484 ulong number = checked (n + (uint)0);
486 return number == n ? 0 : 1;
489 public static int test_0_sub_ovf () {
493 i = System.Int64.MinValue;
498 if (k != System.Int64.MinValue)
502 i = System.Int64.MaxValue;
507 if (k != System.Int64.MaxValue)
511 i = System.Int64.MinValue;
512 j = System.Int64.MinValue + 1234;
520 i = System.Int64.MaxValue;
525 if (k != System.Int64.MaxValue - 1234)
529 i = System.Int64.MaxValue - 1234;
534 if (k != System.Int64.MaxValue)
538 i = System.Int64.MinValue + 1234;
543 if (k != System.Int64.MinValue)
549 public static int test_0_sub_ovf_un () {
553 i = System.UInt64.MaxValue;
558 if (k != System.UInt64.MaxValue)
562 i = System.UInt64.MaxValue;
563 j = System.UInt64.MaxValue;
573 public static int test_2_neg () {
578 public static int test_0_neg_large () {
579 long min = -9223372036854775808;
581 ulong ul = (ulong)min;
582 return (min == -(long)ul) ? 0 : 1;
586 public static int test_5_shift ()
616 public static int test_1_shift_u ()
621 // The JIT optimizes this
630 public static int test_1_shift_u_32 ()
636 // Avoid constant folding
637 for (int i = 0; i < 32; ++i)
640 if ((a >> count) != 0xFFFFFFFFUL)
646 public static int test_1_simple_neg () {
654 public static int test_2_compare () {
663 public static int test_9_alu ()
708 public static int test_24_mul () {
714 public static int test_24_mul_ovf () {
725 public static int test_24_mul_un () {
731 public static int test_24_mul_ovf_un () {
742 public static int test_0_mul_imm () {
753 if ((i * 1234) != 4936)
761 if ((i * -1234) != -4936)
767 public static int test_0_mul_imm_opt ()
820 if ((i * 100) != 100)
823 if ((i * 100) != -100)
829 public static int test_4_divun () {
835 public static int test_1431655764_bigdivun_imm () {
842 public static int test_1431655764_bigdivun () {
850 public static int test_1_remun () {
856 public static int test_2_bigremun () {
864 public static int test_0_ceq () {
868 long d = 0xff00000002;
870 bool val = (a == b); // this should produce a ceq
874 val = (a == c); // this should produce a ceq
878 val = (a == d); // this should produce a ceq
885 public static int test_0_ceq_complex () {
894 public static int test_0_clt () {
898 long d = 0xff00000002L;
901 bool val = (a < b); // this should produce a clt
905 val = (a < c); // this should produce a clt
909 val = (c < a); // this should produce a clt
913 val = (e < d); // this should produce a clt
917 val = (d < e); // this should produce a clt
924 public static int test_0_clt_un () {
928 ulong d = 0xff00000002;
929 ulong e = 0xffffffffffffffff;
931 bool val = (a < b); // this should produce a clt_un
935 val = (a < c); // this should produce a clt_un
939 val = (d < e); // this should produce a clt_un
943 val = (e < d); // this should produce a clt_un
950 public static int test_0_cgt () {
954 long d = 0xff00000002L;
957 bool val = (a > b); // this should produce a cgt
961 val = (a > c); // this should produce a cgt
965 val = (c > a); // this should produce a cgt
969 val = (e > d); // this should produce a cgt
973 val = (d > e); // this should produce a cgt
980 public static int test_0_cgt_un () {
984 ulong d = 0xff00000002;
985 ulong e = 0xffffffffffffffff;
987 bool val = (a > b); // this should produce a cgt_un
991 val = (a > c); // this should produce a cgt_un
995 val = (d > e); // this should produce a cgt_un
999 val = (e > d); // this should produce a cgt_un
1006 static long return_5low () {
1010 static long return_5high () {
1014 public static int test_3_long_ret () {
1015 long val = return_5low ();
1016 return (int) (val - 2);
1019 public static int test_1_long_ret2 () {
1020 long val = return_5high ();
1021 if (val > 0xffffffff)
1026 public static int test_3_byte_cast () {
1027 ulong val = 0xff00ff00f0f0f0f0;
1029 b = (byte) (val & 0xFF);
1036 public static int test_4_ushort_cast () {
1037 ulong val = 0xff00ff00f0f0f0f0;
1039 b = (ushort) (val & 0xFFFF);
1045 public static int test_500_mul_div () {
1049 long res = val * exp / maxexp;
1054 public static int test_3_checked_cast_un () {
1058 checked { j = (long)i; }
1065 public static int test_4_checked_cast () {
1069 checked { j = (ulong)i; }
1076 public static int test_12_checked_i1_cast () {
1084 public static int test_127_checked_i1_cast_un () {
1092 public static int test_1234_checked_i2_cast () {
1100 public static int test_32767_checked_i2_cast_un () {
1108 public static int test_1234_checked_i4_cast () {
1116 public static int test_10_int_uint_compare () {
1119 for (int i = 0; i < size; ++i) {
1125 public static int test_0_ulong_regress () {
1126 ulong u = 4257145737;
1128 return (u == 4257145736) ? 0 : 1;
1131 public static int test_0_ulong_regress2 () {
1133 ulong sum_p = 2897079476 + (ulong) (1 << p2);
1134 return (sum_p == 749595828) ? 0 : 1;
1137 public static int test_0_assemble_long ()
1140 ulong x = 0x12345678;
1144 ulong z = ((x - y) << 32) | a;
1146 if (z != 0x1234567700000005)
1152 public static int test_0_hash ()
1154 ulong x = 0x1234567887654321;
1155 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
1156 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
1162 public static int test_0_shift_regress () {
1167 return ((a >> (b - c)) == 0) ? 0 : 1;
1170 public static int test_1234_conv_ovf_u8 () {
1179 public static int test_0_regress_cprop_80738 () {
1180 int hours = Int32.MinValue;
1181 int hrssec = (hours * 3600);
1182 long t = ((long)(hrssec) * 1000L);
1184 return t == 0 ? 0 : 1;