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 () {
163 public static int test_0_conv_from_i4 () {
175 public static int test_0_conv_from_i4_negative () {
188 public static int test_0_conv_from_r8 () {
197 public static int test_0_conv_from_r4 () {
207 public static int test_8_and () {
208 long a = 0xffffffffff;
213 public static int test_8_and_imm () {
214 long a = 0xffffffffff;
218 public static int test_10_or () {
224 public static int test_10_or_imm () {
229 public static int test_5_xor () {
235 public static int test_5_xor_imm () {
240 public static int test_5_add () {
246 public static int test_5_add_imm () {
251 public static int test_0_add_imm_carry () {
256 public static int test_0_add_imm_no_inc () {
257 // we can't blindly convert an add x, 1 to an inc x
258 long a = 0x1ffffffff;
261 if (c == ((a + 1) + 1))
266 public static int test_4_addcc_imm () {
269 return (int)(a - b + 1);
272 public static int test_5_sub () {
278 public static int test_5_sub_imm () {
283 public static int test_0_sub_imm_carry () {
285 return (int)((a - 1) + 1);
288 public static int test_2_neg () {
293 public static int test_0_neg_large () {
294 long min = -9223372036854775808;
296 ulong ul = (ulong)min;
297 return (min == -(long)ul) ? 0 : 1;
301 public static int test_0_shl () {
312 public static int test_1_rshift ()
322 public static int test_5_shift ()
352 public static int test_1_shift_u ()
357 // The JIT optimizes this
366 public static int test_1_simple_neg () {
374 public static int test_2_compare () {
383 public static int test_9_alu ()
428 public static int test_24_mul () {
434 public static int test_24_mul_ovf () {
445 public static int test_24_mul_un () {
451 public static int test_24_mul_ovf_un () {
462 public static int test_4_divun () {
468 public static int test_1431655764_bigdivun_imm () {
475 public static int test_1431655764_bigdivun () {
483 public static int test_1_remun () {
489 public static int test_2_bigremun () {
497 public static int test_0_ceq () {
501 long d = 0xff00000002;
503 bool val = (a == b); // this should produce a ceq
507 val = (a == c); // this should produce a ceq
511 val = (a == d); // this should produce a ceq
518 public static int test_0_ceq_complex () {
527 public static int test_0_clt () {
531 long d = 0xff00000002L;
534 bool val = (a < b); // this should produce a clt
538 val = (a < c); // this should produce a clt
542 val = (c < a); // this should produce a clt
546 val = (e < d); // this should produce a clt
550 val = (d < e); // this should produce a clt
557 public static int test_0_clt_un () {
561 ulong d = 0xff00000002;
562 ulong e = 0xffffffffffffffff;
564 bool val = (a < b); // this should produce a clt_un
568 val = (a < c); // this should produce a clt_un
572 val = (d < e); // this should produce a clt_un
576 val = (e < d); // this should produce a clt_un
583 public static int test_0_cgt () {
587 long d = 0xff00000002L;
590 bool val = (a > b); // this should produce a cgt
594 val = (a > c); // this should produce a cgt
598 val = (c > a); // this should produce a cgt
602 val = (e > d); // this should produce a cgt
606 val = (d > e); // this should produce a cgt
613 public static int test_0_cgt_un () {
617 ulong d = 0xff00000002;
618 ulong e = 0xffffffffffffffff;
620 bool val = (a > b); // this should produce a cgt_un
624 val = (a > c); // this should produce a cgt_un
628 val = (d > e); // this should produce a cgt_un
632 val = (e > d); // this should produce a cgt_un
639 static long return_5low () {
643 static long return_5high () {
647 public static int test_3_long_ret () {
648 long val = return_5low ();
649 return (int) (val - 2);
652 public static int test_1_long_ret2 () {
653 long val = return_5high ();
654 if (val > 0xffffffff)
659 public static int test_3_byte_cast () {
660 ulong val = 0xff00ff00f0f0f0f0;
662 b = (byte) (val & 0xFF);
669 public static int test_4_ushort_cast () {
670 ulong val = 0xff00ff00f0f0f0f0;
672 b = (ushort) (val & 0xFFFF);
678 public static int test_500_mul_div () {
682 long res = val * exp / maxexp;
687 static long position = 0;
689 public static int test_4_static_inc_long () {
697 return (int)position;
700 static void doit (double value, out long m) {
704 public static int test_3_checked_cast_un () {
708 checked { j = (long)i; }
715 public static int test_4_checked_cast () {
719 checked { j = (ulong)i; }
726 public static int test_12_checked_i1_cast () {
734 public static int test_127_checked_i1_cast_un () {
742 public static int test_1234_checked_i2_cast () {
750 public static int test_32767_checked_i2_cast_un () {
758 public static int test_1234_checked_i4_cast () {
766 public static int test_10_int_uint_compare () {
769 for (int i = 0; i < size; ++i) {
775 public static int test_0_ftol_clobber () {
783 public static int test_0_ulong_regress () {
784 ulong u = 4257145737;
786 return (u == 4257145736) ? 0 : 1;
789 public static int test_0_assemble_long ()
792 ulong x = 0x12345678;
796 ulong z = ((x - y) << 32) | a;
798 if (z != 0x1234567700000005)
804 public static int test_0_hash ()
806 ulong x = 0x1234567887654321;
807 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
808 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
814 public static int test_0_shift_regress () {
819 return ((a >> (b - c)) == 0) ? 0 : 1;