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 get_high_bit (ulong a) {
353 if ((a & 0x8000000000000000) != 0)
358 public static int test_1_and () {
359 ulong a = 0xabcd1234deadbeef;
360 return get_high_bit (a);
363 public static int test_10_or () {
369 public static int test_10_or_imm () {
374 public static int test_5_xor () {
380 public static int test_5_xor_imm () {
385 public static int test_5_add () {
391 public static int test_5_add_imm () {
396 public static int test_0_add_imm_carry () {
401 public static int test_0_add_imm_no_inc () {
402 // we can't blindly convert an add x, 1 to an inc x
403 long a = 0x1ffffffff;
406 if (c == ((a + 1) + 1))
411 public static int test_4_addcc_imm () {
414 return (int)(a - b + 1);
417 public static int test_5_sub () {
423 public static int test_5_sub_imm () {
428 public static int test_0_sub_imm_carry () {
430 return (int)((a - 1) + 1);
433 public static int test_0_add_ovf () {
437 i = System.Int64.MinValue;
442 if (k != System.Int64.MinValue)
446 i = System.Int64.MaxValue;
451 if (k != System.Int64.MaxValue)
455 i = System.Int64.MinValue;
456 j = System.Int64.MaxValue;
464 i = System.Int64.MaxValue;
465 j = System.Int64.MinValue;
473 i = System.Int64.MinValue + 1234;
478 if (k != System.Int64.MinValue)
482 i = System.Int64.MaxValue - 1234;
487 if (k != System.Int64.MaxValue)
493 public static int test_0_add_un_ovf () {
494 ulong n = (ulong)134217728 * 16;
495 ulong number = checked (n + (uint)0);
497 return number == n ? 0 : 1;
500 public static int test_0_sub_ovf () {
504 i = System.Int64.MinValue;
509 if (k != System.Int64.MinValue)
513 i = System.Int64.MaxValue;
518 if (k != System.Int64.MaxValue)
522 i = System.Int64.MinValue;
523 j = System.Int64.MinValue + 1234;
531 i = System.Int64.MaxValue;
536 if (k != System.Int64.MaxValue - 1234)
540 i = System.Int64.MaxValue - 1234;
545 if (k != System.Int64.MaxValue)
549 i = System.Int64.MinValue + 1234;
554 if (k != System.Int64.MinValue)
560 public static int test_0_sub_ovf_un () {
564 i = System.UInt64.MaxValue;
569 if (k != System.UInt64.MaxValue)
573 i = System.UInt64.MaxValue;
574 j = System.UInt64.MaxValue;
584 public static int test_2_neg () {
589 public static int test_0_neg_large () {
590 long min = -9223372036854775808;
592 ulong ul = (ulong)min;
593 return (min == -(long)ul) ? 0 : 1;
597 public static int test_5_shift ()
627 public static int test_1_shift_u ()
632 // The JIT optimizes this
641 public static int test_1_shift_u_32 ()
647 // Avoid constant folding
648 for (int i = 0; i < 32; ++i)
651 if ((a >> count) != 0xFFFFFFFFUL)
657 public static int test_1_simple_neg () {
665 public static int test_2_compare () {
674 public static int test_9_alu ()
719 public static int test_24_mul () {
725 public static int test_24_mul_ovf () {
736 public static int test_24_mul_un () {
742 public static int test_24_mul_ovf_un () {
753 public static int test_0_mul_imm () {
764 if ((i * 1234) != 4936)
772 if ((i * -1234) != -4936)
778 public static int test_0_mul_imm_opt ()
831 if ((i * 100) != 100)
834 if ((i * 100) != -100)
840 public static int test_4_divun () {
846 public static int test_1431655764_bigdivun_imm () {
853 public static int test_1431655764_bigdivun () {
861 public static int test_1_remun () {
867 public static int test_2_bigremun () {
875 public static int test_0_ceq () {
879 long d = 0xff00000002;
881 bool val = (a == b); // this should produce a ceq
885 val = (a == c); // this should produce a ceq
889 val = (a == d); // this should produce a ceq
896 public static int test_0_ceq_complex () {
905 public static int test_0_clt () {
909 long d = 0xff00000002L;
912 bool val = (a < b); // this should produce a clt
916 val = (a < c); // this should produce a clt
920 val = (c < a); // this should produce a clt
924 val = (e < d); // this should produce a clt
928 val = (d < e); // this should produce a clt
935 public static int test_0_clt_un () {
939 ulong d = 0xff00000002;
940 ulong e = 0xffffffffffffffff;
942 bool val = (a < b); // this should produce a clt_un
946 val = (a < c); // this should produce a clt_un
950 val = (d < e); // this should produce a clt_un
954 val = (e < d); // this should produce a clt_un
961 public static int test_0_cgt () {
965 long d = 0xff00000002L;
968 bool val = (a > b); // this should produce a cgt
972 val = (a > c); // this should produce a cgt
976 val = (c > a); // this should produce a cgt
980 val = (e > d); // this should produce a cgt
984 val = (d > e); // this should produce a cgt
991 public static int test_0_cgt_un () {
995 ulong d = 0xff00000002;
996 ulong e = 0xffffffffffffffff;
998 bool val = (a > b); // this should produce a cgt_un
1002 val = (a > c); // this should produce a cgt_un
1006 val = (d > e); // this should produce a cgt_un
1010 val = (e > d); // this should produce a cgt_un
1017 static long return_5low () {
1021 static long return_5high () {
1025 public static int test_3_long_ret () {
1026 long val = return_5low ();
1027 return (int) (val - 2);
1030 public static int test_1_long_ret2 () {
1031 long val = return_5high ();
1032 if (val > 0xffffffff)
1037 public static int test_3_byte_cast () {
1038 ulong val = 0xff00ff00f0f0f0f0;
1040 b = (byte) (val & 0xFF);
1047 public static int test_4_ushort_cast () {
1048 ulong val = 0xff00ff00f0f0f0f0;
1050 b = (ushort) (val & 0xFFFF);
1056 public static int test_500_mul_div () {
1060 long res = val * exp / maxexp;
1065 public static int test_3_checked_cast_un () {
1069 checked { j = (long)i; }
1076 public static int test_4_checked_cast () {
1080 checked { j = (ulong)i; }
1087 public static int test_12_checked_i1_cast () {
1095 public static int test_127_checked_i1_cast_un () {
1103 public static int test_1234_checked_i2_cast () {
1111 public static int test_32767_checked_i2_cast_un () {
1119 public static int test_1234_checked_i4_cast () {
1127 public static int test_10_int_uint_compare () {
1130 for (int i = 0; i < size; ++i) {
1136 public static int test_0_ulong_regress () {
1137 ulong u = 4257145737;
1139 return (u == 4257145736) ? 0 : 1;
1142 public static int test_0_ulong_regress2 () {
1144 ulong sum_p = 2897079476 + (ulong) (1 << p2);
1145 return (sum_p == 749595828) ? 0 : 1;
1148 public static int test_0_assemble_long ()
1151 ulong x = 0x12345678;
1155 ulong z = ((x - y) << 32) | a;
1157 if (z != 0x1234567700000005)
1163 public static int test_0_hash ()
1165 ulong x = 0x1234567887654321;
1166 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
1167 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
1173 public static int test_0_shift_regress () {
1178 return ((a >> (b - c)) == 0) ? 0 : 1;
1181 public static int test_1234_conv_ovf_u8 () {
1190 public static int test_0_regress_cprop_80738 () {
1191 int hours = Int32.MinValue;
1192 int hrssec = (hours * 3600);
1193 long t = ((long)(hrssec) * 1000L);
1195 return t == 0 ? 0 : 1;
1198 public static int test_0_conv_u () {
1200 int** dead = (int**) 0xdeadbeaf;
1201 long i = (long)dead;
1202 return (i == 0xdeadbeaf) ? 0 : 1;
1206 public static int test_0_lconv_to_u2 () {
1208 ulong value = (ulong)(short)-10;
1209 value = (ushort)value;
1210 return (value == 65526) ? 0 : 1;