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_0_add_ovf () {
292 i = System.Int64.MinValue;
297 if (k != System.Int64.MinValue)
301 i = System.Int64.MaxValue;
306 if (k != System.Int64.MaxValue)
310 i = System.Int64.MinValue;
311 j = System.Int64.MaxValue;
319 i = System.Int64.MaxValue;
320 j = System.Int64.MinValue;
328 i = System.Int64.MinValue + 1234;
333 if (k != System.Int64.MinValue)
337 i = System.Int64.MaxValue - 1234;
342 if (k != System.Int64.MaxValue)
348 public static int test_0_add_un_ovf () {
349 ulong n = (ulong)134217728 * 16;
350 ulong number = checked (n + (uint)0);
352 return number == n ? 0 : 1;
355 public static int test_0_sub_ovf () {
359 i = System.Int64.MinValue;
364 if (k != System.Int64.MinValue)
368 i = System.Int64.MaxValue;
373 if (k != System.Int64.MaxValue)
377 i = System.Int64.MinValue;
378 j = System.Int64.MinValue + 1234;
386 i = System.Int64.MaxValue;
391 if (k != System.Int64.MaxValue - 1234)
395 i = System.Int64.MaxValue - 1234;
400 if (k != System.Int64.MaxValue)
404 i = System.Int64.MinValue + 1234;
409 if (k != System.Int64.MinValue)
415 public static int test_0_sub_ovf_un () {
419 i = System.UInt64.MaxValue;
424 if (k != System.UInt64.MaxValue)
428 i = System.UInt64.MaxValue;
429 j = System.UInt64.MaxValue;
439 public static int test_2_neg () {
444 public static int test_0_neg_large () {
445 long min = -9223372036854775808;
447 ulong ul = (ulong)min;
448 return (min == -(long)ul) ? 0 : 1;
452 public static int test_5_shift ()
482 public static int test_1_shift_u ()
487 // The JIT optimizes this
496 public static int test_1_simple_neg () {
504 public static int test_2_compare () {
513 public static int test_9_alu ()
558 public static int test_24_mul () {
564 public static int test_24_mul_ovf () {
575 public static int test_24_mul_un () {
581 public static int test_24_mul_ovf_un () {
592 public static int test_0_mul_imm () {
603 if ((i * 1234) != 4936)
611 if ((i * -1234) != -4936)
617 public static int test_4_divun () {
623 public static int test_1431655764_bigdivun_imm () {
630 public static int test_1431655764_bigdivun () {
638 public static int test_1_remun () {
644 public static int test_2_bigremun () {
652 public static int test_0_ceq () {
656 long d = 0xff00000002;
658 bool val = (a == b); // this should produce a ceq
662 val = (a == c); // this should produce a ceq
666 val = (a == d); // this should produce a ceq
673 public static int test_0_ceq_complex () {
682 public static int test_0_clt () {
686 long d = 0xff00000002L;
689 bool val = (a < b); // this should produce a clt
693 val = (a < c); // this should produce a clt
697 val = (c < a); // this should produce a clt
701 val = (e < d); // this should produce a clt
705 val = (d < e); // this should produce a clt
712 public static int test_0_clt_un () {
716 ulong d = 0xff00000002;
717 ulong e = 0xffffffffffffffff;
719 bool val = (a < b); // this should produce a clt_un
723 val = (a < c); // this should produce a clt_un
727 val = (d < e); // this should produce a clt_un
731 val = (e < d); // this should produce a clt_un
738 public static int test_0_cgt () {
742 long d = 0xff00000002L;
745 bool val = (a > b); // this should produce a cgt
749 val = (a > c); // this should produce a cgt
753 val = (c > a); // this should produce a cgt
757 val = (e > d); // this should produce a cgt
761 val = (d > e); // this should produce a cgt
768 public static int test_0_cgt_un () {
772 ulong d = 0xff00000002;
773 ulong e = 0xffffffffffffffff;
775 bool val = (a > b); // this should produce a cgt_un
779 val = (a > c); // this should produce a cgt_un
783 val = (d > e); // this should produce a cgt_un
787 val = (e > d); // this should produce a cgt_un
794 static long return_5low () {
798 static long return_5high () {
802 public static int test_3_long_ret () {
803 long val = return_5low ();
804 return (int) (val - 2);
807 public static int test_1_long_ret2 () {
808 long val = return_5high ();
809 if (val > 0xffffffff)
814 public static int test_3_byte_cast () {
815 ulong val = 0xff00ff00f0f0f0f0;
817 b = (byte) (val & 0xFF);
824 public static int test_4_ushort_cast () {
825 ulong val = 0xff00ff00f0f0f0f0;
827 b = (ushort) (val & 0xFFFF);
833 public static int test_500_mul_div () {
837 long res = val * exp / maxexp;
842 static long position = 0;
844 public static int test_4_static_inc_long () {
852 return (int)position;
855 static void doit (double value, out long m) {
859 public static int test_3_checked_cast_un () {
863 checked { j = (long)i; }
870 public static int test_4_checked_cast () {
874 checked { j = (ulong)i; }
881 public static int test_12_checked_i1_cast () {
889 public static int test_127_checked_i1_cast_un () {
897 public static int test_1234_checked_i2_cast () {
905 public static int test_32767_checked_i2_cast_un () {
913 public static int test_1234_checked_i4_cast () {
921 public static int test_10_int_uint_compare () {
924 for (int i = 0; i < size; ++i) {
930 public static int test_0_ftol_clobber () {
938 public static int test_0_ulong_regress () {
939 ulong u = 4257145737;
941 return (u == 4257145736) ? 0 : 1;
944 public static int test_0_assemble_long ()
947 ulong x = 0x12345678;
951 ulong z = ((x - y) << 32) | a;
953 if (z != 0x1234567700000005)
959 public static int test_0_hash ()
961 ulong x = 0x1234567887654321;
962 int h = (int)(x & 0xffffffff) ^ (int)(x >> 32);
963 if (h != unchecked ((int)(0x87654321 ^ 0x12345678)))
969 public static int test_0_shift_regress () {
974 return ((a >> (b - c)) == 0) ? 0 : 1;