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 void dummy () {
35 static int test_0_return () {
40 static int dummy1 () {
44 static int test_2_int_return () {
51 static int add1 (int val) {
55 static int test_1_int_pass () {
62 static int add_many (int val, short t, byte b, int da) {
63 return val + t + b + da;
66 static int test_1_int_pass_many () {
68 int r = add_many (5, 2, b, 1);
74 unsafe static float GetFloat (byte *ptr) {
78 unsafe public static float GetFloat(float value)
80 return GetFloat((byte *)&value);
84 static int test_2_inline_saved_arg_type () {
86 return GetFloat (f) == f? 2: 1;
89 static int pass_many_types (int a, long b, int c, long d) {
90 return a + (int)b + c + (int)d;
93 static int test_5_pass_longs () {
94 return pass_many_types (1, 2, -5, 7);
97 static int overflow_registers (int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
98 return a+b+c+d+e+f+g+h+i+j;
101 static int test_55_pass_even_more () {
102 return overflow_registers (1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
105 static int pass_ints_longs (int a, long b, long c, long d, long e, int f, long g) {
106 return (int)(a + b + c + d + e + f + g);
109 static int test_1_sparc_argument_passing () {
110 // The 4. argument tests split reg/mem argument passing
111 // The 5. argument tests mem argument passing
112 // The 7. argument tests passing longs in misaligned memory
113 // The MaxValues are needed so the MS word of the long is not 0
114 return pass_ints_longs (1, 2, System.Int64.MaxValue, System.Int64.MinValue, System.Int64.MaxValue, 0, System.Int64.MinValue);
117 static int pass_bytes (byte a, byte b, byte c, byte d, byte e, byte f, byte g) {
118 return (int)(a + b + c + d + e + f + g);
121 static int test_21_sparc_byte_argument_passing () {
122 return pass_bytes (0, 1, 2, 3, 4, 5, 6);
125 static int pass_sbytes (sbyte a, sbyte b, sbyte c, sbyte d, sbyte e, sbyte f, sbyte g) {
126 return (int)(a + b + c + d + e + f + g);
129 static int test_21_sparc_sbyte_argument_passing () {
130 return pass_sbytes (0, 1, 2, 3, 4, 5, 6);
133 static int pass_shorts (short a, short b, short c, short d, short e, short f, short g) {
134 return (int)(a + b + c + d + e + f + g);
137 static int test_21_sparc_short_argument_passing () {
138 return pass_shorts (0, 1, 2, 3, 4, 5, 6);
141 static int pass_floats_doubles (float a, double b, double c, double d, double e, float f, double g) {
142 return (int)(a + b + c + d + e + f + g);
145 static int test_721_sparc_float_argument_passing () {
146 return pass_floats_doubles (100.0f, 101.0, 102.0, 103.0, 104.0, 105.0f, 106.0);
149 static float pass_floats (float a, float b, float c, float d, float e, float f, float g, float h, float i, float j) {
150 return a + b + c + d + e + f + g + h + i + j;
153 static int test_55_sparc_float_argument_passing2 () {
154 return (int)pass_floats (1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f);
157 // The first argument must be passed on a dword aligned stack location
158 static int pass_byref_ints_longs (ref long a, ref int b, ref byte c, ref short d, ref long e, ref int f, ref long g) {
159 return (int)(a + b + c + d + e + f + g);
162 static int pass_takeaddr_ints_longs (long a, int b, byte c, short d, long e, int f, long g) {
163 return pass_byref_ints_longs (ref a, ref b, ref c, ref d, ref e, ref f, ref g);
166 // Test that arguments are moved to the stack from incoming registers
167 // when the argument must reside in the stack because its address is taken
168 static int test_2_sparc_takeaddr_argument_passing () {
169 return pass_takeaddr_ints_longs (1, 2, 253, -253, System.Int64.MaxValue, 0, System.Int64.MinValue);
172 static int pass_byref_floats_doubles (ref float a, ref double b, ref double c, ref double d, ref double e, ref float f, ref double g) {
173 return (int)(a + b + c + d + e + f + g);
176 static int pass_takeaddr_floats_doubles (float a, double b, double c, double d, double e, float f, double g) {
177 return pass_byref_floats_doubles (ref a, ref b, ref c, ref d, ref e, ref f, ref g);
180 static int test_721_sparc_takeaddr_argument_passing2 () {
181 return pass_takeaddr_floats_doubles (100.0f, 101.0, 102.0, 103.0, 104.0, 105.0f, 106.0);
184 static void pass_byref_double (out double d) {
188 // Test byref double argument passing
189 static int test_0_sparc_byref_double_argument_passing () {
191 pass_byref_double (out d);
192 return (d == 5.0) ? 0 : 1;
195 static void shift_un_arg (ulong value) {
198 } while (value != 0);
201 // Test that assignment to long arguments work
202 static int test_0_long_arg_assign ()
204 ulong c = 0x800000ff00000000;
206 shift_un_arg (c >> 4);
211 static unsafe void* ptr_return (void *ptr)
216 static unsafe int test_0_ptr_return ()
218 void *ptr = new IntPtr (55).ToPointer ();
220 if (ptr_return (ptr) == ptr)
226 static bool isnan (float f) {
230 static int test_0_isnan () {
232 return isnan (f) ? 1 : 0;
237 public FooStruct (long l) {
241 static int test_0_calls_opcode_emulation () {
242 // Test that emulated opcodes do not clobber arguments already in
246 new FooStruct (val * 10000);
251 static int first_is_zero (int v1, int v2) {
256 static int test_1_handle_dup_stloc () {
258 int val = first_is_zero (index, ++index);
264 static long return_5low () {
268 static long return_5high () {
272 public static int test_3_long_ret () {
273 long val = return_5low ();
274 return (int) (val - 2);
277 public static int test_1_long_ret2 () {
278 long val = return_5high ();
279 if (val > 0xffffffff)
284 static void doit (double value, out long m) {
288 public static int test_0_ftol_clobber () {