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
29 return TestDriver
.RunTests (typeof (Tests
));
32 public static int test_10_create () {
33 int[] a
= new int [10];
37 public static int test_0_unset_value () {
38 int[] a
= new int [10];
42 public static int test_3_set_value () {
43 int[] a
= new int [10];
48 public static int test_0_char_array_1 () {
50 char[] tmp
= new char [20];
51 char[] digitLowerTable
= new char[16];
52 tmp
[0] = digitLowerTable
[-(value % 10)];
56 public static int test_0_char_array_2 () {
58 char[] tmp
= new char [20];
59 char[] digitLowerTable
= new char[16];
60 tmp
[0] = digitLowerTable
[value % 10];
64 public static int test_0_char_array_3 () {
66 char[] tmp
= new char [20];
67 char[] digitLowerTable
= new char[16];
68 tmp
[0] = digitLowerTable
[value & 15];
72 public unsafe static int test_0_byte_array () {
73 byte [] src
= new byte [8];
75 byte *dst
= (byte *)&ret
;
78 dst
[0] = src
[4 + start
];
83 public static int test_0_set_after_shift () {
84 int [] n
= new int [1];
87 n
[0] = 100 + (1 << (16 - b
));
95 /* Regression test for #30073 */
96 public static int test_0_newarr_emulation () {
99 double [] arr
= new double [(int)d
];
104 private Int32
[] m_array
= new int [10];
106 void setBit (int bitIndex
, bool value) {
107 int index
= bitIndex
/32;
108 int shift
= bitIndex
%32;
110 Int32 theBit
= 1 << shift
;
112 m_array
[index
] |= theBit
;
114 m_array
[index
] &= ~theBit
;
117 bool getBit (int bitIndex
) {
118 int index
= bitIndex
/32;
119 int shift
= bitIndex
%32;
121 Int32 theBit
= m_array
[index
] & (1 << shift
);
122 return (theBit
== 0) ? false : true;
126 public static int test_1_bit_index () {
127 Tests t
= new Tests ();
141 int [] ma
= new int [56];
142 const int MBIG
= int.MaxValue
;
145 for (int k
= 1; k
< 5; k
++) {
146 for (int i
= 1; i
< 56; i
++) {
147 ma
[i
] -= ma
[1 + (i
+ 30) % 55];
155 public static int test_2_regalloc () {
156 helper1 h
= new helper1 ();
160 public static int test_0_stelemref_1 () {
161 object [] o
= new object [1];
167 public static int test_0_stelemref_2 () {
168 object [] o
= new object [1];
175 class Face
: IFace
{}
177 public static int test_0_stelemref_3 () {
178 object [] o
= new IFace
[1];
184 public static int test_0_stelemref_4 () {
185 object [][] o
= new object [5] [];
186 o
[0] = new object [5];
194 public FooStruct (int i
) {
199 public static int test_0_arrays () {
203 byte[] a1
= new byte [10];
204 for (int i
= 0; i
< 10; ++i
)
207 for (int i
= 0; i
< 10; ++i
)
212 sbyte[] a2
= new sbyte [10];
213 for (int i
= 0; i
< 10; ++i
)
216 for (int i
= 0; i
< 10; ++i
)
221 short[] a3
= new short [10];
222 for (int i
= 0; i
< 10; ++i
)
225 for (int i
= 0; i
< 10; ++i
)
230 ushort[] a4
= new ushort [10];
231 for (int i
= 0; i
< 10; ++i
)
234 for (int i
= 0; i
< 10; ++i
)
239 int[] a5
= new int [10];
240 for (int i
= 0; i
< 10; ++i
)
243 for (int i
= 0; i
< 10; ++i
)
248 uint[] a6
= new uint [10];
249 for (int i
= 0; i
< 10; ++i
)
252 for (int i
= 0; i
< 10; ++i
)
257 long[] a7
= new long [10];
258 for (int i
= 0; i
< 10; ++i
)
261 for (int i
= 0; i
< 10; ++i
)
266 ulong[] a8
= new ulong [10];
267 for (int i
= 0; i
< 10; ++i
)
270 for (int i
= 0; i
< 10; ++i
)
275 float[] a9
= new float [10];
276 for (int i
= 0; i
< 10; ++i
)
279 for (int i
= 0; i
< 10; ++i
)
284 double[] a10
= new double [10];
285 for (int i
= 0; i
< 10; ++i
)
288 for (int i
= 0; i
< 10; ++i
)
293 object[] a11
= new object [10];
294 object o
= new Object ();
295 for (int i
= 0; i
< 10; ++i
)
297 for (int i
= 0; i
< 10; ++i
)
301 FooStruct
[] a12
= new FooStruct
[10];
302 for (int i
= 0; i
< 10; ++i
)
303 a12
[i
] = new FooStruct (i
);
305 for (int i
= 0; i
< 10; ++i
)
313 public static int test_0_multi_dimension_arrays () {
316 byte[,] a1
= new byte [10, 10];
317 for (int i
= 0; i
< 10; ++i
)
320 for (int i
= 0; i
< 10; ++i
)
325 sbyte[,] a2
= new sbyte [10, 10];
326 for (int i
= 0; i
< 10; ++i
)
327 a2
[i
, i
] = (sbyte)i
;
329 for (int i
= 0; i
< 10; ++i
)
334 short[,] a3
= new short [10, 10];
335 for (int i
= 0; i
< 10; ++i
)
336 a3
[i
, i
] = (short)i
;
338 for (int i
= 0; i
< 10; ++i
)
343 ushort[,] a4
= new ushort [10, 10];
344 for (int i
= 0; i
< 10; ++i
)
345 a4
[i
, i
] = (ushort)i
;
347 for (int i
= 0; i
< 10; ++i
)
352 int[,] a5
= new int [10, 10];
353 for (int i
= 0; i
< 10; ++i
)
356 for (int i
= 0; i
< 10; ++i
)
361 uint[,] a6
= new uint [10, 10];
362 for (int i
= 0; i
< 10; ++i
)
365 for (int i
= 0; i
< 10; ++i
)
366 sum
+= (int)a6
[i
, i
];
370 long[,] a7
= new long [10, 10];
371 for (int i
= 0; i
< 10; ++i
)
374 for (int i
= 0; i
< 10; ++i
)
375 sum
+= (int)a7
[i
, i
];
379 ulong[,] a8
= new ulong [10, 10];
380 for (int i
= 0; i
< 10; ++i
)
381 a8
[i
, i
] = (ulong)i
;
383 for (int i
= 0; i
< 10; ++i
)
384 sum
+= (int)a8
[i
, i
];
388 float[,] a9
= new float [10, 10];
389 for (int i
= 0; i
< 10; ++i
)
390 a9
[i
, i
] = (float)i
;
392 for (int i
= 0; i
< 10; ++i
)
393 sum
+= (int)a9
[i
, i
];
397 double[,] a10
= new double [10, 10];
398 for (int i
= 0; i
< 10; ++i
)
401 for (int i
= 0; i
< 10; ++i
)
402 sum
+= (int)a10
[i
, i
];
406 object[,] a11
= new object [10, 10];
407 object o
= new Object ();
408 for (int i
= 0; i
< 10; ++i
)
410 for (int i
= 0; i
< 10; ++i
)
414 FooStruct
[,] a12
= new FooStruct
[10, 10];
415 for (int i
= 0; i
< 10; ++i
)
416 for (int j
= 0; j
< 10; ++j
) {
417 /* This one calls Address */
418 a12
[i
, j
] = new FooStruct (i
+ j
);
420 /* Test Set as well */
421 FooStruct s
= new FooStruct (i
+ j
);
425 for (int i
= 0; i
< 10; ++i
)
426 for (int j
= 0; j
< 10; ++j
) {
427 /* This one calls Address */
430 /* Test Get as well */
431 FooStruct s
= a12
[i
, j
];
440 public static int test_0_bug_71454 () {
441 int[,] a
= new int[4,4];
442 int[,] b
= new int[4,4];
443 for(int i
= 0; i
< 4; ++i
) {
449 public static int test_0_interface_array_cast () {
451 object [] a
= new ICloneable
[2];
452 ICloneable
[] b
= (ICloneable
[])a
;
460 public static Foo
[][] foo
;
463 public static int test_0_regress_74549 () {
468 public static int test_0_regress_75832 () {
469 int[] table
= new int[] { 0, 0 }
;
480 public static int test_0_stelem_ref_null_opt () {
481 object[] arr
= new Tests
[1];
483 arr
[0] = new Tests ();
486 return arr
[0] == null ? 0 : 1;
489 public static int test_0_invalid_new_array_size () {
494 res
= new float [size
];
495 } catch (OverflowException e
) {
497 } catch (Exception
) {
505 res
= new float [size
];
506 } catch (OverflowException e
) {
508 } catch (Exception
) {
518 public static int test_0_multidym_array_with_negative_lower_bound () {
519 int[,] x
= (int[,]) Array
.CreateInstance(typeof (int), new int[] { 2, 2 }
, new int[] { -2, -3 }
);
521 if(x
.GetLowerBound (0) != -2)
523 if (x
.GetLowerBound (1) != -3)
526 x
.SetValue (10, new int [] { -2, -3 }
);
527 x
.SetValue (20, new int [] { -2, -2 }
);
528 x
.SetValue (30, new int [] { -1, -3 }
);
529 x
.SetValue (40, new int [] { -1, -2 }
);
532 x
.SetValue (10, new int [] { -3, -3 }
);
534 } catch (IndexOutOfRangeException
) { }
537 x
.SetValue (10, new int [] { -2, -4 }
);
539 } catch (IndexOutOfRangeException
) { }
542 x
.SetValue (10, new int [] { 0, -3 }
);
544 } catch (IndexOutOfRangeException
) { }
547 x
.SetValue (10, new int [] { -1, -1 }
);
549 } catch (IndexOutOfRangeException
) { }
551 if ((int)x
.GetValue (new int [] { -2, -3 }
) != 10)
553 if ((int)x
.GetValue (new int [] { -2, -2 }
) != 20)
555 if ((int)x
.GetValue (new int [] { -1, -3 }
) != 30)
557 if ((int)x
.GetValue (new int [] { -1, -2 }
) != 40)
561 x
.GetValue (new int [] { -3, -3 }
);
563 } catch (IndexOutOfRangeException
) { }
566 x
.GetValue ( new int [] { -2, -4 }
);
568 } catch (IndexOutOfRangeException
) { }
571 x
.GetValue (new int [] { 0, -3 }
);
573 } catch (IndexOutOfRangeException
) { }
576 x
.GetValue (new int [] { -1, -1 }
);
578 } catch (IndexOutOfRangeException
) { }
583 public static int test_0_invalid_new_multi_dym_array_size () {
589 res
= new float [dym_size
, size
];
590 } catch (OverflowException e
) {
592 } catch (Exception
) {
600 res
= new float [size
, dym_size
];
601 } catch (OverflowException e
) {
603 } catch (Exception
) {
613 public static int long_indices () {
614 int[] arr
= new int [10];
615 int[,] arr2
= new int [10, 10];
618 if (arr
[index
] != 5)
620 arr2
[index
, index
] = 5;
621 if (arr2
[index
, index
] != 5)