2 using System.Reflection;
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * static int test_<result>_<name> ();
11 * where <result> is an integer (the value that needs to be returned by
12 * the method to make it pass.
13 * <name> is a user-displayed name used to identify the test.
15 * The tests can be driven in two ways:
16 * *) running the program directly: Main() uses reflection to find and invoke
17 * the test methods (this is useful mostly to check that the tests are correct)
18 * *) with the --regression switch of the jit (this is the preferred way since
19 * all the tests will be run with optimizations on and off)
21 * The reflection logic could be moved to a .dll since we need at least another
22 * regression test file written in IL code to have better control on how
35 public Sample (int v) {
49 return TestDriver.RunTests (typeof (Tests));
52 static int test_0_return () {
56 s.c = (short)(s.a + s.b);
61 static int test_0_string_access () {
68 static int test_0_string_virtual_call () {
70 string s2 = s.ToString ();
76 static int test_0_iface_call () {
78 object o = ((ICloneable)s).Clone ();
82 static int test_5_newobj () {
83 Sample s = new Sample (5);
87 static int test_4_box () {
92 static int test_0_enum_unbox () {
93 SampleEnum x = SampleEnum.A;
103 static Simple get_simple (int v) {
104 Simple r = new Simple ();
107 r.c = (short)(v + 2);
113 static int test_3_return_struct () {
114 Simple v = get_simple (1);
127 public virtual Simple v_get_simple (int v)
129 return get_simple (v);
132 static int test_2_return_struct_virtual () {
133 Tests t = new Tests ();
134 Simple v = t.v_get_simple (2);
147 static int receive_simple (int a, Simple v, int b) {
163 static int test_5_pass_struct () {
164 Simple v = get_simple (1);
165 if (receive_simple (7, v, 9) != 1)
167 if (receive_simple (7, get_simple (1), 9) != 1)
175 int buf_length, buf_offset;
177 public long Seek (long position) {
179 /* interaction between the register allocator and
180 * allocating arguments to registers */
181 if (pos >= buf_start && pos <= buf_start + buf_length) {
182 buf_offset = (int) (pos - buf_start);
190 static int test_0_seektest () {
191 TestRegA t = new TestRegA ();
192 return (int)t.Seek (0);
195 class Super : ICloneable {
196 public virtual object Clone () {
203 static int test_0_super_cast () {
204 Duper d = new Duper ();
218 d = (Duper)(object)sup;
225 static int test_0_super_cast_array () {
226 Duper[] d = new Duper [0];
237 if (!(d is Object[]))
240 d = (Duper[])(object[])sup;
247 static int test_0_enum_array_cast () {
248 TypeCode[] tc = new TypeCode [0];
257 if (a is ValueType[])
271 vta = (ValueType[])a;
288 static int test_0_more_cast_corner_cases () {
289 ValueType[] vta = new ValueType [0];
290 Enum[] ea = new Enum [0];
295 if (!(a is object[]))
297 if (!(a is ValueType[]))
302 if (!(a is object[]))
304 if (!(a is ValueType[]))
366 static int test_0_cast_iface_array () {
367 object o = new ICloneable [0];
368 object o2 = new Duper [0];
372 if (!(o is object[]))
374 if (!(o2 is ICloneable[]))
388 t = (ICloneable[])o2;
404 if (!(o is ICloneable[]))
407 /* add tests for interfaces that 'inherit' interfaces */
411 private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
413 private static int AbsoluteDays (int year, int month, int day)
416 int[] days = daysmonthleap;
419 return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
422 static int test_719162_complex_div () {
423 int adays = AbsoluteDays (1970, 1, 1);
427 static int test_1_store_decimal () {
428 decimal[,] a = {{1}};
435 static int test_2_intptr_stobj () {
436 System.IntPtr [] arr = { new System.IntPtr () };
438 if (arr [0] != (System.IntPtr)0)