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 [Category ("!INTERPRETER")]
322 public static int test_0_multi_dimension_arrays () {
325 byte[,] a1 = new byte [10, 10];
326 for (int i = 0; i < 10; ++i)
329 for (int i = 0; i < 10; ++i)
334 sbyte[,] a2 = new sbyte [10, 10];
335 for (int i = 0; i < 10; ++i)
336 a2 [i, i] = (sbyte)i;
338 for (int i = 0; i < 10; ++i)
343 short[,] a3 = new short [10, 10];
344 for (int i = 0; i < 10; ++i)
345 a3 [i, i] = (short)i;
347 for (int i = 0; i < 10; ++i)
352 ushort[,] a4 = new ushort [10, 10];
353 for (int i = 0; i < 10; ++i)
354 a4 [i, i] = (ushort)i;
356 for (int i = 0; i < 10; ++i)
361 int[,] a5 = new int [10, 10];
362 for (int i = 0; i < 10; ++i)
365 for (int i = 0; i < 10; ++i)
370 uint[,] a6 = new uint [10, 10];
371 for (int i = 0; i < 10; ++i)
374 for (int i = 0; i < 10; ++i)
375 sum += (int)a6 [i, i];
379 long[,] a7 = new long [10, 10];
380 for (int i = 0; i < 10; ++i)
383 for (int i = 0; i < 10; ++i)
384 sum += (int)a7 [i, i];
388 ulong[,] a8 = new ulong [10, 10];
389 for (int i = 0; i < 10; ++i)
390 a8 [i, i] = (ulong)i;
392 for (int i = 0; i < 10; ++i)
393 sum += (int)a8 [i, i];
397 float[,] a9 = new float [10, 10];
398 for (int i = 0; i < 10; ++i)
399 a9 [i, i] = (float)i;
401 for (int i = 0; i < 10; ++i)
402 sum += (int)a9 [i, i];
406 double[,] a10 = new double [10, 10];
407 for (int i = 0; i < 10; ++i)
410 for (int i = 0; i < 10; ++i)
411 sum += (int)a10 [i, i];
415 object[,] a11 = new object [10, 10];
416 object o = new Object ();
417 for (int i = 0; i < 10; ++i)
419 for (int i = 0; i < 10; ++i)
423 FooStruct[,] a12 = new FooStruct [10, 10];
424 for (int i = 0; i < 10; ++i)
425 for (int j = 0; j < 10; ++j) {
426 /* This one calls Address */
427 a12 [i, j] = new FooStruct (i + j);
429 /* Test Set as well */
430 FooStruct s = new FooStruct (i + j);
434 for (int i = 0; i < 10; ++i)
435 for (int j = 0; j < 10; ++j) {
436 /* This one calls Address */
439 /* Test Get as well */
440 FooStruct s = a12 [i, j];
447 object[,] a13 = null;
449 a13 [0, 0] = new Object ();
451 } catch (NullReferenceException) {
457 public static int test_100_3_dimensional_arrays () {
458 int[,,] test = new int[10, 10, 10];
460 test [1, 1, 1] = 100;
461 return test [1, 1, 1];
464 public static int test_100_4_dimensional_arrays () {
465 int[,,,] test = new int[10, 10, 10, 10];
467 test [1, 1, 1, 1] = 100;
468 return test [1, 1, 1, 1];
471 public static int test_0_bug_71454 () {
472 int[,] a = new int[4,4];
473 int[,] b = new int[4,4];
474 for(int i = 0; i < 4; ++i) {
480 public static int test_0_interface_array_cast () {
482 object [] a = new ICloneable [2];
483 ICloneable [] b = (ICloneable [])a;
491 public static Foo[][] foo;
494 public static int test_0_regress_74549 () {
499 public static int test_0_regress_75832 () {
500 int[] table = new int[] { 0, 0 };
514 public static int test_0_stelem_ref_null_opt () {
515 object[] arr = new RefClass [1];
517 arr [0] = new RefClass ();
520 return arr [0] == null ? 0 : 1;
523 public static int test_0_invalid_new_array_size () {
528 res = new float [size];
529 } catch (OverflowException e) {
531 } catch (Exception) {
539 res = new float [size];
540 } catch (OverflowException e) {
542 } catch (Exception) {
552 [Category ("!INTERPRETER")]
553 public static int test_0_multidym_array_with_negative_lower_bound () {
554 int[,] x = (int[,]) Array.CreateInstance(typeof (int), new int[] { 2, 2 }, new int[] { -2, -3 });
556 if(x.GetLowerBound (0) != -2)
558 if (x.GetLowerBound (1) != -3)
561 x.SetValue (10, new int [] { -2, -3 });
562 x.SetValue (20, new int [] { -2, -2 });
563 x.SetValue (30, new int [] { -1, -3 });
564 x.SetValue (40, new int [] { -1, -2 });
567 x.SetValue (10, new int [] { -3, -3 });
569 } catch (IndexOutOfRangeException) { }
572 x.SetValue (10, new int [] { -2, -4 });
574 } catch (IndexOutOfRangeException) { }
577 x.SetValue (10, new int [] { 0, -3 });
579 } catch (IndexOutOfRangeException) { }
582 x.SetValue (10, new int [] { -1, -1 });
584 } catch (IndexOutOfRangeException) { }
586 if ((int)x.GetValue (new int [] { -2, -3 }) != 10)
588 if ((int)x.GetValue (new int [] { -2, -2 }) != 20)
590 if ((int)x.GetValue (new int [] { -1, -3 }) != 30)
592 if ((int)x.GetValue (new int [] { -1, -2 }) != 40)
596 x.GetValue (new int [] { -3, -3 });
598 } catch (IndexOutOfRangeException) { }
601 x.GetValue ( new int [] { -2, -4 });
603 } catch (IndexOutOfRangeException) { }
606 x.GetValue (new int [] { 0, -3 });
608 } catch (IndexOutOfRangeException) { }
611 x.GetValue (new int [] { -1, -1 });
613 } catch (IndexOutOfRangeException) { }
618 public static int test_0_invalid_new_multi_dym_array_size () {
624 res = new float [dym_size, size];
625 } catch (OverflowException e) {
627 } catch (Exception) {
635 res = new float [size, dym_size];
636 } catch (OverflowException e) {
638 } catch (Exception) {
648 public enum IntEnum {
652 public enum UintEnum : uint {
656 static bool TryCast<T> (object o) {
660 public static int test_0_primitive_array_cast () {
661 object a = new int[1];
662 object b = new uint[1];
663 object c = new IntEnum[1];
664 object d = new UintEnum[1];
666 object[] arr = new object[] { a, b, c, d };
669 foreach (var v in arr) {
670 if (!TryCast<int> (v))
672 if (!TryCast<uint> (v))
674 if (!TryCast<IntEnum> (v))
676 if (!TryCast<UintEnum> (v))
681 foreach (var v in arr) {
686 if (!(v is IntEnum[]))
688 if (!(v is UintEnum[]))
695 public static int test_0_intptr_array_cast () {
696 object[] a = new object[] { new int[1], new uint[1] };
697 object[] b = new object[] { new long[1], new ulong[1] };
698 object[] c = new object[] { new IntPtr[1], new UIntPtr[1] };
701 if (IntPtr.Size == 4) {
702 foreach (var v in a) {
703 if (!(v is IntPtr[]))
705 if (!(v is IntPtr[]))
709 foreach (var v in b) {
717 foreach (var v in c) {
725 foreach (var v in a) {
732 foreach (var v in b) {
733 if (!(v is IntPtr[]))
735 if (!(v is IntPtr[]))
739 foreach (var v in c) {
750 public static int test_0_long_indices () {
751 int[] arr = new int [10];
752 int[,] arr2 = new int [10, 10];
755 if (arr [index] != 5)
757 arr2 [index, index] = 5;
758 if (arr2 [index, index] != 5)
764 public static int test_0_ldelema_2_64bit () {
765 bool[,] test = new bool[201,201];
767 for(x=-100;x<100;x++) for(y=-100;y<100;y++){
768 test[x+100,y+100] = true;
773 static bool alloc_long (long l) {
775 var arr = new byte[l];
777 } catch (Exception e) {
783 [Category ("!INTERPRETER")]
784 public static int test_0_newarr_ovf () {
785 if (!alloc_long (5000000000))
787 if (!alloc_long (4000000000))
789 if (!alloc_long (-1))
791 if (!alloc_long (-4000000000))
793 if (!alloc_long (-6000000000))
798 static int llvm_ldlen_licm (int[] arr) {
800 // The ldlen should be moved out of the loop
801 for (int i = 0; i < arr.Length; ++i)
806 public static int test_10_llvm_ldlen_licm () {
807 int[] arr = new int [10];
808 for (int i = 0; i < 10; ++i)
810 return llvm_ldlen_licm (arr);