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_10_simple_cast () {
37 static int test_1_bigmul1 () {
43 c = (long)a * (long)b;
49 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 static int test_1_bigmul3 () {
62 c = (ulong) a * (ulong) b;
68 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 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 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 static int test_0_beq () {
96 long a = 0xffffffffff;
97 if (a != 0xffffffffff)
102 static int test_0_bne_un () {
103 long a = 0xffffffffff;
104 if (a == 0xfffffffffe)
109 static int test_0_ble () {
110 long a = 0xffffffffff;
111 if (a > 0xffffffffff)
116 static int test_0_ble_un () {
117 ulong a = 0xffffffffff;
118 if (a > 0xffffffffff)
123 static int test_0_bge () {
124 long a = 0xffffffffff;
125 if (a < 0xffffffffff)
130 static int test_0_bge_un () {
131 ulong a = 0xffffffffff;
132 if (a < 0xffffffffff)
137 static int test_0_blt () {
138 long a = 0xfffffffffe;
139 if (a >= 0xffffffffff)
144 static int test_0_blt_un () {
145 ulong a = 0xfffffffffe;
146 if (a >= 0xffffffffff)
151 static int test_0_bgt () {
152 long a = 0xffffffffff;
153 if (a <= 0xfffffffffe)
158 static int test_0_conv_to_i4 () {
163 static int test_0_conv_from_i4 () {
175 static int test_0_conv_from_i4_negative () {
188 static int test_0_conv_from_r8 () {
197 static int test_0_conv_from_r4 () {
207 static int test_8_and () {
208 long a = 0xffffffffff;
213 static int test_8_and_imm () {
214 long a = 0xffffffffff;
218 static int test_10_or () {
224 static int test_10_or_imm () {
229 static int test_5_xor () {
235 static int test_5_xor_imm () {
240 static int test_5_add () {
246 static int test_5_add_imm () {
251 static int test_0_add_imm_carry () {
256 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 static int test_4_addcc_imm () {
269 return (int)(a - b + 1);
272 static int test_5_sub () {
278 static int test_5_sub_imm () {
283 static int test_0_sub_imm_carry () {
285 return (int)((a - 1) + 1);
288 static int test_2_neg () {
293 static int test_0_neg_large () {
294 long min = -9223372036854775808;
296 ulong ul = (ulong)min;
297 return (min == -(long)ul) ? 0 : 1;
301 static int test_0_shl () {
312 static int test_1_rshift ()
322 static int test_5_shift ()
352 static int test_1_shift_u ()
358 // The JIT optimizes this
367 static int test_1_simple_neg () {
375 static int test_2_compare () {
384 static int test_9_alu ()
429 static int test_24_mul () {
435 static int test_24_mul_ovf () {
446 static int test_24_mul_un () {
452 static int test_24_mul_ovf_un () {
463 static int test_4_divun () {
469 static int test_1431655764_bigdivun_imm () {
476 static int test_1431655764_bigdivun () {
484 static int test_1_remun () {
490 static int test_2_bigremun () {
498 static int test_0_ceq () {
502 long d = 0xff00000002;
504 bool val = (a == b); // this should produce a ceq
508 val = (a == c); // this should produce a ceq
512 val = (a == d); // this should produce a ceq
519 static int test_0_ceq_complex () {
528 static int test_0_clt () {
532 long d = 0xff00000002L;
535 bool val = (a < b); // this should produce a clt
539 val = (a < c); // this should produce a clt
543 val = (c < a); // this should produce a clt
547 val = (e < d); // this should produce a clt
551 val = (d < e); // this should produce a clt
558 static int test_0_clt_un () {
562 ulong d = 0xff00000002;
563 ulong e = 0xffffffffffffffff;
565 bool val = (a < b); // this should produce a clt_un
569 val = (a < c); // this should produce a clt_un
573 val = (d < e); // this should produce a clt_un
577 val = (e < d); // this should produce a clt_un
584 static int test_0_cgt () {
588 long d = 0xff00000002L;
591 bool val = (a > b); // this should produce a cgt
595 val = (a > c); // this should produce a cgt
599 val = (c > a); // this should produce a cgt
603 val = (e > d); // this should produce a cgt
607 val = (d > e); // this should produce a cgt
614 static int test_0_cgt_un () {
618 ulong d = 0xff00000002;
619 ulong e = 0xffffffffffffffff;
621 bool val = (a > b); // this should produce a cgt_un
625 val = (a > c); // this should produce a cgt_un
629 val = (d > e); // this should produce a cgt_un
633 val = (e > d); // this should produce a cgt_un
640 static long return_5low () {
644 static long return_5high () {
648 static int test_3_long_ret () {
649 long val = return_5low ();
650 return (int) (val - 2);
653 static int test_1_long_ret2 () {
654 long val = return_5high ();
655 if (val > 0xffffffff)
660 static int test_3_byte_cast () {
661 ulong val = 0xff00ff00f0f0f0f0;
663 b = (byte) (val & 0xFF);
670 static int test_4_ushort_cast () {
671 ulong val = 0xff00ff00f0f0f0f0;
673 b = (ushort) (val & 0xFFFF);
679 static int test_500_mul_div () {
683 long res = val * exp / maxexp;
688 static long position = 0;
690 static int test_4_static_inc_long () {
698 return (int)position;
701 static void doit (double value, out long m) {
705 static int test_3_checked_cast_un () {
709 checked { j = (long)i; }
716 static int test_4_checked_cast () {
720 checked { j = (ulong)i; }
727 static int test_1234_checked_i2_cast () {
735 static int test_1234_checked_i4_cast () {
743 static int test_10_int_uint_compare () {
746 for (int i = 0; i < size; ++i) {
752 static int test_0_ftol_clobber () {
760 static int test_71_long_shift_right () {
761 ulong value = 38654838087;
763 byte [] buffer = new byte [1];
764 buffer [x] = ((byte)(value >> x));
768 static int test_0_ulong_regress () {
769 ulong u = 4257145737;
771 return (u == 4257145736) ? 0 : 1;
775 static int test_0_addsub_mem ()
792 static int test_0_sh32_mem ()
794 y = 0x0102130405060708;
800 y = 0x0102130405060708;
803 if (y != 0x0506070800000000)
806 x = 0x0102130405060708;
809 if (x != 0x0506070800000000)
815 static int test_0_assemble_long ()
818 ulong x = 0x12345678;
822 ulong z = ((x - y) << 32) | a;
824 if (z != 0x1234567700000005)
830 static int test_0_hash ()
832 ulong x = 0x1234567887654321;
833 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
834 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
840 static int test_0_shift_regress () {
845 return ((a >> (b - c)) == 0) ? 0 : 1;