Merge pull request #4621 from alexanderkyte/strdup_env
[mono.git] / mono / mini / mixed.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Reflection;
4 using System.Runtime.InteropServices;
5 using System.Runtime.CompilerServices;
6
7 /*
8  * Regression tests for the mixed-mode execution.
9  * Run with --interp=jit=JitClass
10  */
11
12 struct AStruct {
13         public int i;
14 }
15
16 struct GStruct<T> {
17         public int i;
18 }
19
20 class InterpClass
21 {
22         [MethodImplAttribute (MethodImplOptions.NoInlining)]
23         public static void entry_void_0 () {
24         }
25
26         [MethodImplAttribute (MethodImplOptions.NoInlining)]
27         public static int entry_int_int (int i) {
28                 return i + 1;
29         }
30
31         [MethodImplAttribute (MethodImplOptions.NoInlining)]
32         public int entry_int_this_int (int i) {
33                 return i + 1;
34         }
35
36         [MethodImplAttribute (MethodImplOptions.NoInlining)]
37         public static string entry_string_string (string s1, string s2) {
38                 return s1 + s2;
39         }
40
41         [MethodImplAttribute (MethodImplOptions.NoInlining)]
42         public static AStruct entry_struct_struct (AStruct l) {
43                 return l;
44         }
45
46         [MethodImplAttribute (MethodImplOptions.NoInlining)]
47         public static List<string> entry_ginst_ginst (List<string> l) {
48                 return l;
49         }
50
51         [MethodImplAttribute (MethodImplOptions.NoInlining)]
52         public static GStruct<string> entry_ginst_ginst_vtype (GStruct<string> l) {
53                 return l;
54         }
55
56         [MethodImplAttribute (MethodImplOptions.NoInlining)]
57         public static void entry_void_byref_int (ref int i) {
58                 i = i + 1;
59         }
60
61         [MethodImplAttribute (MethodImplOptions.NoInlining)]
62         public static int entry_8_int_args (int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8) {
63                 return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8;
64         }
65
66         [MethodImplAttribute (MethodImplOptions.NoInlining)]
67         public static int entry_9_int_args (int i1, int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9) {
68                 return i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8 + i9;
69         }
70
71         [MethodImplAttribute (MethodImplOptions.NoInlining)]
72         public static IntPtr entry_intptr_intptr (IntPtr i) {
73                 return i;
74         }
75
76 }
77
78 /* The methods in this class will always be JITted */
79 class JitClass
80 {
81         [MethodImplAttribute (MethodImplOptions.NoInlining)]
82         public static int entry () {
83                 InterpClass.entry_void_0 ();
84                 InterpClass.entry_void_0 ();
85                 int res = InterpClass.entry_int_int (1);
86                 if (res != 2)
87                         return 1;
88                 var c = new InterpClass ();
89                 res = c.entry_int_this_int (1);
90                 if (res != 2)
91                         return 2;
92                 var s = InterpClass.entry_string_string ("A", "B");
93                 if (s != "AB")
94                         return 3;
95                 var astruct = new AStruct () { i = 1 };
96                 var astruct2 = InterpClass.entry_struct_struct (astruct);
97                 if (astruct2.i != 1)
98                         return 4;
99                 var l = new List<string> ();
100                 var l2 = InterpClass.entry_ginst_ginst (l);
101                 if (l != l2)
102                         return 5;
103                 var gstruct = new GStruct<string> () { i = 1 };
104                 var gstruct2 = InterpClass.entry_ginst_ginst_vtype (gstruct);
105                 if (gstruct2.i != 1)
106                         return 6;
107                 int val = 1;
108                 InterpClass.entry_void_byref_int (ref val);
109                 if (val != 2)
110                         return 7;
111                 res = InterpClass.entry_8_int_args (1, 2, 3, 4, 5, 6, 7, 8);
112                 if (res != 36)
113                         return 8;
114                 res = InterpClass.entry_9_int_args (1, 2, 3, 4, 5, 6, 7, 8, 9);
115                 if (res != 45)
116                         return 9;
117                 var ptr = new IntPtr (32);
118                 var ptr2 = InterpClass.entry_intptr_intptr (ptr);
119                 if (ptr != ptr2)
120                         return 10;
121                 return 0;
122         }
123
124         [MethodImplAttribute (MethodImplOptions.NoInlining)]
125         public static AStruct exit_vtype (AStruct s) {
126                 return s;
127         }
128
129         [MethodImplAttribute (MethodImplOptions.NoInlining)]
130         public static List<string> exit_ginst (List<string> l) {
131                 return l;
132         }
133
134         [MethodImplAttribute (MethodImplOptions.NoInlining)]
135         public static GStruct<string> exit_ginst_vtype (GStruct<string> l) {
136                 return l;
137         }
138
139         [MethodImplAttribute (MethodImplOptions.NoInlining)]
140         public static void exit_byref (ref int i) {
141                 i += 1;
142         }
143 }
144
145 #if __MOBILE__
146 class MixedTests
147 #else
148 class Tests
149 #endif
150 {
151
152 #if !__MOBILE__
153         public static int Main (string[] args) {
154                 return TestDriver.RunTests (typeof (Tests), args);
155         }
156 #endif
157
158         public static int test_0_entry () {
159                 // This does an interp->jit transition
160                 return JitClass.entry ();
161         }
162
163         public static int test_0_exit () {
164                 var astruct = new AStruct () { i = 1};
165                 var astruct2 = JitClass.exit_vtype (astruct);
166                 if (astruct2.i != 1)
167                         return 1;
168                 var ginst = new List<string> ();
169                 var ginst2 = JitClass.exit_ginst (ginst);
170                 if (ginst != ginst2)
171                         return 2;
172                 var gstruct = new GStruct<string> () { i = 1 };
173                 var gstruct2 = JitClass.exit_ginst_vtype (gstruct);
174                 if (gstruct2.i != 1)
175                         return 3;
176                 var anint = 1;
177                 JitClass.exit_byref (ref anint);
178                 if (anint != 2)
179                         return 4;
180                 return 0;
181         }
182 }