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
51 public void populate ()
61 return one == 1 && two == 2 &&
62 three == 3 && four == 4 &&
63 five == 5 && six == 6 &&
64 seven == 7 && eight == 8 &&
65 nine == 9 && ten == 10;
71 public Sample (int v) {
76 [StructLayout ( LayoutKind.Explicit )]
77 struct StructWithBigOffsets {
78 [ FieldOffset(10000) ] public byte b;
79 [ FieldOffset(11000) ] public short s;
80 [ FieldOffset(12000) ] public uint i;
81 [ FieldOffset(13000) ] public long l;
82 [ FieldOffset(14000) ] public float f;
83 [ FieldOffset(15000) ] public double d;
95 return TestDriver.RunTests (typeof (Tests));
98 static int test_0_return () {
102 s.c = (short)(s.a + s.b);
107 static int test_0_string_access () {
114 static int test_0_string_virtual_call () {
116 string s2 = s.ToString ();
122 static int test_0_iface_call () {
124 object o = ((ICloneable)s).Clone ();
128 static int test_5_newobj () {
129 Sample s = new Sample (5);
133 static int test_4_box () {
138 static int test_0_enum_unbox () {
139 SampleEnum x = SampleEnum.A;
149 static Simple get_simple (int v) {
150 Simple r = new Simple ();
153 r.c = (short)(v + 2);
159 static int test_3_return_struct () {
160 Simple v = get_simple (1);
173 public virtual Simple v_get_simple (int v)
175 return get_simple (v);
178 static int test_2_return_struct_virtual () {
179 Tests t = new Tests ();
180 Simple v = t.v_get_simple (2);
193 static int receive_simple (int a, Simple v, int b) {
209 static int test_5_pass_struct () {
210 Simple v = get_simple (1);
211 if (receive_simple (7, v, 9) != 0)
213 if (receive_simple (7, get_simple (1), 9) != 0)
218 // Test alignment of small structs
220 static Small get_small (byte v) {
221 Small r = new Small ();
224 r.b2 = (byte)(v + 1);
229 static Small return_small (Small s) {
233 static int receive_small (int a, Small v, int b) {
241 static int test_5_pass_small_struct () {
242 Small v = get_small (1);
243 if (receive_small (7, v, 9) != 0)
245 if (receive_small (7, get_small (1), 9) != 0)
247 v = return_small (v);
258 public AStruct (int i) {
262 public override int GetHashCode () {
267 // Test that vtypes are unboxed during a virtual call
268 static int test_44_unbox_trampoline () {
269 AStruct s = new AStruct (44);
271 return o.GetHashCode ();
274 static int test_0_unbox_trampoline2 () {
278 if (i.ToString () != "12")
280 if (((Int32)o).ToString () != "12")
282 if (o.ToString () != "12")
287 // Test fields with big offsets
288 static int test_0_fields_with_big_offsets () {
289 StructWithBigOffsets s = new StructWithBigOffsets ();
290 StructWithBigOffsets s2 = new StructWithBigOffsets ();
310 if (s2.i != 0xdeadbeef)
312 if (s2.l != 0xcafebabe)
325 int buf_length, buf_offset;
333 public long Seek (long position) {
335 /* interaction between the register allocator and
336 * allocating arguments to registers */
337 if (pos >= buf_start && pos <= buf_start + buf_length) {
338 buf_offset = (int) (pos - buf_start);
346 static int test_0_seektest () {
347 TestRegA t = new TestRegA ();
348 return (int)t.Seek (0);
351 class Super : ICloneable {
352 public virtual object Clone () {
359 static int test_0_null_cast () {
367 static int test_0_super_cast () {
368 Duper d = new Duper ();
382 d = (Duper)(object)sup;
389 static int test_0_super_cast_array () {
390 Duper[] d = new Duper [0];
401 if (!(d is Object[]))
404 d = (Duper[])(object[])sup;
411 static int test_0_multi_array_cast () {
412 Duper[,] d = new Duper [1, 1];
416 o [0, 0] = new Super ();
419 catch (ArrayTypeMismatchException) {
425 static int test_0_vector_array_cast () {
426 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
427 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
429 if (arr1.GetType () != typeof (int[]))
432 if (arr2.GetType () == typeof (int[]))
443 catch (InvalidCastException) {
452 static int test_0_enum_array_cast () {
453 TypeCode[] tc = new TypeCode [0];
462 if (a is ValueType[])
476 vta = (ValueType[])a;
493 static int test_0_more_cast_corner_cases () {
494 ValueType[] vta = new ValueType [0];
495 Enum[] ea = new Enum [0];
500 if (!(a is object[]))
502 if (!(a is ValueType[]))
507 if (!(a is object[]))
509 if (!(a is ValueType[]))
571 static int test_0_cast_iface_array () {
572 object o = new ICloneable [0];
573 object o2 = new Duper [0];
577 if (!(o is object[]))
579 if (!(o2 is ICloneable[]))
593 t = (ICloneable[])o2;
609 if (!(o is ICloneable[]))
612 /* add tests for interfaces that 'inherit' interfaces */
616 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
618 private static int AbsoluteDays (int year, int month, int day)
621 int[] days = daysmonthleap;
624 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
627 static int test_719162_complex_div () {
628 int adays = AbsoluteDays (1970, 1, 1);
632 delegate int GetIntDel ();
634 static int return4 () {
642 static int test_2_static_delegate () {
643 GetIntDel del = new GetIntDel (return4);
650 static int test_2_instance_delegate () {
651 Tests t = new Tests ();
652 GetIntDel del = new GetIntDel (t.return5);
659 static int test_1_store_decimal () {
660 decimal[,] a = {{1}};
667 static int test_2_intptr_stobj () {
668 System.IntPtr [] arr = { new System.IntPtr () };
670 if (arr [0] != (System.IntPtr)0)
675 static int llmult (int a, int b, int c, int d) {
676 return a + b + c + d;
680 * Test that evaluation of complex arguments does not overwrite the
681 * arguments already in outgoing registers.
683 static int test_155_regalloc () {
689 int[] arr = new int [5];
691 return llmult (arr [c + d], 150, 5, 0);
694 static bool large_struct_test (Large a, Large b, Large c, Large d)
696 if (!a.check ()) return false;
697 if (!b.check ()) return false;
698 if (!c.check ()) return false;
699 if (!d.check ()) return false;
703 static int test_2_large_struct_pass ()
714 if (large_struct_test (a, b, c, d))
719 public static unsafe int test_0_pin_string () {
721 fixed (char *c = x) {