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 static int test_0_unbox_trampoline2 () {
248 if (i.ToString () != "12")
250 if (((Int32)o).ToString () != "12")
252 if (o.ToString () != "12")
257 // Test fields with big offsets
258 static int test_0_fields_with_big_offsets () {
259 StructWithBigOffsets s = new StructWithBigOffsets ();
260 StructWithBigOffsets s2 = new StructWithBigOffsets ();
280 if (s2.i != 0xdeadbeef)
282 if (s2.l != 0xcafebabe)
295 int buf_length, buf_offset;
303 public long Seek (long position) {
305 /* interaction between the register allocator and
306 * allocating arguments to registers */
307 if (pos >= buf_start && pos <= buf_start + buf_length) {
308 buf_offset = (int) (pos - buf_start);
316 static int test_0_seektest () {
317 TestRegA t = new TestRegA ();
318 return (int)t.Seek (0);
321 class Super : ICloneable {
322 public virtual object Clone () {
329 static int test_0_super_cast () {
330 Duper d = new Duper ();
344 d = (Duper)(object)sup;
351 static int test_0_super_cast_array () {
352 Duper[] d = new Duper [0];
363 if (!(d is Object[]))
366 d = (Duper[])(object[])sup;
373 static int test_0_multi_array_cast () {
374 Duper[,] d = new Duper [1, 1];
378 o [0, 0] = new Super ();
381 catch (ArrayTypeMismatchException) {
387 static int test_0_vector_array_cast () {
388 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
389 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
391 if (arr1.GetType () != typeof (int[]))
394 if (arr2.GetType () == typeof (int[]))
405 catch (InvalidCastException) {
414 static int test_0_enum_array_cast () {
415 TypeCode[] tc = new TypeCode [0];
424 if (a is ValueType[])
438 vta = (ValueType[])a;
455 static int test_0_more_cast_corner_cases () {
456 ValueType[] vta = new ValueType [0];
457 Enum[] ea = new Enum [0];
462 if (!(a is object[]))
464 if (!(a is ValueType[]))
469 if (!(a is object[]))
471 if (!(a is ValueType[]))
533 static int test_0_cast_iface_array () {
534 object o = new ICloneable [0];
535 object o2 = new Duper [0];
539 if (!(o is object[]))
541 if (!(o2 is ICloneable[]))
555 t = (ICloneable[])o2;
571 if (!(o is ICloneable[]))
574 /* add tests for interfaces that 'inherit' interfaces */
578 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
580 private static int AbsoluteDays (int year, int month, int day)
583 int[] days = daysmonthleap;
586 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
589 static int test_719162_complex_div () {
590 int adays = AbsoluteDays (1970, 1, 1);
594 delegate int GetIntDel ();
596 static int return4 () {
604 static int test_2_static_delegate () {
605 GetIntDel del = new GetIntDel (return4);
612 static int test_2_instance_delegate () {
613 Tests t = new Tests ();
614 GetIntDel del = new GetIntDel (t.return5);
621 static int test_1_store_decimal () {
622 decimal[,] a = {{1}};
629 static int test_2_intptr_stobj () {
630 System.IntPtr [] arr = { new System.IntPtr () };
632 if (arr [0] != (System.IntPtr)0)
637 static int llmult (int a, int b, int c, int d) {
638 return a + b + c + d;
642 * Test that evaluation of complex arguments does not overwrite the
643 * arguments already in outgoing registers.
645 static int test_155_regalloc () {
651 int[] arr = new int [5];
653 return llmult (arr [c + d], 150, 5, 0);