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
26 delegate int IntNoArgs();
30 public virtual int method1 () {
34 public virtual int method2 () {
38 public virtual int method3 () {
42 public virtual int method4 () {
46 public virtual int method5 () {
52 public class Middle
: Base
{
53 public override int method2 () {
57 public override int method4 () {
61 public override sealed int method5 () {
67 public class OpenFinal
: Middle
{
68 public override sealed int method4 () {
72 static public int staticMethod() {
78 sealed public class SealedFinal
: Middle
{
79 public override int method1 () {
83 static public int staticMethod() {
89 class DevirtualizationTests
{
92 static int Main (string[] args
) {
93 return TestDriver
.RunTests (typeof (DevirtualizationTests
), args
);
97 static public int test_0_sealed_class_devirt_right_method () {
98 SealedFinal x
= new SealedFinal ();
99 if (x
.method1 () != 4)
101 if (x
.method2 () != 2)
103 if (x
.method3 () != 1)
108 static public int test_0_sealed_method_devirt_right_method () {
109 OpenFinal x
= new OpenFinal ();
110 if (x
.method4 () != 3)
112 if (x
.method5 () != 2)
117 static public int test_0_sealed_class_devirt_right_method_using_delegates () {
118 SealedFinal x
= new SealedFinal ();
119 IntNoArgs d1
= new IntNoArgs(x
.method1
);
120 IntNoArgs d2
= new IntNoArgs(x
.method2
);
121 IntNoArgs d3
= new IntNoArgs(x
.method3
);
132 static public int test_0_sealed_method_devirt_right_method_using_delegates () {
133 OpenFinal x
= new OpenFinal ();
134 IntNoArgs d1
= new IntNoArgs(x
.method4
);
135 IntNoArgs d2
= new IntNoArgs(x
.method5
);
145 static public int test_0_delegate_over_static_method_devirtualize_ok () {
146 IntNoArgs d1
= new IntNoArgs(OpenFinal
.staticMethod
);
147 IntNoArgs d2
= new IntNoArgs(SealedFinal
.staticMethod
);
157 static public int test_0_npe_still_happens() {
159 SealedFinal y
= null;
164 } catch(NullReferenceException e
) {
171 } catch(NullReferenceException e
) {
178 } catch(NullReferenceException e
) {
185 } catch(NullReferenceException e
) {
192 } catch(NullReferenceException e
) {