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
28 static int Main (string[] args
) {
29 return TestDriver
.RunTests (typeof (Tests
), args
);
32 static public int test_0_many_nested_loops () {
33 // we do the loop a few times otherwise it's too fast
34 for (int i
= 0; i
< 5; ++i
) {
62 public static int test_0_logic_run ()
64 // GPL: Copyright (C) 2001 Southern Storm Software, Pty Ltd.
83 // First set of tests.
84 for(iter
= 0; iter
< 2000000; ++iter
) {
85 if((flag1
|| flag2
) && (flag3
|| flag4
) &&
86 (flag5
|| flag6
|| flag7
))
111 static public int test_1028_sieve () {
112 //int NUM = ((argc == 2) ? atoi(argv[1]) : 1);
114 byte[] flags
= new byte[8192 + 1];
120 for (i
=2; i
<= 8192; i
++) {
123 for (i
=2; i
<= 8192; i
++) {
125 // remove all multiples of prime: i
126 for (k
=i
+i
; k
<= 8192; k
+=i
) {
133 //printf("Count: %d\n", count);
137 public static int fib (int n
) {
140 return fib(n
-2)+fib(n
-1);
143 public static int test_3524578_fib () {
144 for (int i
= 0; i
< 10; i
++)
150 private static ulong numMoves
;
152 static void movetower (int disc
, int from, int to
, int use
) {
155 movetower (disc
-1, from, use
, to
);
156 movetower (disc
-1, use
, to
, from);
160 public static int test_0_hanoi () {
161 int iterations
= 5000;
165 while (iterations
> 0) {
167 movetower (numdiscs
, 1, 3, 2);
169 if (numMoves
!= 20475000)
174 public static int test_0_castclass () {
177 for (int i
= 0; i
< 100000000; i
++) {
178 string b
= (string)a
;
179 if ((object)a
!= (object)b
)
185 public static int test_23005000_float () {
206 /// Gaussian blur of a generated grayscale picture
207 private int test_0_blur(int size) {
208 const int num = 5; // Number of time to blur
209 byte[,] arr1 = new byte[size, size];
210 byte[,] arr2 = new byte[size, size];
214 while(iterations-- > 0) {
217 for(int i = 0; i < size; i++) {
218 for(int j = 0; j < size; j++) {
219 arr1[i, j] = (byte) (i%255);
223 for(int n = 0; n < num; n++) { // num rounds of blurring
224 for(int i = 3; i < size-3; i++) // vertical blur arr1 -> arr2
225 for(int j = 0; j < size; j++)
226 arr2[i, j] = (byte)((arr1[i-3, j] + arr1[i+3, j]
227 + 6*(arr1[i-2, j]+arr1[i+2, j])
228 + 15*(arr1[i-1, j]+arr1[i+1, j])
229 + 20*arr1[i, j] + 32)>>6);
231 for(int j = 3; j < size-3; j++) // horizontal blur arr1 -> arr2
232 for(int i = 0; i < size; i++)
233 arr1[i, j] = (byte)((arr2[i, j-3] + arr2[i, j+3]
234 + 6*(arr2[i, j-2]+arr2[i, j+2])
235 + 15*(arr2[i, j-1]+arr2[i, j+1])
236 + 20*arr2[i, j] + 32)>>6);