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_super_cast () {
360 Duper d = new Duper ();
374 d = (Duper)(object)sup;
381 static int test_0_super_cast_array () {
382 Duper[] d = new Duper [0];
393 if (!(d is Object[]))
396 d = (Duper[])(object[])sup;
403 static int test_0_multi_array_cast () {
404 Duper[,] d = new Duper [1, 1];
408 o [0, 0] = new Super ();
411 catch (ArrayTypeMismatchException) {
417 static int test_0_vector_array_cast () {
418 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
419 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
421 if (arr1.GetType () != typeof (int[]))
424 if (arr2.GetType () == typeof (int[]))
435 catch (InvalidCastException) {
444 static int test_0_enum_array_cast () {
445 TypeCode[] tc = new TypeCode [0];
454 if (a is ValueType[])
468 vta = (ValueType[])a;
485 static int test_0_more_cast_corner_cases () {
486 ValueType[] vta = new ValueType [0];
487 Enum[] ea = new Enum [0];
492 if (!(a is object[]))
494 if (!(a is ValueType[]))
499 if (!(a is object[]))
501 if (!(a is ValueType[]))
563 static int test_0_cast_iface_array () {
564 object o = new ICloneable [0];
565 object o2 = new Duper [0];
569 if (!(o is object[]))
571 if (!(o2 is ICloneable[]))
585 t = (ICloneable[])o2;
601 if (!(o is ICloneable[]))
604 /* add tests for interfaces that 'inherit' interfaces */
608 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
610 private static int AbsoluteDays (int year, int month, int day)
613 int[] days = daysmonthleap;
616 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
619 static int test_719162_complex_div () {
620 int adays = AbsoluteDays (1970, 1, 1);
624 delegate int GetIntDel ();
626 static int return4 () {
634 static int test_2_static_delegate () {
635 GetIntDel del = new GetIntDel (return4);
642 static int test_2_instance_delegate () {
643 Tests t = new Tests ();
644 GetIntDel del = new GetIntDel (t.return5);
651 static int test_1_store_decimal () {
652 decimal[,] a = {{1}};
659 static int test_2_intptr_stobj () {
660 System.IntPtr [] arr = { new System.IntPtr () };
662 if (arr [0] != (System.IntPtr)0)
667 static int llmult (int a, int b, int c, int d) {
668 return a + b + c + d;
672 * Test that evaluation of complex arguments does not overwrite the
673 * arguments already in outgoing registers.
675 static int test_155_regalloc () {
681 int[] arr = new int [5];
683 return llmult (arr [c + d], 150, 5, 0);
686 static bool large_struct_test (Large a, Large b, Large c, Large d)
688 if (!a.check ()) return false;
689 if (!b.check ()) return false;
690 if (!c.check ()) return false;
691 if (!d.check ()) return false;
695 static int test_2_large_struct_pass ()
706 if (large_struct_test (a, b, c, d))