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 // Test fields with big offsets
245 static int test_1_fields_with_big_offsets () {
246 StructWithBigOffsets s = new StructWithBigOffsets ();
247 StructWithBigOffsets s2 = new StructWithBigOffsets ();
263 if ((s2.b != 0xde) || (s2.s != 0x12de) || (s2.i != 0xdeadbeef) || (s2.l != 0xcafebabe) || (s2.f != 3.14F) || (s2.d != 3.14))
272 int buf_length, buf_offset;
280 public long Seek (long position) {
282 /* interaction between the register allocator and
283 * allocating arguments to registers */
284 if (pos >= buf_start && pos <= buf_start + buf_length) {
285 buf_offset = (int) (pos - buf_start);
293 static int test_0_seektest () {
294 TestRegA t = new TestRegA ();
295 return (int)t.Seek (0);
298 class Super : ICloneable {
299 public virtual object Clone () {
306 static int test_0_super_cast () {
307 Duper d = new Duper ();
321 d = (Duper)(object)sup;
328 static int test_0_super_cast_array () {
329 Duper[] d = new Duper [0];
340 if (!(d is Object[]))
343 d = (Duper[])(object[])sup;
350 static int test_0_multi_array_cast () {
351 Duper[,] d = new Duper [1, 1];
355 o [0, 0] = new Super ();
358 catch (ArrayTypeMismatchException) {
364 static int test_0_vector_array_cast () {
365 Array arr1 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {0});
366 Array arr2 = Array.CreateInstance (typeof (int), new int[] {1}, new int[] {10});
368 if (arr1.GetType () != typeof (int[]))
371 if (arr2.GetType () == typeof (int[]))
382 catch (InvalidCastException) {
391 static int test_0_enum_array_cast () {
392 TypeCode[] tc = new TypeCode [0];
401 if (a is ValueType[])
415 vta = (ValueType[])a;
432 static int test_0_more_cast_corner_cases () {
433 ValueType[] vta = new ValueType [0];
434 Enum[] ea = new Enum [0];
439 if (!(a is object[]))
441 if (!(a is ValueType[]))
446 if (!(a is object[]))
448 if (!(a is ValueType[]))
510 static int test_0_cast_iface_array () {
511 object o = new ICloneable [0];
512 object o2 = new Duper [0];
516 if (!(o is object[]))
518 if (!(o2 is ICloneable[]))
532 t = (ICloneable[])o2;
548 if (!(o is ICloneable[]))
551 /* add tests for interfaces that 'inherit' interfaces */
555 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
557 private static int AbsoluteDays (int year, int month, int day)
560 int[] days = daysmonthleap;
563 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
566 static int test_719162_complex_div () {
567 int adays = AbsoluteDays (1970, 1, 1);
571 delegate int GetIntDel ();
573 static int return4 () {
581 static int test_2_static_delegate () {
582 GetIntDel del = new GetIntDel (return4);
589 static int test_2_instance_delegate () {
590 Tests t = new Tests ();
591 GetIntDel del = new GetIntDel (t.return5);
598 static int test_1_store_decimal () {
599 decimal[,] a = {{1}};
606 static int test_2_intptr_stobj () {
607 System.IntPtr [] arr = { new System.IntPtr () };
609 if (arr [0] != (System.IntPtr)0)