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(10001) ] public sbyte sb;
80 [ FieldOffset(11000) ] public short s;
81 [ FieldOffset(11002) ] public ushort us;
82 [ FieldOffset(12000) ] public uint i;
83 [ FieldOffset(12004) ] public int si;
84 [ FieldOffset(13000) ] public long l;
85 [ FieldOffset(14000) ] public float f;
86 [ FieldOffset(15000) ] public double d;
98 return TestDriver.RunTests (typeof (Tests));
101 static int test_0_return () {
105 s.c = (short)(s.a + s.b);
110 static int test_0_string_access () {
117 static int test_0_string_virtual_call () {
119 string s2 = s.ToString ();
125 static int test_0_iface_call () {
127 object o = ((ICloneable)s).Clone ();
131 static int test_5_newobj () {
132 Sample s = new Sample (5);
136 static int test_4_box () {
141 static int test_0_enum_unbox () {
142 SampleEnum x = SampleEnum.A;
152 static Simple get_simple (int v) {
153 Simple r = new Simple ();
156 r.c = (short)(v + 2);
162 static int test_3_return_struct () {
163 Simple v = get_simple (1);
176 public virtual Simple v_get_simple (int v)
178 return get_simple (v);
181 static int test_2_return_struct_virtual () {
182 Tests t = new Tests ();
183 Simple v = t.v_get_simple (2);
196 static int receive_simple (int a, Simple v, int b) {
212 static int test_5_pass_struct () {
213 Simple v = get_simple (1);
214 if (receive_simple (7, v, 9) != 0)
216 if (receive_simple (7, get_simple (1), 9) != 0)
221 // Test alignment of small structs
223 static Small get_small (byte v) {
224 Small r = new Small ();
227 r.b2 = (byte)(v + 1);
232 static Small return_small (Small s) {
236 static int receive_small (int a, Small v, int b) {
244 static int test_5_pass_small_struct () {
245 Small v = get_small (1);
246 if (receive_small (7, v, 9) != 0)
248 if (receive_small (7, get_small (1), 9) != 0)
250 v = return_small (v);
261 public AStruct (int i) {
265 public override int GetHashCode () {
270 // Test that vtypes are unboxed during a virtual call
271 static int test_44_unbox_trampoline () {
272 AStruct s = new AStruct (44);
274 return o.GetHashCode ();
277 static int test_0_unbox_trampoline2 () {
281 if (i.ToString () != "12")
283 if (((Int32)o).ToString () != "12")
285 if (o.ToString () != "12")
290 // Test fields with big offsets
291 static int test_0_fields_with_big_offsets () {
292 StructWithBigOffsets s = new StructWithBigOffsets ();
293 StructWithBigOffsets s2 = new StructWithBigOffsets ();
319 if (s2.i != 0xdeadbeef)
321 if (s2.l != 0xcafebabe)
340 int buf_length, buf_offset;
348 public long Seek (long position) {
350 /* interaction between the register allocator and
351 * allocating arguments to registers */
352 if (pos >= buf_start && pos <= buf_start + buf_length) {
353 buf_offset = (int) (pos - buf_start);
361 static int test_0_seektest () {
362 TestRegA t = new TestRegA ();
363 return (int)t.Seek (0);
366 class Super : ICloneable {
367 public virtual object Clone () {
374 static int test_0_null_cast () {
382 static int test_0_super_cast () {
383 Duper d = new Duper ();
397 d = (Duper)(object)sup;
404 static int test_0_super_cast_array () {
405 Duper[] d = new Duper [0];
416 if (!(d is Object[]))
419 d = (Duper[])(object[])sup;
426 static int test_0_multi_array_cast () {
427 Duper[,] d = new Duper [1, 1];
431 o [0, 0] = new Super ();
434 catch (ArrayTypeMismatchException) {
440 static int test_0_vector_array_cast () {
441 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
442 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
444 if (arr1.GetType () != typeof (int[]))
447 if (arr2.GetType () == typeof (int[]))
458 catch (InvalidCastException) {
467 static int test_0_enum_array_cast () {
468 TypeCode[] tc = new TypeCode [0];
477 if (a is ValueType[])
491 vta = (ValueType[])a;
508 static int test_0_more_cast_corner_cases () {
509 ValueType[] vta = new ValueType [0];
510 Enum[] ea = new Enum [0];
515 if (!(a is object[]))
517 if (!(a is ValueType[]))
522 if (!(a is object[]))
524 if (!(a is ValueType[]))
586 static int test_0_cast_iface_array () {
587 object o = new ICloneable [0];
588 object o2 = new Duper [0];
592 if (!(o is object[]))
594 if (!(o2 is ICloneable[]))
608 t = (ICloneable[])o2;
624 if (!(o is ICloneable[]))
627 /* add tests for interfaces that 'inherit' interfaces */
631 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
633 private static int AbsoluteDays (int year, int month, int day)
636 int[] days = daysmonthleap;
639 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
642 static int test_719162_complex_div () {
643 int adays = AbsoluteDays (1970, 1, 1);
647 delegate int GetIntDel ();
649 static int return4 () {
657 static int test_2_static_delegate () {
658 GetIntDel del = new GetIntDel (return4);
665 static int test_2_instance_delegate () {
666 Tests t = new Tests ();
667 GetIntDel del = new GetIntDel (t.return5);
674 static int test_1_store_decimal () {
675 decimal[,] a = {{1}};
682 static int test_2_intptr_stobj () {
683 System.IntPtr [] arr = { new System.IntPtr () };
685 if (arr [0] != (System.IntPtr)0)
690 static int llmult (int a, int b, int c, int d) {
691 return a + b + c + d;
695 * Test that evaluation of complex arguments does not overwrite the
696 * arguments already in outgoing registers.
698 static int test_155_regalloc () {
704 int[] arr = new int [5];
706 return llmult (arr [c + d], 150, 5, 0);
709 static bool large_struct_test (Large a, Large b, Large c, Large d)
711 if (!a.check ()) return false;
712 if (!b.check ()) return false;
713 if (!c.check ()) return false;
714 if (!d.check ()) return false;
718 static int test_2_large_struct_pass ()
729 if (large_struct_test (a, b, c, d))
734 public static unsafe int test_0_pin_string () {
736 fixed (char *c = x) {
743 public static int my_flags;
744 public static int test_0_and_cmp_static ()
747 /* various forms of test [mem], imm */
749 my_flags = 0x01020304;
751 if ((my_flags & 0x01020304) == 0)
754 if ((my_flags & 0x00000304) == 0)
757 if ((my_flags & 0x00000004) == 0)
760 if ((my_flags & 0x00000300) == 0)
763 if ((my_flags & 0x00020000) == 0)
766 if ((my_flags & 0x01000000) == 0)
773 public static int test_0_byte_compares ()
779 if (!(b < System.Byte.MaxValue))
782 if (!(b <= System.Byte.MaxValue))
788 public static int test_71_long_shift_right () {
789 ulong value = 38654838087;
791 byte [] buffer = new byte [1];
792 buffer [x] = ((byte)(value >> x));
797 public static int test_0_addsub_mem ()
814 public static int test_0_sh32_mem ()
816 y = 0x0102130405060708;
822 y = 0x0102130405060708;
825 if (y != 0x0506070800000000)
828 x = 0x0102130405060708;
831 if (x != 0x0506070800000000)
838 static uint dum_de_dum = 1;
839 static int test_0_long_arg_opt ()
841 return Foo (0x1234567887654321, dum_de_dum);
844 static int Foo (ulong x, ulong y)
846 if (x != 0x1234567887654321)
855 static int test_0_long_ret_opt ()
858 if (x != 0x1234567887654321)
869 return 0x1234567887654321;
877 /* from bug# 71515 */
878 static int counter = 0;
879 static bool WriteStuff () {
883 static int test_0_cond_branch_side_effects () {
892 public static int arg_only_written (string file_name, int[]
894 if (file_name == null)
903 public static int[] foo () {
907 public static void bar (int i) {
911 public static int test_0_arg_only_written ()
913 return arg_only_written ("md.in", null);