[runtime] Accomplish BITCODE build symbol sharing with only make (#3329)
[mono-project.git] / mono / tests / pinvoke_ppcs.cs
blob08ad1d6eccd40994ab972de400b48d6f8d0b5d10
1 // pinvoke_ppcs.cs - Test cases for passing structures to and and returning
2 // structures from functions. This particular test is for
3 // structures consisting wholy of 2 byte fields.
4 //
5 // The Power ABI version 2 allows for special parameter
6 // passing and returning optimizations for certain
7 // structures of homogenous composition (like all ints).
8 // This set of tests checks all the possible combinations
9 // that use the special parm/return rules and one beyond.
11 // Bill Seurer (seurer@linux.vnet.ibm.com)
13 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
16 using System;
17 using System.Runtime.InteropServices;
20 public class Test_short {
22 [DllImport ("libtest", EntryPoint="mono_return_short1")]
23 public static extern short1 mono_return_short1 (short1 s, int addend);
24 [StructLayout(LayoutKind.Sequential)]
25 public struct short1 {
26 public short f1;
28 [DllImport ("libtest", EntryPoint="mono_return_short2")]
29 public static extern short2 mono_return_short2 (short2 s, int addend);
30 [StructLayout(LayoutKind.Sequential)]
31 public struct short2 {
32 public short f1,f2;
34 [DllImport ("libtest", EntryPoint="mono_return_short3")]
35 public static extern short3 mono_return_short3 (short3 s, int addend);
36 [StructLayout(LayoutKind.Sequential)]
37 public struct short3 {
38 public short f1,f2,f3;
40 [DllImport ("libtest", EntryPoint="mono_return_short4")]
41 public static extern short4 mono_return_short4 (short4 s, int addend);
42 [StructLayout(LayoutKind.Sequential)]
43 public struct short4 {
44 public short f1,f2,f3,f4;
46 [DllImport ("libtest", EntryPoint="mono_return_short5")]
47 public static extern short5 mono_return_short5 (short5 s, int addend);
48 [StructLayout(LayoutKind.Sequential)]
49 public struct short5 {
50 public short f1,f2,f3,f4,f5;
52 [DllImport ("libtest", EntryPoint="mono_return_short6")]
53 public static extern short6 mono_return_short6 (short6 s, int addend);
54 [StructLayout(LayoutKind.Sequential)]
55 public struct short6 {
56 public short f1,f2,f3,f4,f5,f6;
58 [DllImport ("libtest", EntryPoint="mono_return_short7")]
59 public static extern short7 mono_return_short7 (short7 s, int addend);
60 [StructLayout(LayoutKind.Sequential)]
61 public struct short7 {
62 public short f1,f2,f3,f4,f5,f6,f7;
64 [DllImport ("libtest", EntryPoint="mono_return_short8")]
65 public static extern short8 mono_return_short8 (short8 s, int addend);
66 [StructLayout(LayoutKind.Sequential)]
67 public struct short8 {
68 public short f1,f2,f3,f4,f5,f6,f7,f8;
70 // This structure is 1 element too large to use the special return
71 // rules.
72 [DllImport ("libtest", EntryPoint="mono_return_short9")]
73 public static extern short9 mono_return_short9 (short9 s, int addend);
74 [StructLayout(LayoutKind.Sequential)]
75 public struct short9 {
76 public short f1,f2,f3,f4,f5,f6,f7,f8,f9;
79 // This structure has nested structures within it but they are
80 // homogenous and thus should still use the special rules.
81 public struct short8_nested1 {
82 public short f1;
84 public struct short8_nested2 {
85 public short f8;
87 [DllImport ("libtest", EntryPoint="mono_return_short8_nested")]
88 public static extern short8_nested mono_return_short8_nested (short8_nested s, int addend);
89 [StructLayout(LayoutKind.Sequential)]
90 public struct short8_nested {
91 public short8_nested1 nested1;
92 public short f2,f3,f4,f5,f6,f7;
93 public short8_nested2 nested2;
96 public static int Main (string[] args) {
98 short1 s1;
99 s1.f1 = 1;
100 s1 = mono_return_short1(s1, 90);
101 if (s1.f1 != 1+90) {
102 Console.WriteLine(" short1 s1.f1: got {0} but expected {1}", s1.f1, 1+90);
103 return 1;
106 short2 s2;
107 s2.f1 = 1;
108 s2.f2 = 2;
109 s2 = mono_return_short2(s2, 90);
110 if (s2.f1 != 1+90) {
111 Console.WriteLine(" short2 s2.f1: got {0} but expected {1}", s2.f1, 1+90);
112 return 1;
114 if (s2.f2 != 2+90) {
115 Console.WriteLine(" short2 s2.f2: got {0} but expected {1}", s2.f2, 2+90);
116 return 2;
119 short3 s3;
120 s3.f1 = 1;
121 s3.f2 = 2;
122 s3.f3 = 3;
123 s3 = mono_return_short3(s3, 90);
124 if (s3.f1 != 1+90) {
125 Console.WriteLine(" short3 s3.f1: got {0} but expected {1}", s3.f1, 1+90);
126 return 1;
128 if (s3.f2 != 2+90) {
129 Console.WriteLine(" short3 s3.f2: got {0} but expected {1}", s3.f2, 2+90);
130 return 2;
132 if (s3.f3 != 3+90) {
133 Console.WriteLine(" short3 s3.f3: got {0} but expected {1}", s3.f3, 3+90);
134 return 3;
137 short4 s4;
138 s4.f1 = 1;
139 s4.f2 = 2;
140 s4.f3 = 3;
141 s4.f4 = 4;
142 s4 = mono_return_short4(s4, 90);
143 if (s4.f1 != 1+90) {
144 Console.WriteLine(" short4 s4.f1: got {0} but expected {1}", s4.f1, 1+90);
145 return 1;
147 if (s4.f2 != 2+90) {
148 Console.WriteLine(" short4 s4.f2: got {0} but expected {1}", s4.f2, 2+90);
149 return 2;
151 if (s4.f3 != 3+90) {
152 Console.WriteLine(" short4 s4.f3: got {0} but expected {1}", s4.f3, 3+90);
153 return 3;
155 if (s4.f4 != 4+90) {
156 Console.WriteLine(" short4 s4.f4: got {0} but expected {1}", s4.f4, 4+90);
157 return 4;
160 short5 s5;
161 s5.f1 = 1;
162 s5.f2 = 2;
163 s5.f3 = 3;
164 s5.f4 = 4;
165 s5.f5 = 5;
166 s5 = mono_return_short5(s5, 90);
167 if (s5.f1 != 1+90) {
168 Console.WriteLine(" short5 s5.f1: got {0} but expected {1}", s5.f1, 1+90);
169 return 1;
171 if (s5.f2 != 2+90) {
172 Console.WriteLine(" short5 s5.f2: got {0} but expected {1}", s5.f2, 2+90);
173 return 2;
175 if (s5.f3 != 3+90) {
176 Console.WriteLine(" short5 s5.f3: got {0} but expected {1}", s5.f3, 3+90);
177 return 3;
179 if (s5.f4 != 4+90) {
180 Console.WriteLine(" short5 s5.f4: got {0} but expected {1}", s5.f4, 4+90);
181 return 4;
183 if (s5.f5 != 5+90) {
184 Console.WriteLine(" short5 s5.f5: got {0} but expected {1}", s5.f5, 5+90);
185 return 5;
188 short6 s6;
189 s6.f1 = 1;
190 s6.f2 = 2;
191 s6.f3 = 3;
192 s6.f4 = 4;
193 s6.f5 = 5;
194 s6.f6 = 6;
195 s6 = mono_return_short6(s6, 90);
196 if (s6.f1 != 1+90) {
197 Console.WriteLine(" short6 s6.f1: got {0} but expected {1}", s6.f1, 1+90);
198 return 1;
200 if (s6.f2 != 2+90) {
201 Console.WriteLine(" short6 s6.f2: got {0} but expected {1}", s6.f2, 2+90);
202 return 2;
204 if (s6.f3 != 3+90) {
205 Console.WriteLine(" short6 s6.f3: got {0} but expected {1}", s6.f3, 3+90);
206 return 3;
208 if (s6.f4 != 4+90) {
209 Console.WriteLine(" short6 s6.f4: got {0} but expected {1}", s6.f4, 4+90);
210 return 4;
212 if (s6.f5 != 5+90) {
213 Console.WriteLine(" short6 s6.f5: got {0} but expected {1}", s6.f5, 5+90);
214 return 5;
216 if (s6.f6 != 6+90) {
217 Console.WriteLine(" short6 s6.f6: got {0} but expected {1}", s6.f6, 6+90);
218 return 6;
221 short7 s7;
222 s7.f1 = 1;
223 s7.f2 = 2;
224 s7.f3 = 3;
225 s7.f4 = 4;
226 s7.f5 = 5;
227 s7.f6 = 6;
228 s7.f7 = 7;
229 s7 = mono_return_short7(s7, 90);
230 if (s7.f1 != 1+90) {
231 Console.WriteLine(" short7 s7.f1: got {0} but expected {1}", s7.f1, 1+90);
232 return 1;
234 if (s7.f2 != 2+90) {
235 Console.WriteLine(" short7 s7.f2: got {0} but expected {1}", s7.f2, 2+90);
236 return 2;
238 if (s7.f3 != 3+90) {
239 Console.WriteLine(" short7 s7.f3: got {0} but expected {1}", s7.f3, 3+90);
240 return 3;
242 if (s7.f4 != 4+90) {
243 Console.WriteLine(" short7 s7.f4: got {0} but expected {1}", s7.f4, 4+90);
244 return 4;
246 if (s7.f5 != 5+90) {
247 Console.WriteLine(" short7 s7.f5: got {0} but expected {1}", s7.f5, 5+90);
248 return 5;
250 if (s7.f6 != 6+90) {
251 Console.WriteLine(" short7 s7.f6: got {0} but expected {1}", s7.f6, 6+90);
252 return 6;
254 if (s7.f7 != 7+90) {
255 Console.WriteLine(" short7 s7.f7: got {0} but expected {1}", s7.f7, 7+90);
256 return 7;
259 short8 s8;
260 s8.f1 = 1;
261 s8.f2 = 2;
262 s8.f3 = 3;
263 s8.f4 = 4;
264 s8.f5 = 5;
265 s8.f6 = 6;
266 s8.f7 = 7;
267 s8.f8 = 8;
268 s8 = mono_return_short8(s8, 90);
269 if (s8.f1 != 1+90) {
270 Console.WriteLine(" short8 s8.f1: got {0} but expected {1}", s8.f1, 1+90);
271 return 1;
273 if (s8.f2 != 2+90) {
274 Console.WriteLine(" short8 s8.f2: got {0} but expected {1}", s8.f2, 2+90);
275 return 2;
277 if (s8.f3 != 3+90) {
278 Console.WriteLine(" short8 s8.f3: got {0} but expected {1}", s8.f3, 3+90);
279 return 3;
281 if (s8.f4 != 4+90) {
282 Console.WriteLine(" short8 s8.f4: got {0} but expected {1}", s8.f4, 4+90);
283 return 4;
285 if (s8.f5 != 5+90) {
286 Console.WriteLine(" short8 s8.f5: got {0} but expected {1}", s8.f5, 5+90);
287 return 5;
289 if (s8.f6 != 6+90) {
290 Console.WriteLine(" short8 s8.f6: got {0} but expected {1}", s8.f6, 6+90);
291 return 6;
293 if (s8.f7 != 7+90) {
294 Console.WriteLine(" short8 s8.f7: got {0} but expected {1}", s8.f7, 7+90);
295 return 7;
297 if (s8.f8 != 8+90) {
298 Console.WriteLine(" short8 s8.f8: got {0} but expected {1}", s8.f8, 8+90);
299 return 8;
302 short9 s9;
303 s9.f1 = 1;
304 s9.f2 = 2;
305 s9.f3 = 3;
306 s9.f4 = 4;
307 s9.f5 = 5;
308 s9.f6 = 6;
309 s9.f7 = 7;
310 s9.f8 = 8;
311 s9.f9 = 9;
312 s9 = mono_return_short9(s9, 90);
313 if (s9.f1 != 1+90) {
314 Console.WriteLine(" short9 s9.f1: got {0} but expected {1}", s9.f1, 1+90);
315 return 1;
317 if (s9.f2 != 2+90) {
318 Console.WriteLine(" short9 s9.f2: got {0} but expected {1}", s9.f2, 2+90);
319 return 2;
321 if (s9.f3 != 3+90) {
322 Console.WriteLine(" short9 s9.f3: got {0} but expected {1}", s9.f3, 3+90);
323 return 3;
325 if (s9.f4 != 4+90) {
326 Console.WriteLine(" short9 s9.f4: got {0} but expected {1}", s9.f4, 4+90);
327 return 4;
329 if (s9.f5 != 5+90) {
330 Console.WriteLine(" short9 s9.f5: got {0} but expected {1}", s9.f5, 5+90);
331 return 5;
333 if (s9.f6 != 6+90) {
334 Console.WriteLine(" short9 s9.f6: got {0} but expected {1}", s9.f6, 6+90);
335 return 6;
337 if (s9.f7 != 7+90) {
338 Console.WriteLine(" short9 s9.f7: got {0} but expected {1}", s9.f7, 7+90);
339 return 7;
341 if (s9.f8 != 8+90) {
342 Console.WriteLine(" short9 s9.f8: got {0} but expected {1}", s9.f8, 8+90);
343 return 8;
345 if (s9.f9 != 9+90) {
346 Console.WriteLine(" short9 s9.f9: got {0} but expected {1}", s9.f9, 9+90);
347 return 9;
351 short8_nested sn8;
352 sn8.nested1.f1 = 1;
353 sn8.f2 = 2;
354 sn8.f3 = 3;
355 sn8.f4 = 4;
356 sn8.f5 = 5;
357 sn8.f6 = 6;
358 sn8.f7 = 7;
359 sn8.nested2.f8 = 8;
360 sn8 = mono_return_short8_nested(sn8, 90);
361 if (sn8.nested1.f1 != 1+90) {
362 Console.WriteLine(" short8_nested sn8.nested1.f1: got {0} but expected {1}", sn8.nested1.f1, 1+90);
363 return 1;
365 if (sn8.f2 != 2+90) {
366 Console.WriteLine(" short8_nested sn8.f2: got {0} but expected {1}", sn8.f2, 2+90);
367 return 2;
369 if (sn8.f3 != 3+90) {
370 Console.WriteLine(" short8_nested sn8.f3: got {0} but expected {1}", sn8.f3, 3+90);
371 return 3;
373 if (sn8.f4 != 4+90) {
374 Console.WriteLine(" short8_nested sn8.f4: got {0} but expected {1}", sn8.f4, 4+90);
375 return 4;
377 if (sn8.f5 != 5+90) {
378 Console.WriteLine(" short8_nested sn8.f5: got {0} but expected {1}", sn8.f5, 5+90);
379 return 5;
381 if (sn8.f6 != 6+90) {
382 Console.WriteLine(" short8_nested sn8.f6: got {0} but expected {1}", sn8.f6, 6+90);
383 return 6;
385 if (sn8.f7 != 7+90) {
386 Console.WriteLine(" short8_nested sn8.f7: got {0} but expected {1}", sn8.f7, 7+90);
387 return 7;
389 if (sn8.nested2.f8 != 8+90) {
390 Console.WriteLine(" short8_nested sn8.nested2.f8: got {0} but expected {1}", sn8.nested2.f8, 8+90);
391 return 8;
394 return 0;
395 } // end Main
396 } // end class Test_short