2 using System
.Reflection
;
5 * Regression tests for the mono JIT.
7 * Each test needs to be of the form:
9 * public 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_0_sin_precision () {
40 double d1
= Math
.Sin (1);
41 double d2
= Math
.Sin (1) - d1
;
42 return (d2
== 0) ? 0 : 1;
45 public static int test_0_cos_precision () {
46 double d1
= Math
.Cos (1);
47 double d2
= Math
.Cos (1) - d1
;
48 return (d2
== 0) ? 0 : 1;
51 public static int test_0_tan_precision () {
52 double d1
= Math
.Tan (1);
53 double d2
= Math
.Tan (1) - d1
;
54 return (d2
== 0) ? 0 : 1;
57 public static int test_0_atan_precision () {
58 double d1
= Math
.Atan (double.NegativeInfinity
);
59 double d2
= Math
.Atan (double.NegativeInfinity
) - d1
;
60 return (d2
== 0) ? 0 : 1;
63 public static int test_0_sqrt_precision () {
64 double d1
= Math
.Sqrt (2);
65 double d2
= Math
.Sqrt (2) - d1
;
66 return (d2
== 0) ? 0 : 1;
69 public static int test_2_sqrt () {
70 return (int) Math
.Sqrt (4);
72 public static int test_0_sqrt_precision_and_not_spill () {
74 double[] operands
= new double[3];
75 double[] temporaries
= new double[3];
76 for (int i
= 0; i
< 3; i
++) {
77 operands
[i
] = (i
+1) * (i
+1) * (i
+1);
79 expected
= operands
[0];
81 temporaries
[i
] = operands
[i
] / expected
;
82 temporaries
[i
] = Math
.Sqrt (temporaries
[i
]);
83 expected
= temporaries
[i
];
86 //Console.Write( "{0}: {1}\n", i, temporaries [i] );
88 expected
= temporaries
[2];
90 double result
= Math
.Sqrt (operands
[2] / Math
.Sqrt (operands
[1] / operands
[0]));
92 //Console.Write( "result: {0,20:G}\n", result );
94 return (result
== expected
) ? 0 : 1;
97 public static int test_0_sqrt_precision_and_spill () {
99 double[] operands
= new double[9];
100 double[] temporaries
= new double[9];
101 for (int i
= 0; i
< 9; i
++) {
102 operands
[i
] = (i
+1) * (i
+1) * (i
+1);
104 expected
= operands
[0];
106 temporaries
[i
] = operands
[i
] / expected
;
107 temporaries
[i
] = Math
.Sqrt (temporaries
[i
]);
108 expected
= temporaries
[i
];
111 //Console.Write( "{0}: {1}\n", i, temporaries [i] );
113 expected
= temporaries
[8];
115 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]))))))));
117 //Console.Write( "result: {0,20:G}\n", result );
119 return (result
== expected
) ? 0 : 1;
122 public static int test_0_div_precision_and_spill () {
124 double[] operands
= new double[9];
125 double[] temporaries
= new double[9];
126 for (int i
= 0; i
< 9; i
++) {
127 operands
[i
] = (i
+1) * (i
+1);
129 expected
= operands
[0];
131 temporaries
[i
] = operands
[i
] / expected
;
132 expected
= temporaries
[i
];
135 //Console.Write( "{0}: {1}\n", i, temporaries [i] );
137 expected
= temporaries
[8];
139 double result
= (operands
[8] / (operands
[7] / (operands
[6] / (operands
[5] / (operands
[4] / (operands
[3] / (operands
[2] / (operands
[1] / operands
[0]))))))));
141 //Console.Write( "result: {0,20:G}\n", result );
143 return (result
== expected
) ? 0 : 1;
146 public static int test_0_sqrt_nan () {
147 return Double
.IsNaN (Math
.Sqrt (Double
.NaN
)) ? 0 : 1;
150 public static int test_0_sin_nan () {
151 return Double
.IsNaN (Math
.Sin (Double
.NaN
)) ? 0 : 1;
154 public static int test_0_cos_nan () {
155 return Double
.IsNaN (Math
.Cos (Double
.NaN
)) ? 0 : 1;
158 public static int test_0_tan_nan () {
159 return Double
.IsNaN (Math
.Tan (Double
.NaN
)) ? 0 : 1;
162 public static int test_0_atan_nan () {
163 return Double
.IsNaN (Math
.Atan (Double
.NaN
)) ? 0 : 1;
166 public static int test_0_min () {
167 if (Math
.Min (5, 6) != 5)
169 if (Math
.Min (6, 5) != 5)
171 if (Math
.Min (-100, -101) != -101)
173 if (Math
.Min ((long)5, (long)6) != 5)
175 if (Math
.Min ((long)6, (long)5) != 5)
177 if (Math
.Min ((long)-100, (long)-101) != -101)
182 public static int test_0_max () {
183 if (Math
.Max (5, 6) != 6)
185 if (Math
.Max (6, 5) != 6)
187 if (Math
.Max (-100, -101) != -100)
189 if (Math
.Max ((long)5, (long)6) != 6)
191 if (Math
.Max ((long)6, (long)5) != 6)
193 if (Math
.Max ((long)-100, (long)-101) != -100)
198 public static int test_0_min_un () {
199 uint a
= (uint)int.MaxValue
+ 10;
201 for (uint b
= 7; b
<= 10; ++b
) {
202 if (Math
.Min (a
, b
) != b
)
204 if (Math
.Min (b
, a
) != b
)
208 if (Math
.Min ((ulong)5, (ulong)6) != 5)
210 if (Math
.Min ((ulong)6, (ulong)5) != 5)
213 ulong la
= (ulong)long.MaxValue
+ 10;
215 for (ulong b
= 7; b
<= 10; ++b
) {
216 if (Math
.Min (la
, b
) != b
)
218 if (Math
.Min (b
, la
) != b
)
225 public static int test_0_max_un () {
226 uint a
= (uint)int.MaxValue
+ 10;
228 for (uint b
= 7; b
<= 10; ++b
) {
229 if (Math
.Max (a
, b
) != a
)
231 if (Math
.Max (b
, a
) != a
)
235 if (Math
.Max ((ulong)5, (ulong)6) != 6)
237 if (Math
.Max ((ulong)6, (ulong)5) != 6)
240 ulong la
= (ulong)long.MaxValue
+ 10;
242 for (ulong b
= 7; b
<= 10; ++b
) {
243 if (Math
.Max (la
, b
) != la
)
245 if (Math
.Max (b
, la
) != la
)
252 public static int test_0_abs () {
255 if (Math
.Abs (d
) != 5.0)
260 public static int test_0_round () {
261 if (Math
.Round (5.0) != 5.0)
264 if (Math
.Round (5.000000000000001) != 5.0)
267 if (Math
.Round (5.499999999999999) != 5.0)
270 if (Math
.Round (5.5) != 6.0)
273 if (Math
.Round (5.999999999999999) != 6.0)
276 if (Math
.Round (Double
.Epsilon
) != 0)
279 if (!Double
.IsNaN (Math
.Round (Double
.NaN
)))
282 if (!Double
.IsPositiveInfinity (Math
.Round (Double
.PositiveInfinity
)))
285 if (!Double
.IsNegativeInfinity (Math
.Round (Double
.NegativeInfinity
)))
288 if (Math
.Round (Double
.MinValue
) != Double
.MinValue
)
291 if (Math
.Round (Double
.MaxValue
) != Double
.MaxValue
)