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
34 public static int Main (string[] args
) {
35 return TestDriver
.RunTests (typeof (Tests
), args
);
39 public static int test_10_create () {
40 int[] a
= new int [10];
44 public static int test_0_unset_value () {
45 int[] a
= new int [10];
49 public static int test_3_set_value () {
50 int[] a
= new int [10];
55 public static int test_0_char_array_1 () {
57 char[] tmp
= new char [20];
58 char[] digitLowerTable
= new char[16];
59 tmp
[0] = digitLowerTable
[-(value % 10)];
63 public static int test_0_char_array_2 () {
65 char[] tmp
= new char [20];
66 char[] digitLowerTable
= new char[16];
67 tmp
[0] = digitLowerTable
[value % 10];
71 public static int test_0_char_array_3 () {
73 char[] tmp
= new char [20];
74 char[] digitLowerTable
= new char[16];
75 tmp
[0] = digitLowerTable
[value & 15];
79 public unsafe static int test_0_byte_array () {
80 byte [] src
= new byte [8];
82 byte *dst
= (byte *)&ret
;
85 dst
[0] = src
[4 + start
];
90 public static int test_0_set_after_shift () {
91 int [] n
= new int [1];
94 n
[0] = 100 + (1 << (16 - b
));
102 /* Regression test for #30073 */
103 public static int test_0_newarr_emulation () {
106 double [] arr
= new double [(int)d
];
112 private Int32
[] m_array
= new int [10];
114 public void setBit (int bitIndex
, bool value) {
115 int index
= bitIndex
/32;
116 int shift
= bitIndex
%32;
118 Int32 theBit
= 1 << shift
;
120 m_array
[index
] |= theBit
;
122 m_array
[index
] &= ~theBit
;
125 public bool getBit (int bitIndex
) {
126 int index
= bitIndex
/32;
127 int shift
= bitIndex
%32;
129 Int32 theBit
= m_array
[index
] & (1 << shift
);
130 return (theBit
== 0) ? false : true;
134 public static int test_1_bit_index () {
135 var t
= new BitClass ();
149 int [] ma
= new int [56];
150 const int MBIG
= int.MaxValue
;
153 for (int k
= 1; k
< 5; k
++) {
154 for (int i
= 1; i
< 56; i
++) {
155 ma
[i
] -= ma
[1 + (i
+ 30) % 55];
163 public static int test_2_regalloc () {
164 helper1 h
= new helper1 ();
168 public static int test_0_stelemref_1 () {
169 object [] o
= new object [1];
175 public static int test_0_stelemref_2 () {
176 object [] o
= new object [1];
183 class Face
: IFace
{}
185 public static int test_0_stelemref_3 () {
186 object [] o
= new IFace
[1];
192 public static int test_0_stelemref_4 () {
193 object [][] o
= new object [5] [];
194 o
[0] = new object [5];
202 public FooStruct (int i
) {
207 public static int test_0_arrays () {
211 byte[] a1
= new byte [10];
212 for (int i
= 0; i
< 10; ++i
)
215 for (int i
= 0; i
< 10; ++i
)
220 sbyte[] a2
= new sbyte [10];
221 for (int i
= 0; i
< 10; ++i
)
224 for (int i
= 0; i
< 10; ++i
)
229 short[] a3
= new short [10];
230 for (int i
= 0; i
< 10; ++i
)
233 for (int i
= 0; i
< 10; ++i
)
238 ushort[] a4
= new ushort [10];
239 for (int i
= 0; i
< 10; ++i
)
242 for (int i
= 0; i
< 10; ++i
)
247 int[] a5
= new int [10];
248 for (int i
= 0; i
< 10; ++i
)
251 for (int i
= 0; i
< 10; ++i
)
256 uint[] a6
= new uint [10];
257 for (int i
= 0; i
< 10; ++i
)
260 for (int i
= 0; i
< 10; ++i
)
265 long[] a7
= new long [10];
266 for (int i
= 0; i
< 10; ++i
)
269 for (int i
= 0; i
< 10; ++i
)
274 ulong[] a8
= new ulong [10];
275 for (int i
= 0; i
< 10; ++i
)
278 for (int i
= 0; i
< 10; ++i
)
283 float[] a9
= new float [10];
284 for (int i
= 0; i
< 10; ++i
)
287 for (int i
= 0; i
< 10; ++i
)
292 double[] a10
= new double [10];
293 for (int i
= 0; i
< 10; ++i
)
296 for (int i
= 0; i
< 10; ++i
)
301 object[] a11
= new object [10];
302 object o
= new Object ();
303 for (int i
= 0; i
< 10; ++i
)
305 for (int i
= 0; i
< 10; ++i
)
309 FooStruct
[] a12
= new FooStruct
[10];
310 for (int i
= 0; i
< 10; ++i
)
311 a12
[i
] = new FooStruct (i
);
313 for (int i
= 0; i
< 10; ++i
)
321 public static int test_0_multi_dimension_arrays () {
324 byte[,] a1
= new byte [10, 10];
325 for (int i
= 0; i
< 10; ++i
)
328 for (int i
= 0; i
< 10; ++i
)
333 sbyte[,] a2
= new sbyte [10, 10];
334 for (int i
= 0; i
< 10; ++i
)
335 a2
[i
, i
] = (sbyte)i
;
337 for (int i
= 0; i
< 10; ++i
)
342 short[,] a3
= new short [10, 10];
343 for (int i
= 0; i
< 10; ++i
)
344 a3
[i
, i
] = (short)i
;
346 for (int i
= 0; i
< 10; ++i
)
351 ushort[,] a4
= new ushort [10, 10];
352 for (int i
= 0; i
< 10; ++i
)
353 a4
[i
, i
] = (ushort)i
;
355 for (int i
= 0; i
< 10; ++i
)
360 int[,] a5
= new int [10, 10];
361 for (int i
= 0; i
< 10; ++i
)
364 for (int i
= 0; i
< 10; ++i
)
369 uint[,] a6
= new uint [10, 10];
370 for (int i
= 0; i
< 10; ++i
)
373 for (int i
= 0; i
< 10; ++i
)
374 sum
+= (int)a6
[i
, i
];
378 long[,] a7
= new long [10, 10];
379 for (int i
= 0; i
< 10; ++i
)
382 for (int i
= 0; i
< 10; ++i
)
383 sum
+= (int)a7
[i
, i
];
387 ulong[,] a8
= new ulong [10, 10];
388 for (int i
= 0; i
< 10; ++i
)
389 a8
[i
, i
] = (ulong)i
;
391 for (int i
= 0; i
< 10; ++i
)
392 sum
+= (int)a8
[i
, i
];
396 float[,] a9
= new float [10, 10];
397 for (int i
= 0; i
< 10; ++i
)
398 a9
[i
, i
] = (float)i
;
400 for (int i
= 0; i
< 10; ++i
)
401 sum
+= (int)a9
[i
, i
];
405 double[,] a10
= new double [10, 10];
406 for (int i
= 0; i
< 10; ++i
)
409 for (int i
= 0; i
< 10; ++i
)
410 sum
+= (int)a10
[i
, i
];
414 object[,] a11
= new object [10, 10];
415 object o
= new Object ();
416 for (int i
= 0; i
< 10; ++i
)
418 for (int i
= 0; i
< 10; ++i
)
422 FooStruct
[,] a12
= new FooStruct
[10, 10];
423 for (int i
= 0; i
< 10; ++i
)
424 for (int j
= 0; j
< 10; ++j
) {
425 /* This one calls Address */
426 a12
[i
, j
] = new FooStruct (i
+ j
);
428 /* Test Set as well */
429 FooStruct s
= new FooStruct (i
+ j
);
433 for (int i
= 0; i
< 10; ++i
)
434 for (int j
= 0; j
< 10; ++j
) {
435 /* This one calls Address */
438 /* Test Get as well */
439 FooStruct s
= a12
[i
, j
];
446 object[,] a13
= null;
448 a13
[0, 0] = new Object ();
450 } catch (NullReferenceException
) {
456 public static int test_100_3_dimensional_arrays () {
457 int[,,] test
= new int[10, 10, 10];
459 test
[1, 1, 1] = 100;
460 return test
[1, 1, 1];
463 public static int test_100_4_dimensional_arrays () {
464 int[,,,] test
= new int[10, 10, 10, 10];
466 test
[1, 1, 1, 1] = 100;
467 return test
[1, 1, 1, 1];
470 public static int test_0_bug_71454 () {
471 int[,] a
= new int[4,4];
472 int[,] b
= new int[4,4];
473 for(int i
= 0; i
< 4; ++i
) {
479 public static int test_0_interface_array_cast () {
481 object [] a
= new ICloneable
[2];
482 ICloneable
[] b
= (ICloneable
[])a
;
490 public static Foo
[][] foo
;
493 public static int test_0_regress_74549 () {
498 public static int test_0_regress_75832 () {
499 int[] table
= new int[] { 0, 0 }
;
513 public static int test_0_stelem_ref_null_opt () {
514 object[] arr
= new RefClass
[1];
516 arr
[0] = new RefClass ();
519 return arr
[0] == null ? 0 : 1;
522 public static int test_0_invalid_new_array_size () {
527 res
= new float [size
];
528 } catch (OverflowException e
) {
530 } catch (Exception
) {
538 res
= new float [size
];
539 } catch (OverflowException e
) {
541 } catch (Exception
) {
551 public static int test_0_multidym_array_with_negative_lower_bound () {
552 int[,] x
= (int[,]) Array
.CreateInstance(typeof (int), new int[] { 2, 2 }
, new int[] { -2, -3 }
);
554 if(x
.GetLowerBound (0) != -2)
556 if (x
.GetLowerBound (1) != -3)
559 x
.SetValue (10, new int [] { -2, -3 }
);
560 x
.SetValue (20, new int [] { -2, -2 }
);
561 x
.SetValue (30, new int [] { -1, -3 }
);
562 x
.SetValue (40, new int [] { -1, -2 }
);
565 x
.SetValue (10, new int [] { -3, -3 }
);
567 } catch (IndexOutOfRangeException
) { }
570 x
.SetValue (10, new int [] { -2, -4 }
);
572 } catch (IndexOutOfRangeException
) { }
575 x
.SetValue (10, new int [] { 0, -3 }
);
577 } catch (IndexOutOfRangeException
) { }
580 x
.SetValue (10, new int [] { -1, -1 }
);
582 } catch (IndexOutOfRangeException
) { }
584 if ((int)x
.GetValue (new int [] { -2, -3 }
) != 10)
586 if ((int)x
.GetValue (new int [] { -2, -2 }
) != 20)
588 if ((int)x
.GetValue (new int [] { -1, -3 }
) != 30)
590 if ((int)x
.GetValue (new int [] { -1, -2 }
) != 40)
594 x
.GetValue (new int [] { -3, -3 }
);
596 } catch (IndexOutOfRangeException
) { }
599 x
.GetValue ( new int [] { -2, -4 }
);
601 } catch (IndexOutOfRangeException
) { }
604 x
.GetValue (new int [] { 0, -3 }
);
606 } catch (IndexOutOfRangeException
) { }
609 x
.GetValue (new int [] { -1, -1 }
);
611 } catch (IndexOutOfRangeException
) { }
616 public static int test_0_invalid_new_multi_dym_array_size () {
622 res
= new float [dym_size
, size
];
623 } catch (OverflowException e
) {
625 } catch (Exception
) {
633 res
= new float [size
, dym_size
];
634 } catch (OverflowException e
) {
636 } catch (Exception
) {
646 public enum IntEnum
{
650 public enum UintEnum
: uint {
654 static bool TryCast
<T
> (object o
) {
658 public static int test_0_primitive_array_cast () {
659 object a
= new int[1];
660 object b
= new uint[1];
661 object c
= new IntEnum
[1];
662 object d
= new UintEnum
[1];
664 object[] arr
= new object[] { a, b, c, d }
;
667 foreach (var v
in arr
) {
668 if (!TryCast
<int> (v
))
670 if (!TryCast
<uint> (v
))
672 if (!TryCast
<IntEnum
> (v
))
674 if (!TryCast
<UintEnum
> (v
))
679 foreach (var v
in arr
) {
684 if (!(v
is IntEnum
[]))
686 if (!(v
is UintEnum
[]))
693 public static int test_0_intptr_array_cast () {
694 object[] a
= new object[] { new int[1], new uint[1] }
;
695 object[] b
= new object[] { new long[1], new ulong[1] }
;
696 object[] c
= new object[] { new IntPtr[1], new UIntPtr[1] }
;
699 if (IntPtr
.Size
== 4) {
700 foreach (var v
in a
) {
701 if (!(v
is IntPtr
[]))
703 if (!(v
is IntPtr
[]))
707 foreach (var v
in b
) {
715 foreach (var v
in c
) {
723 foreach (var v
in a
) {
730 foreach (var v
in b
) {
731 if (!(v
is IntPtr
[]))
733 if (!(v
is IntPtr
[]))
737 foreach (var v
in c
) {
748 public static int test_0_long_indices () {
749 int[] arr
= new int [10];
750 int[,] arr2
= new int [10, 10];
753 if (arr
[index
] != 5)
755 arr2
[index
, index
] = 5;
756 if (arr2
[index
, index
] != 5)
762 public static int test_0_ldelema_2_64bit () {
763 bool[,] test
= new bool[201,201];
765 for(x
=-100;x
<100;x
++) for(y
=-100;y
<100;y
++){
766 test
[x
+100,y
+100] = true;
771 public struct TestStruct
{
775 public static int test_0_ldelema () {
777 TestStruct
[] frames
= null;
780 } catch (NullReferenceException
) {
785 static bool alloc_long (long l
) {
787 var arr
= new byte[l
];
789 } catch (Exception e
) {
795 public static int test_0_newarr_ovf () {
796 if (!alloc_long (5000000000))
798 if (!alloc_long (4000000000))
800 if (!alloc_long (-1))
802 if (!alloc_long (-4000000000))
804 if (!alloc_long (-6000000000))
809 static int llvm_ldlen_licm (int[] arr
) {
811 // The ldlen should be moved out of the loop
812 for (int i
= 0; i
< arr
.Length
; ++i
)
817 public static int test_10_llvm_ldlen_licm () {
818 int[] arr
= new int [10];
819 for (int i
= 0; i
< 10; ++i
)
821 return llvm_ldlen_licm (arr
);