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
];
438 object[,] a13
= null;
440 a13
[0, 0] = new Object ();
442 } catch (NullReferenceException
) {
448 public static int test_100_3_dimensional_arrays () {
449 int[,,] test
= new int[10, 10, 10];
451 test
[1, 1, 1] = 100;
452 return test
[1, 1, 1];
455 public static int test_0_bug_71454 () {
456 int[,] a
= new int[4,4];
457 int[,] b
= new int[4,4];
458 for(int i
= 0; i
< 4; ++i
) {
464 public static int test_0_interface_array_cast () {
466 object [] a
= new ICloneable
[2];
467 ICloneable
[] b
= (ICloneable
[])a
;
475 public static Foo
[][] foo
;
478 public static int test_0_regress_74549 () {
483 public static int test_0_regress_75832 () {
484 int[] table
= new int[] { 0, 0 }
;
495 public static int test_0_stelem_ref_null_opt () {
496 object[] arr
= new Tests
[1];
498 arr
[0] = new Tests ();
501 return arr
[0] == null ? 0 : 1;
504 public static int test_0_invalid_new_array_size () {
509 res
= new float [size
];
510 } catch (OverflowException e
) {
512 } catch (Exception
) {
520 res
= new float [size
];
521 } catch (OverflowException e
) {
523 } catch (Exception
) {
533 public static int test_0_multidym_array_with_negative_lower_bound () {
534 int[,] x
= (int[,]) Array
.CreateInstance(typeof (int), new int[] { 2, 2 }
, new int[] { -2, -3 }
);
536 if(x
.GetLowerBound (0) != -2)
538 if (x
.GetLowerBound (1) != -3)
541 x
.SetValue (10, new int [] { -2, -3 }
);
542 x
.SetValue (20, new int [] { -2, -2 }
);
543 x
.SetValue (30, new int [] { -1, -3 }
);
544 x
.SetValue (40, new int [] { -1, -2 }
);
547 x
.SetValue (10, new int [] { -3, -3 }
);
549 } catch (IndexOutOfRangeException
) { }
552 x
.SetValue (10, new int [] { -2, -4 }
);
554 } catch (IndexOutOfRangeException
) { }
557 x
.SetValue (10, new int [] { 0, -3 }
);
559 } catch (IndexOutOfRangeException
) { }
562 x
.SetValue (10, new int [] { -1, -1 }
);
564 } catch (IndexOutOfRangeException
) { }
566 if ((int)x
.GetValue (new int [] { -2, -3 }
) != 10)
568 if ((int)x
.GetValue (new int [] { -2, -2 }
) != 20)
570 if ((int)x
.GetValue (new int [] { -1, -3 }
) != 30)
572 if ((int)x
.GetValue (new int [] { -1, -2 }
) != 40)
576 x
.GetValue (new int [] { -3, -3 }
);
578 } catch (IndexOutOfRangeException
) { }
581 x
.GetValue ( new int [] { -2, -4 }
);
583 } catch (IndexOutOfRangeException
) { }
586 x
.GetValue (new int [] { 0, -3 }
);
588 } catch (IndexOutOfRangeException
) { }
591 x
.GetValue (new int [] { -1, -1 }
);
593 } catch (IndexOutOfRangeException
) { }
598 public static int test_0_invalid_new_multi_dym_array_size () {
604 res
= new float [dym_size
, size
];
605 } catch (OverflowException e
) {
607 } catch (Exception
) {
615 res
= new float [size
, dym_size
];
616 } catch (OverflowException e
) {
618 } catch (Exception
) {
628 public enum IntEnum
{
632 public enum UintEnum
: uint {
636 static bool TryCast
<T
> (object o
) {
640 public static int test_0_primitive_array_cast () {
641 object a
= new int[1];
642 object b
= new uint[1];
643 object c
= new IntEnum
[1];
644 object d
= new UintEnum
[1];
646 object[] arr
= new object[] { a, b, c, d }
;
649 foreach (var v
in arr
) {
650 if (!TryCast
<int> (v
))
652 if (!TryCast
<uint> (v
))
654 if (!TryCast
<IntEnum
> (v
))
656 if (!TryCast
<UintEnum
> (v
))
661 foreach (var v
in arr
) {
666 if (!(v
is IntEnum
[]))
668 if (!(v
is UintEnum
[]))
675 public static int test_0_intptr_array_cast () {
676 object[] a
= new object[] { new int[1], new uint[1] }
;
677 object[] b
= new object[] { new long[1], new ulong[1] }
;
678 object[] c
= new object[] { new IntPtr[1], new UIntPtr[1] }
;
681 if (IntPtr
.Size
== 4) {
682 foreach (var v
in a
) {
683 if (!(v
is IntPtr
[]))
685 if (!(v
is IntPtr
[]))
689 foreach (var v
in b
) {
697 foreach (var v
in c
) {
705 foreach (var v
in a
) {
712 foreach (var v
in b
) {
713 if (!(v
is IntPtr
[]))
715 if (!(v
is IntPtr
[]))
719 foreach (var v
in c
) {
730 public static int long_indices () {
731 int[] arr
= new int [10];
732 int[,] arr2
= new int [10, 10];
735 if (arr
[index
] != 5)
737 arr2
[index
, index
] = 5;
738 if (arr2
[index
, index
] != 5)