2 using System
.Reflection
;
5 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
6 * Regression tests for the mono JIT.
8 * Each test needs to be of the form:
10 * static int test_<result>_<name> ();
12 * where <result> is an integer (the value that needs to be returned by
13 * the method to make it pass.
14 * <name> is a user-displayed name used to identify the test.
16 * The tests can be driven in two ways:
17 * *) running the program directly: Main() uses reflection to find and invoke
18 * the test methods (this is useful mostly to check that the tests are correct)
19 * *) with the --regression switch of the jit (this is the preferred way since
20 * all the tests will be run with optimizations on and off)
22 * The reflection logic could be moved to a .dll since we need at least another
23 * regression test file written in IL code to have better control on how
29 static int Main (string[] args
) {
30 return TestDriver
.RunTests (typeof (Tests
), args
);
33 static public int test_0_many_nested_loops () {
34 // we do the loop a few times otherwise it's too fast
35 for (int i
= 0; i
< 5; ++i
) {
63 public static int test_0_logic_run ()
65 // GPL: Copyright (C) 2001 Southern Storm Software, Pty Ltd.
84 // First set of tests.
85 for(iter
= 0; iter
< 2000000; ++iter
) {
86 if((flag1
|| flag2
) && (flag3
|| flag4
) &&
87 (flag5
|| flag6
|| flag7
))
112 static public int test_1028_sieve () {
113 //int NUM = ((argc == 2) ? atoi(argv[1]) : 1);
115 byte[] flags
= new byte[8192 + 1];
121 for (i
=2; i
<= 8192; i
++) {
124 for (i
=2; i
<= 8192; i
++) {
126 // remove all multiples of prime: i
127 for (k
=i
+i
; k
<= 8192; k
+=i
) {
134 //printf("Count: %d\n", count);
138 public static int fib (int n
) {
141 return fib(n
-2)+fib(n
-1);
144 public static int test_3524578_fib () {
145 for (int i
= 0; i
< 10; i
++)
151 private static ulong numMoves
;
153 static void movetower (int disc
, int from, int to
, int use
) {
156 movetower (disc
-1, from, use
, to
);
157 movetower (disc
-1, use
, to
, from);
161 public static int test_0_hanoi () {
162 int iterations
= 5000;
166 while (iterations
> 0) {
168 movetower (numdiscs
, 1, 3, 2);
170 if (numMoves
!= 20475000)
175 public static int test_0_castclass () {
178 for (int i
= 0; i
< 100000000; i
++) {
179 string b
= (string)a
;
180 if ((object)a
!= (object)b
)
186 public static int test_23005000_float () {
207 /// Gaussian blur of a generated grayscale picture
208 private int test_0_blur(int size) {
209 const int num = 5; // Number of time to blur
210 byte[,] arr1 = new byte[size, size];
211 byte[,] arr2 = new byte[size, size];
215 while(iterations-- > 0) {
218 for(int i = 0; i < size; i++) {
219 for(int j = 0; j < size; j++) {
220 arr1[i, j] = (byte) (i%255);
224 for(int n = 0; n < num; n++) { // num rounds of blurring
225 for(int i = 3; i < size-3; i++) // vertical blur arr1 -> arr2
226 for(int j = 0; j < size; j++)
227 arr2[i, j] = (byte)((arr1[i-3, j] + arr1[i+3, j]
228 + 6*(arr1[i-2, j]+arr1[i+2, j])
229 + 15*(arr1[i-1, j]+arr1[i+1, j])
230 + 20*arr1[i, j] + 32)>>6);
232 for(int j = 3; j < size-3; j++) // horizontal blur arr1 -> arr2
233 for(int i = 0; i < size; i++)
234 arr1[i, j] = (byte)((arr2[i, j-3] + arr2[i, j+3]
235 + 6*(arr2[i, j-2]+arr2[i, j+2])
236 + 15*(arr2[i, j-1]+arr2[i, j+1])
237 + 20*arr2[i, j] + 32)>>6);