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_0_mul_imm_opt ()
683 if ((i * 100) != 100)
686 if ((i * 100) != -100)
692 public static int test_4_divun () {
698 public static int test_1431655764_bigdivun_imm () {
705 public static int test_1431655764_bigdivun () {
713 public static int test_1_remun () {
719 public static int test_2_bigremun () {
727 public static int test_0_ceq () {
731 long d = 0xff00000002;
733 bool val = (a == b); // this should produce a ceq
737 val = (a == c); // this should produce a ceq
741 val = (a == d); // this should produce a ceq
748 public static int test_0_ceq_complex () {
757 public static int test_0_clt () {
761 long d = 0xff00000002L;
764 bool val = (a < b); // this should produce a clt
768 val = (a < c); // this should produce a clt
772 val = (c < a); // this should produce a clt
776 val = (e < d); // this should produce a clt
780 val = (d < e); // this should produce a clt
787 public static int test_0_clt_un () {
791 ulong d = 0xff00000002;
792 ulong e = 0xffffffffffffffff;
794 bool val = (a < b); // this should produce a clt_un
798 val = (a < c); // this should produce a clt_un
802 val = (d < e); // this should produce a clt_un
806 val = (e < d); // this should produce a clt_un
813 public static int test_0_cgt () {
817 long d = 0xff00000002L;
820 bool val = (a > b); // this should produce a cgt
824 val = (a > c); // this should produce a cgt
828 val = (c > a); // this should produce a cgt
832 val = (e > d); // this should produce a cgt
836 val = (d > e); // this should produce a cgt
843 public static int test_0_cgt_un () {
847 ulong d = 0xff00000002;
848 ulong e = 0xffffffffffffffff;
850 bool val = (a > b); // this should produce a cgt_un
854 val = (a > c); // this should produce a cgt_un
858 val = (d > e); // this should produce a cgt_un
862 val = (e > d); // this should produce a cgt_un
869 static long return_5low () {
873 static long return_5high () {
877 public static int test_3_long_ret () {
878 long val = return_5low ();
879 return (int) (val - 2);
882 public static int test_1_long_ret2 () {
883 long val = return_5high ();
884 if (val > 0xffffffff)
889 public static int test_3_byte_cast () {
890 ulong val = 0xff00ff00f0f0f0f0;
892 b = (byte) (val & 0xFF);
899 public static int test_4_ushort_cast () {
900 ulong val = 0xff00ff00f0f0f0f0;
902 b = (ushort) (val & 0xFFFF);
908 public static int test_500_mul_div () {
912 long res = val * exp / maxexp;
917 static long position = 0;
919 public static int test_4_static_inc_long () {
927 return (int)position;
930 static void doit (double value, out long m) {
934 public static int test_3_checked_cast_un () {
938 checked { j = (long)i; }
945 public static int test_4_checked_cast () {
949 checked { j = (ulong)i; }
956 public static int test_12_checked_i1_cast () {
964 public static int test_127_checked_i1_cast_un () {
972 public static int test_1234_checked_i2_cast () {
980 public static int test_32767_checked_i2_cast_un () {
988 public static int test_1234_checked_i4_cast () {
996 public static int test_10_int_uint_compare () {
999 for (int i = 0; i < size; ++i) {
1005 public static int test_0_ftol_clobber () {
1013 public static int test_0_ulong_regress () {
1014 ulong u = 4257145737;
1016 return (u == 4257145736) ? 0 : 1;
1019 public static int test_0_assemble_long ()
1022 ulong x = 0x12345678;
1026 ulong z = ((x - y) << 32) | a;
1028 if (z != 0x1234567700000005)
1034 public static int test_0_hash ()
1036 ulong x = 0x1234567887654321;
1037 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
1038 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
1044 public static int test_0_shift_regress () {
1049 return ((a >> (b - c)) == 0) ? 0 : 1;