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 static int test_0_sin_precision () {
33 double d1 = Math.Sin (1);
34 double d2 = Math.Sin (1) - d1;
35 return (d2 == 0) ? 0 : 1;
38 static int test_0_cos_precision () {
39 double d1 = Math.Cos (1);
40 double d2 = Math.Cos (1) - d1;
41 return (d2 == 0) ? 0 : 1;
44 static int test_0_tan_precision () {
45 double d1 = Math.Tan (1);
46 double d2 = Math.Tan (1) - d1;
47 return (d2 == 0) ? 0 : 1;
50 static int test_0_atan_precision () {
51 double d1 = Math.Atan (double.NegativeInfinity);
52 double d2 = Math.Atan (double.NegativeInfinity) - d1;
53 return (d2 == 0) ? 0 : 1;
56 static int test_0_sqrt_precision () {
57 double d1 = Math.Sqrt (2);
58 double d2 = Math.Sqrt (2) - d1;
59 return (d2 == 0) ? 0 : 1;
62 static int test_2_sqrt () {
63 return (int) Math.Sqrt (4);
65 static int test_0_sqrt_precision_and_not_spill () {
67 double[] operands = new double[3];
68 double[] temporaries = new double[3];
69 for (int i = 0; i < 3; i++) {
70 operands [i] = (i+1) * (i+1) * (i+1);
72 expected = operands [0];
74 temporaries [i] = operands [i] / expected;
75 temporaries [i] = Math.Sqrt (temporaries [i]);
76 expected = temporaries [i];
79 //Console.Write( "{0}: {1}\n", i, temporaries [i] );
81 expected = temporaries [2];
83 double result = Math.Sqrt (operands [2] / Math.Sqrt (operands [1] / operands [0]));
85 //Console.Write( "result: {0,20:G}\n", result );
87 return (result == expected) ? 0 : 1;
90 static int test_0_sqrt_precision_and_spill () {
92 double[] operands = new double[9];
93 double[] temporaries = new double[9];
94 for (int i = 0; i < 9; i++) {
95 operands [i] = (i+1) * (i+1) * (i+1);
97 expected = operands [0];
99 temporaries [i] = operands [i] / expected;
100 temporaries [i] = Math.Sqrt (temporaries [i]);
101 expected = temporaries [i];
104 //Console.Write( "{0}: {1}\n", i, temporaries [i] );
106 expected = temporaries [8];
108 double result = Math.Sqrt (operands [8] / Math.Sqrt (operands [7] / Math.Sqrt (operands [6] / Math.Sqrt (operands [5] / Math.Sqrt (operands [4] / Math.Sqrt (operands [3] / Math.Sqrt (operands [2] / Math.Sqrt (operands [1] / operands [0]))))))));
110 //Console.Write( "result: {0,20:G}\n", result );
112 return (result == expected) ? 0 : 1;
115 static int test_0_div_precision_and_spill () {
117 double[] operands = new double[9];
118 double[] temporaries = new double[9];
119 for (int i = 0; i < 9; i++) {
120 operands [i] = (i+1) * (i+1);
122 expected = operands [0];
124 temporaries [i] = operands [i] / expected;
125 expected = temporaries [i];
128 //Console.Write( "{0}: {1}\n", i, temporaries [i] );
130 expected = temporaries [8];
132 double result = (operands [8] / (operands [7] / (operands [6] / (operands [5] / (operands [4] / (operands [3] / (operands [2] / (operands [1] / operands [0]))))))));
134 //Console.Write( "result: {0,20:G}\n", result );
136 return (result == expected) ? 0 : 1;
139 static int test_0_sqrt_nan () {
140 return Double.IsNaN (Math.Sqrt (Double.NaN)) ? 0 : 1;
143 static int test_0_sin_nan () {
144 return Double.IsNaN (Math.Sin (Double.NaN)) ? 0 : 1;
147 static int test_0_cos_nan () {
148 return Double.IsNaN (Math.Cos (Double.NaN)) ? 0 : 1;
151 static int test_0_tan_nan () {
152 return Double.IsNaN (Math.Tan (Double.NaN)) ? 0 : 1;
155 static int test_0_atan_nan () {
156 return Double.IsNaN (Math.Atan (Double.NaN)) ? 0 : 1;