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 // The first argument must be passed on a dword aligned stack location
150 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) {
151 return (int)(a + b + c + d + e + f + g);
154 static int pass_takeaddr_ints_longs (long a, int b, byte c, short d, long e, int f, long g) {
155 return pass_byref_ints_longs (ref a, ref b, ref c, ref d, ref e, ref f, ref g);
158 // Test that arguments are moved to the stack from incoming registers
159 // when the argument must reside in the stack because its address is taken
160 static int test_2_sparc_takeaddr_argument_passing () {
161 return pass_takeaddr_ints_longs (1, 2, 253, -253, System.Int64.MaxValue, 0, System.Int64.MinValue);
164 static void pass_byref_double (out double d) {
168 // Test byref double argument passing
169 static int test_0_sparc_byref_double_argument_passing () {
171 pass_byref_double (out d);
172 return (d == 5.0) ? 0 : 1;
175 static void shift_un_arg (ulong value) {
178 } while (value != 0);
181 // Test that assignment to long arguments work
182 static int test_0_long_arg_assign ()
184 ulong c = 0x800000ff00000000;
186 shift_un_arg (c >> 4);
191 static unsafe void* ptr_return (void *ptr)
196 static unsafe int test_0_ptr_return ()
198 void *ptr = new IntPtr (55).ToPointer ();
200 if (ptr_return (ptr) == ptr)
206 static bool isnan (float f) {
210 static int test_0_isnan () {
212 return isnan (f) ? 1 : 0;
217 public FooStruct (long l) {
221 static int test_0_calls_opcode_emulation () {
222 // Test that emulated opcodes do not clobber arguments already in
226 new FooStruct (val * 10000);