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 () {
201 public static int test_0_conv_from_r8 () {
210 public static int test_0_conv_from_r4 () {
220 public static int test_8_and () {
221 long a = 0xffffffffff;
226 public static int test_8_and_imm () {
227 long a = 0xffffffffff;
231 public static int test_10_or () {
237 public static int test_10_or_imm () {
242 public static int test_5_xor () {
248 public static int test_5_xor_imm () {
253 public static int test_5_add () {
259 public static int test_5_add_imm () {
264 public static int test_0_add_imm_carry () {
269 public static int test_0_add_imm_no_inc () {
270 // we can't blindly convert an add x, 1 to an inc x
271 long a = 0x1ffffffff;
274 if (c == ((a + 1) + 1))
279 public static int test_4_addcc_imm () {
282 return (int)(a - b + 1);
285 public static int test_5_sub () {
291 public static int test_5_sub_imm () {
296 public static int test_0_sub_imm_carry () {
298 return (int)((a - 1) + 1);
301 public static int test_0_add_ovf () {
305 i = System.Int64.MinValue;
310 if (k != System.Int64.MinValue)
314 i = System.Int64.MaxValue;
319 if (k != System.Int64.MaxValue)
323 i = System.Int64.MinValue;
324 j = System.Int64.MaxValue;
332 i = System.Int64.MaxValue;
333 j = System.Int64.MinValue;
341 i = System.Int64.MinValue + 1234;
346 if (k != System.Int64.MinValue)
350 i = System.Int64.MaxValue - 1234;
355 if (k != System.Int64.MaxValue)
361 public static int test_0_add_un_ovf () {
362 ulong n = (ulong)134217728 * 16;
363 ulong number = checked (n + (uint)0);
365 return number == n ? 0 : 1;
368 public static int test_0_sub_ovf () {
372 i = System.Int64.MinValue;
377 if (k != System.Int64.MinValue)
381 i = System.Int64.MaxValue;
386 if (k != System.Int64.MaxValue)
390 i = System.Int64.MinValue;
391 j = System.Int64.MinValue + 1234;
399 i = System.Int64.MaxValue;
404 if (k != System.Int64.MaxValue - 1234)
408 i = System.Int64.MaxValue - 1234;
413 if (k != System.Int64.MaxValue)
417 i = System.Int64.MinValue + 1234;
422 if (k != System.Int64.MinValue)
428 public static int test_0_sub_ovf_un () {
432 i = System.UInt64.MaxValue;
437 if (k != System.UInt64.MaxValue)
441 i = System.UInt64.MaxValue;
442 j = System.UInt64.MaxValue;
452 public static int test_2_neg () {
457 public static int test_0_neg_large () {
458 long min = -9223372036854775808;
460 ulong ul = (ulong)min;
461 return (min == -(long)ul) ? 0 : 1;
465 public static int test_5_shift ()
495 public static int test_1_shift_u ()
500 // The JIT optimizes this
509 public static int test_1_simple_neg () {
517 public static int test_2_compare () {
526 public static int test_9_alu ()
571 public static int test_24_mul () {
577 public static int test_24_mul_ovf () {
588 public static int test_24_mul_un () {
594 public static int test_24_mul_ovf_un () {
605 public static int test_0_mul_imm () {
616 if ((i * 1234) != 4936)
624 if ((i * -1234) != -4936)
630 public static int test_4_divun () {
636 public static int test_1431655764_bigdivun_imm () {
643 public static int test_1431655764_bigdivun () {
651 public static int test_1_remun () {
657 public static int test_2_bigremun () {
665 public static int test_0_ceq () {
669 long d = 0xff00000002;
671 bool val = (a == b); // this should produce a ceq
675 val = (a == c); // this should produce a ceq
679 val = (a == d); // this should produce a ceq
686 public static int test_0_ceq_complex () {
695 public static int test_0_clt () {
699 long d = 0xff00000002L;
702 bool val = (a < b); // this should produce a clt
706 val = (a < c); // this should produce a clt
710 val = (c < a); // this should produce a clt
714 val = (e < d); // this should produce a clt
718 val = (d < e); // this should produce a clt
725 public static int test_0_clt_un () {
729 ulong d = 0xff00000002;
730 ulong e = 0xffffffffffffffff;
732 bool val = (a < b); // this should produce a clt_un
736 val = (a < c); // this should produce a clt_un
740 val = (d < e); // this should produce a clt_un
744 val = (e < d); // this should produce a clt_un
751 public static int test_0_cgt () {
755 long d = 0xff00000002L;
758 bool val = (a > b); // this should produce a cgt
762 val = (a > c); // this should produce a cgt
766 val = (c > a); // this should produce a cgt
770 val = (e > d); // this should produce a cgt
774 val = (d > e); // this should produce a cgt
781 public static int test_0_cgt_un () {
785 ulong d = 0xff00000002;
786 ulong e = 0xffffffffffffffff;
788 bool val = (a > b); // this should produce a cgt_un
792 val = (a > c); // this should produce a cgt_un
796 val = (d > e); // this should produce a cgt_un
800 val = (e > d); // this should produce a cgt_un
807 static long return_5low () {
811 static long return_5high () {
815 public static int test_3_long_ret () {
816 long val = return_5low ();
817 return (int) (val - 2);
820 public static int test_1_long_ret2 () {
821 long val = return_5high ();
822 if (val > 0xffffffff)
827 public static int test_3_byte_cast () {
828 ulong val = 0xff00ff00f0f0f0f0;
830 b = (byte) (val & 0xFF);
837 public static int test_4_ushort_cast () {
838 ulong val = 0xff00ff00f0f0f0f0;
840 b = (ushort) (val & 0xFFFF);
846 public static int test_500_mul_div () {
850 long res = val * exp / maxexp;
855 static long position = 0;
857 public static int test_4_static_inc_long () {
865 return (int)position;
868 static void doit (double value, out long m) {
872 public static int test_3_checked_cast_un () {
876 checked { j = (long)i; }
883 public static int test_4_checked_cast () {
887 checked { j = (ulong)i; }
894 public static int test_12_checked_i1_cast () {
902 public static int test_127_checked_i1_cast_un () {
910 public static int test_1234_checked_i2_cast () {
918 public static int test_32767_checked_i2_cast_un () {
926 public static int test_1234_checked_i4_cast () {
934 public static int test_10_int_uint_compare () {
937 for (int i = 0; i < size; ++i) {
943 public static int test_0_ftol_clobber () {
951 public static int test_0_ulong_regress () {
952 ulong u = 4257145737;
954 return (u == 4257145736) ? 0 : 1;
957 public static int test_0_assemble_long ()
960 ulong x = 0x12345678;
964 ulong z = ((x - y) << 32) | a;
966 if (z != 0x1234567700000005)
972 public static int test_0_hash ()
974 ulong x = 0x1234567887654321;
975 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
976 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
982 public static int test_0_shift_regress () {
987 return ((a >> (b - c)) == 0) ? 0 : 1;