2 using System.Reflection;
3 using System.Runtime.InteropServices;
6 * Regression tests for the mono JIT.
8 * Each test needs to be of the form:
10 * static int test_<result>_<name> ();
12 * where <result> is an integer (the value that needs to be returned by
13 * the method to make it pass.
14 * <name> is a user-displayed name used to identify the test.
16 * The tests can be driven in two ways:
17 * *) running the program directly: Main() uses reflection to find and invoke
18 * the test methods (this is useful mostly to check that the tests are correct)
19 * *) with the --regression switch of the jit (this is the preferred way since
20 * all the tests will be run with optimizations on and off)
22 * The reflection logic could be moved to a .dll since we need at least another
23 * regression test file written in IL code to have better control on how
41 public Sample (int v) {
46 [StructLayout ( LayoutKind.Explicit )]
47 struct StructWithBigOffsets {
48 [ FieldOffset(10000) ] public byte b;
49 [ FieldOffset(11000) ] public short s;
50 [ FieldOffset(12000) ] public uint i;
51 [ FieldOffset(13000) ] public long l;
52 [ FieldOffset(14000) ] public float f;
53 [ FieldOffset(15000) ] public double d;
65 return TestDriver.RunTests (typeof (Tests));
68 static int test_0_return () {
72 s.c = (short)(s.a + s.b);
77 static int test_0_string_access () {
84 static int test_0_string_virtual_call () {
86 string s2 = s.ToString ();
92 static int test_0_iface_call () {
94 object o = ((ICloneable)s).Clone ();
98 static int test_5_newobj () {
99 Sample s = new Sample (5);
103 static int test_4_box () {
108 static int test_0_enum_unbox () {
109 SampleEnum x = SampleEnum.A;
119 static Simple get_simple (int v) {
120 Simple r = new Simple ();
123 r.c = (short)(v + 2);
129 static int test_3_return_struct () {
130 Simple v = get_simple (1);
143 public virtual Simple v_get_simple (int v)
145 return get_simple (v);
148 static int test_2_return_struct_virtual () {
149 Tests t = new Tests ();
150 Simple v = t.v_get_simple (2);
163 static int receive_simple (int a, Simple v, int b) {
179 static int test_5_pass_struct () {
180 Simple v = get_simple (1);
181 if (receive_simple (7, v, 9) != 0)
183 if (receive_simple (7, get_simple (1), 9) != 0)
188 // Test alignment of small structs
190 static Small get_small (byte v) {
191 Small r = new Small ();
194 r.b2 = (byte)(v + 1);
199 static Small return_small (Small s) {
203 static int receive_small (int a, Small v, int b) {
211 static int test_5_pass_small_struct () {
212 Small v = get_small (1);
213 if (receive_small (7, v, 9) != 0)
215 if (receive_small (7, get_small (1), 9) != 0)
217 v = return_small (v);
228 public AStruct (int i) {
232 public override int GetHashCode () {
237 // Test that vtypes are unboxed during a virtual call
238 static int test_44_unbox_trampoline () {
239 AStruct s = new AStruct (44);
241 return o.GetHashCode ();
244 // Test fields with big offsets
245 static int test_0_fields_with_big_offsets () {
246 StructWithBigOffsets s = new StructWithBigOffsets ();
247 StructWithBigOffsets s2 = new StructWithBigOffsets ();
267 if (s2.i != 0xdeadbeef)
269 if (s2.l != 0xcafebabe)
282 int buf_length, buf_offset;
290 public long Seek (long position) {
292 /* interaction between the register allocator and
293 * allocating arguments to registers */
294 if (pos >= buf_start && pos <= buf_start + buf_length) {
295 buf_offset = (int) (pos - buf_start);
303 static int test_0_seektest () {
304 TestRegA t = new TestRegA ();
305 return (int)t.Seek (0);
308 class Super : ICloneable {
309 public virtual object Clone () {
316 static int test_0_super_cast () {
317 Duper d = new Duper ();
331 d = (Duper)(object)sup;
338 static int test_0_super_cast_array () {
339 Duper[] d = new Duper [0];
350 if (!(d is Object[]))
353 d = (Duper[])(object[])sup;
360 static int test_0_multi_array_cast () {
361 Duper[,] d = new Duper [1, 1];
365 o [0, 0] = new Super ();
368 catch (ArrayTypeMismatchException) {
374 static int test_0_vector_array_cast () {
375 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
376 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
378 if (arr1.GetType () != typeof (int[]))
381 if (arr2.GetType () == typeof (int[]))
392 catch (InvalidCastException) {
401 static int test_0_enum_array_cast () {
402 TypeCode[] tc = new TypeCode [0];
411 if (a is ValueType[])
425 vta = (ValueType[])a;
442 static int test_0_more_cast_corner_cases () {
443 ValueType[] vta = new ValueType [0];
444 Enum[] ea = new Enum [0];
449 if (!(a is object[]))
451 if (!(a is ValueType[]))
456 if (!(a is object[]))
458 if (!(a is ValueType[]))
520 static int test_0_cast_iface_array () {
521 object o = new ICloneable [0];
522 object o2 = new Duper [0];
526 if (!(o is object[]))
528 if (!(o2 is ICloneable[]))
542 t = (ICloneable[])o2;
558 if (!(o is ICloneable[]))
561 /* add tests for interfaces that 'inherit' interfaces */
565 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
567 private static int AbsoluteDays (int year, int month, int day)
570 int[] days = daysmonthleap;
573 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
576 static int test_719162_complex_div () {
577 int adays = AbsoluteDays (1970, 1, 1);
581 delegate int GetIntDel ();
583 static int return4 () {
591 static int test_2_static_delegate () {
592 GetIntDel del = new GetIntDel (return4);
599 static int test_2_instance_delegate () {
600 Tests t = new Tests ();
601 GetIntDel del = new GetIntDel (t.return5);
608 static int test_1_store_decimal () {
609 decimal[,] a = {{1}};
616 static int test_2_intptr_stobj () {
617 System.IntPtr [] arr = { new System.IntPtr () };
619 if (arr [0] != (System.IntPtr)0)
624 static int llmult (int a, int b, int c, int d) {
625 return a + b + c + d;
629 * Test that evaluation of complex arguments does not overwrite the
630 * arguments already in outgoing registers.
632 static int test_155_regalloc () {
638 int[] arr = new int [5];
640 return llmult (arr [c + d], 150, 5, 0);