2 using System.Reflection;
3 using System.Runtime.InteropServices;
4 using System.Runtime.CompilerServices;
7 * Regression tests for the mono JIT.
9 * Each test needs to be of the form:
11 * static int test_<result>_<name> ();
13 * where <result> is an integer (the value that needs to be returned by
14 * the method to make it pass.
15 * <name> is a user-displayed name used to identify the test.
17 * The tests can be driven in two ways:
18 * *) running the program directly: Main() uses reflection to find and invoke
19 * the test methods (this is useful mostly to check that the tests are correct)
20 * *) with the --regression switch of the jit (this is the preferred way since
21 * all the tests will be run with optimizations on and off)
23 * The reflection logic could be moved to a .dll since we need at least another
24 * regression test file written in IL code to have better control on how
52 public void populate ()
62 return one == 1 && two == 2 &&
63 three == 3 && four == 4 &&
64 five == 5 && six == 6 &&
65 seven == 7 && eight == 8 &&
66 nine == 9 && ten == 10;
72 public Sample (int v) {
77 [StructLayout ( LayoutKind.Explicit )]
78 struct StructWithBigOffsets {
79 [ FieldOffset(10000) ] public byte b;
80 [ FieldOffset(10001) ] public sbyte sb;
81 [ FieldOffset(11000) ] public short s;
82 [ FieldOffset(11002) ] public ushort us;
83 [ FieldOffset(12000) ] public uint i;
84 [ FieldOffset(12004) ] public int si;
85 [ FieldOffset(13000) ] public long l;
86 [ FieldOffset(14000) ] public float f;
87 [ FieldOffset(15000) ] public double d;
99 return TestDriver.RunTests (typeof (Tests));
102 static int test_0_return () {
106 s.c = (short)(s.a + s.b);
111 static int test_0_string_access () {
118 static int test_0_string_virtual_call () {
120 string s2 = s.ToString ();
126 static int test_0_iface_call () {
128 object o = ((ICloneable)s).Clone ();
132 static int test_5_newobj () {
133 Sample s = new Sample (5);
137 static int test_4_box () {
142 static int test_0_enum_unbox () {
143 SampleEnum x = SampleEnum.A;
153 static Simple get_simple (int v) {
154 Simple r = new Simple ();
157 r.c = (short)(v + 2);
163 static int test_3_return_struct () {
164 Simple v = get_simple (1);
177 public virtual Simple v_get_simple (int v)
179 return get_simple (v);
182 static int test_2_return_struct_virtual () {
183 Tests t = new Tests ();
184 Simple v = t.v_get_simple (2);
197 static int receive_simple (int a, Simple v, int b) {
213 static int test_5_pass_struct () {
214 Simple v = get_simple (1);
215 if (receive_simple (7, v, 9) != 0)
217 if (receive_simple (7, get_simple (1), 9) != 0)
222 // Test alignment of small structs
224 static Small get_small (byte v) {
225 Small r = new Small ();
228 r.b2 = (byte)(v + 1);
233 static Small return_small (Small s) {
237 static int receive_small (int a, Small v, int b) {
245 static int test_5_pass_small_struct () {
246 Small v = get_small (1);
247 if (receive_small (7, v, 9) != 0)
249 if (receive_small (7, get_small (1), 9) != 0)
251 v = return_small (v);
262 public AStruct (int i) {
266 public override int GetHashCode () {
271 // Test that vtypes are unboxed during a virtual call
272 static int test_44_unbox_trampoline () {
273 AStruct s = new AStruct (44);
275 return o.GetHashCode ();
278 static int test_0_unbox_trampoline2 () {
282 if (i.ToString () != "12")
284 if (((Int32)o).ToString () != "12")
286 if (o.ToString () != "12")
291 // Test fields with big offsets
292 static int test_0_fields_with_big_offsets () {
293 StructWithBigOffsets s = new StructWithBigOffsets ();
294 StructWithBigOffsets s2 = new StructWithBigOffsets ();
320 if (s2.i != 0xdeadbeef)
322 if (s2.l != 0xcafebabe)
341 int buf_length, buf_offset;
349 public long Seek (long position) {
351 /* interaction between the register allocator and
352 * allocating arguments to registers */
353 if (pos >= buf_start && pos <= buf_start + buf_length) {
354 buf_offset = (int) (pos - buf_start);
362 static int test_0_seektest () {
363 TestRegA t = new TestRegA ();
364 return (int)t.Seek (0);
367 class Super : ICloneable {
368 public virtual object Clone () {
375 static int test_0_null_cast () {
383 static int test_0_super_cast () {
384 Duper d = new Duper ();
398 d = (Duper)(object)sup;
405 static int test_0_super_cast_array () {
406 Duper[] d = new Duper [0];
417 if (!(d is Object[]))
420 d = (Duper[])(object[])sup;
427 static int test_0_multi_array_cast () {
428 Duper[,] d = new Duper [1, 1];
432 o [0, 0] = new Super ();
435 catch (ArrayTypeMismatchException) {
441 static int test_0_vector_array_cast () {
442 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
443 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
445 if (arr1.GetType () != typeof (int[]))
448 if (arr2.GetType () == typeof (int[]))
459 catch (InvalidCastException) {
468 static int test_0_enum_array_cast () {
469 TypeCode[] tc = new TypeCode [0];
478 if (a is ValueType[])
492 vta = (ValueType[])a;
509 static int test_0_more_cast_corner_cases () {
510 ValueType[] vta = new ValueType [0];
511 Enum[] ea = new Enum [0];
516 if (!(a is object[]))
518 if (!(a is ValueType[]))
523 if (!(a is object[]))
525 if (!(a is ValueType[]))
587 static int test_0_cast_iface_array () {
588 object o = new ICloneable [0];
589 object o2 = new Duper [0];
593 if (!(o is object[]))
595 if (!(o2 is ICloneable[]))
609 t = (ICloneable[])o2;
625 if (!(o is ICloneable[]))
628 /* add tests for interfaces that 'inherit' interfaces */
632 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
634 private static int AbsoluteDays (int year, int month, int day)
637 int[] days = daysmonthleap;
640 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
643 static int test_719162_complex_div () {
644 int adays = AbsoluteDays (1970, 1, 1);
648 delegate int GetIntDel ();
650 static int return4 () {
658 static int test_2_static_delegate () {
659 GetIntDel del = new GetIntDel (return4);
666 static int test_2_instance_delegate () {
667 Tests t = new Tests ();
668 GetIntDel del = new GetIntDel (t.return5);
675 static int test_1_store_decimal () {
676 decimal[,] a = {{1}};
683 static int test_2_intptr_stobj () {
684 System.IntPtr [] arr = { new System.IntPtr () };
686 if (arr [0] != (System.IntPtr)0)
691 static int llmult (int a, int b, int c, int d) {
692 return a + b + c + d;
696 * Test that evaluation of complex arguments does not overwrite the
697 * arguments already in outgoing registers.
699 static int test_155_regalloc () {
705 int[] arr = new int [5];
707 return llmult (arr [c + d], 150, 5, 0);
710 static bool large_struct_test (Large a, Large b, Large c, Large d)
712 if (!a.check ()) return false;
713 if (!b.check ()) return false;
714 if (!c.check ()) return false;
715 if (!d.check ()) return false;
719 static int test_2_large_struct_pass ()
730 if (large_struct_test (a, b, c, d))
735 public static unsafe int test_0_pin_string () {
737 fixed (char *c = x) {
744 public static int my_flags;
745 public static int test_0_and_cmp_static ()
748 /* various forms of test [mem], imm */
750 my_flags = 0x01020304;
752 if ((my_flags & 0x01020304) == 0)
755 if ((my_flags & 0x00000304) == 0)
758 if ((my_flags & 0x00000004) == 0)
761 if ((my_flags & 0x00000300) == 0)
764 if ((my_flags & 0x00020000) == 0)
767 if ((my_flags & 0x01000000) == 0)
774 public static int test_0_byte_compares ()
780 if (!(b < System.Byte.MaxValue))
783 if (!(b <= System.Byte.MaxValue))
789 public static int test_71_long_shift_right () {
790 ulong value = 38654838087;
792 byte [] buffer = new byte [1];
793 buffer [x] = ((byte)(value >> x));
798 public static int test_0_addsub_mem ()
815 public static int test_0_sh32_mem ()
817 y = 0x0102130405060708;
823 y = 0x0102130405060708;
826 if (y != 0x0506070800000000)
829 x = 0x0102130405060708;
832 if (x != 0x0506070800000000)
839 static uint dum_de_dum = 1;
840 static int test_0_long_arg_opt ()
842 return Foo (0x1234567887654321, dum_de_dum);
845 static int Foo (ulong x, ulong y)
847 if (x != 0x1234567887654321)
856 static int test_0_long_ret_opt ()
859 if (x != 0x1234567887654321)
870 return 0x1234567887654321;
878 /* from bug# 71515 */
879 static int counter = 0;
880 static bool WriteStuff () {
884 static int test_0_cond_branch_side_effects () {
893 public static int arg_only_written (string file_name, int[]
895 if (file_name == null)
904 public static int[] foo () {
908 public static void bar (int i) {
912 public static int test_0_arg_only_written ()
914 return arg_only_written ("md.in", null);
917 static long position = 0;
919 public static int test_4_static_inc_long () {
927 return (int)position;
932 public FooStruct (long l) {
936 static int test_0_calls_opcode_emulation () {
937 // Test that emulated opcodes do not clobber arguments already in
941 new FooStruct (val * 10000);
946 static int test_0_intrins_string_length () {
949 return (s.Length == 3) ? 0 : 1;
952 static int test_0_intrins_string_chars () {
955 return (s [0] == 'A' && s [1] == 'B' && s [2] == 'C') ? 0 : 1;
958 static int test_0_intrins_object_gettype () {
961 return (o.GetType () == typeof (int)) ? 0 : 1;
964 static int test_0_intrins_object_gethashcode () {
965 object o = new Object ();
967 return (o.GetHashCode () == o.GetHashCode ()) ? 0 : 1;
973 static int test_0_intrins_object_ctor () {
974 object o = new FooClass ();
976 return (o != null) ? 0 : 1;
979 static int test_0_intrins_array_rank () {
980 int[,] a = new int [10, 10];
982 return (a.Rank == 2) ? 0 : 1;
985 static int test_0_intrins_array_length () {
986 int[,] a = new int [10, 10];
989 return (a2.Length == 100) ? 0 : 1;
992 static int test_0_intrins_runtimehelpers_offset_to_string_data () {
993 int i = RuntimeHelpers.OffsetToStringData;