1 // pinvoke_ppcd.cs - Test cases for passing structures to and and returning
2 // structures from functions. This particular test is for
3 // structures consisting wholy of 8 byte fields.
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.
17 using System
.Runtime
.InteropServices
;
20 public class Test_double
{
22 [DllImport ("libtest", EntryPoint
="mono_return_double1")]
23 public static extern double1
mono_return_double1 (double1 s
, int addend
);
24 [StructLayout(LayoutKind
.Sequential
)]
25 public struct double1
{
28 [DllImport ("libtest", EntryPoint
="mono_return_double2")]
29 public static extern double2
mono_return_double2 (double2 s
, int addend
);
30 [StructLayout(LayoutKind
.Sequential
)]
31 public struct double2
{
34 // This structure is 1 element too large to use the special return
36 [DllImport ("libtest", EntryPoint
="mono_return_double3")]
37 public static extern double3
mono_return_double3 (double3 s
, int addend
);
38 [StructLayout(LayoutKind
.Sequential
)]
39 public struct double3
{
40 public double f1
,f2
,f3
;
42 [DllImport ("libtest", EntryPoint
="mono_return_double4")]
43 public static extern double4
mono_return_double4 (double4 s
, int addend
);
44 [StructLayout(LayoutKind
.Sequential
)]
45 public struct double4
{
46 public double f1
,f2
,f3
,f4
;
48 [DllImport ("libtest", EntryPoint
="mono_return_double5")]
49 public static extern double5
mono_return_double5 (double5 s
, int addend
);
50 [StructLayout(LayoutKind
.Sequential
)]
51 public struct double5
{
52 public double f1
,f2
,f3
,f4
,f5
;
54 [DllImport ("libtest", EntryPoint
="mono_return_double6")]
55 public static extern double6
mono_return_double6 (double6 s
, int addend
);
56 [StructLayout(LayoutKind
.Sequential
)]
57 public struct double6
{
58 public double f1
,f2
,f3
,f4
,f5
,f6
;
60 [DllImport ("libtest", EntryPoint
="mono_return_double7")]
61 public static extern double7
mono_return_double7 (double7 s
, int addend
);
62 [StructLayout(LayoutKind
.Sequential
)]
63 public struct double7
{
64 public double f1
,f2
,f3
,f4
,f5
,f6
,f7
;
66 [DllImport ("libtest", EntryPoint
="mono_return_double8")]
67 public static extern double8
mono_return_double8 (double8 s
, int addend
);
68 [StructLayout(LayoutKind
.Sequential
)]
69 public struct double8
{
70 public double f1
,f2
,f3
,f4
,f5
,f6
,f7
,f8
;
72 // This structure is 1 element too large to use the special parameter
74 [DllImport ("libtest", EntryPoint
="mono_return_double9")]
75 public static extern double9
mono_return_double9 (double9 s
, int addend
);
76 [StructLayout(LayoutKind
.Sequential
)]
77 public struct double9
{
78 public double f1
,f2
,f3
,f4
,f5
,f6
,f7
,f8
,f9
;
81 // This structure has nested structures within it but they are
82 // homogenous and thus should still use the special rules.
83 public struct double2_nested1
{
86 public struct double2_nested2
{
89 [DllImport ("libtest", EntryPoint
="mono_return_double2_nested")]
90 public static extern double2_nested
mono_return_double2_nested (double2_nested s
, int addend
);
91 [StructLayout(LayoutKind
.Sequential
)]
92 public struct double2_nested
{
93 public double2_nested1 nested1
;
94 public double2_nested2 nested2
;
97 [DllImport ("libtest", EntryPoint
="mono_return_double_array4")]
98 public static extern double_array4
mono_return_double_array4 (double_array4 s
, int addend
);
99 [StructLayout(LayoutKind
.Sequential
)]
100 public unsafe struct double_array4
{
101 public fixed double f1
[4];
105 public static int Main (string[] args
) {
108 s1
= mono_return_double1(s1
, 9);
110 Console
.WriteLine(" double1 s1.f1: got {0} but expected {1}", s1
.f1
, 1+9);
117 s2
= mono_return_double2(s2
, 9);
119 Console
.WriteLine(" double2 s2.f1: got {0} but expected {1}", s2
.f1
, 1+9);
123 Console
.WriteLine(" double2 s2.f2: got {0} but expected {1}", s2
.f2
, 2+9);
131 s3
= mono_return_double3(s3
, 9);
133 Console
.WriteLine(" double3 s3.f1: got {0} but expected {1}", s3
.f1
, 1+9);
137 Console
.WriteLine(" double3 s3.f2: got {0} but expected {1}", s3
.f2
, 2+9);
141 Console
.WriteLine(" double3 s3.f3: got {0} but expected {1}", s3
.f3
, 3+9);
150 s4
= mono_return_double4(s4
, 9);
152 Console
.WriteLine(" double4 s4.f1: got {0} but expected {1}", s4
.f1
, 1+9);
156 Console
.WriteLine(" double4 s4.f2: got {0} but expected {1}", s4
.f2
, 2+9);
160 Console
.WriteLine(" double4 s4.f3: got {0} but expected {1}", s4
.f3
, 3+9);
164 Console
.WriteLine(" double4 s4.f4: got {0} but expected {1}", s4
.f4
, 4+9);
174 s5
= mono_return_double5(s5
, 9);
176 Console
.WriteLine(" double5 s5.f1: got {0} but expected {1}", s5
.f1
, 1+9);
180 Console
.WriteLine(" double5 s5.f2: got {0} but expected {1}", s5
.f2
, 2+9);
184 Console
.WriteLine(" double5 s5.f3: got {0} but expected {1}", s5
.f3
, 3+9);
188 Console
.WriteLine(" double5 s5.f4: got {0} but expected {1}", s5
.f4
, 4+9);
192 Console
.WriteLine(" double5 s5.f5: got {0} but expected {1}", s5
.f5
, 5+9);
203 s6
= mono_return_double6(s6
, 9);
205 Console
.WriteLine(" double6 s6.f1: got {0} but expected {1}", s6
.f1
, 1+9);
209 Console
.WriteLine(" double6 s6.f2: got {0} but expected {1}", s6
.f2
, 2+9);
213 Console
.WriteLine(" double6 s6.f3: got {0} but expected {1}", s6
.f3
, 3+9);
217 Console
.WriteLine(" double6 s6.f4: got {0} but expected {1}", s6
.f4
, 4+9);
221 Console
.WriteLine(" double6 s6.f5: got {0} but expected {1}", s6
.f5
, 5+9);
225 Console
.WriteLine(" double6 s6.f6: got {0} but expected {1}", s6
.f6
, 6+9);
237 s7
= mono_return_double7(s7
, 9);
239 Console
.WriteLine(" double7 s7.f1: got {0} but expected {1}", s7
.f1
, 1+9);
243 Console
.WriteLine(" double7 s7.f2: got {0} but expected {1}", s7
.f2
, 2+9);
247 Console
.WriteLine(" double7 s7.f3: got {0} but expected {1}", s7
.f3
, 3+9);
251 Console
.WriteLine(" double7 s7.f4: got {0} but expected {1}", s7
.f4
, 4+9);
255 Console
.WriteLine(" double7 s7.f5: got {0} but expected {1}", s7
.f5
, 5+9);
259 Console
.WriteLine(" double7 s7.f6: got {0} but expected {1}", s7
.f6
, 6+9);
263 Console
.WriteLine(" double7 s7.f7: got {0} but expected {1}", s7
.f7
, 7+9);
276 s8
= mono_return_double8(s8
, 9);
278 Console
.WriteLine(" double8 s8.f1: got {0} but expected {1}", s8
.f1
, 1+9);
282 Console
.WriteLine(" double8 s8.f2: got {0} but expected {1}", s8
.f2
, 2+9);
286 Console
.WriteLine(" double8 s8.f3: got {0} but expected {1}", s8
.f3
, 3+9);
290 Console
.WriteLine(" double8 s8.f4: got {0} but expected {1}", s8
.f4
, 4+9);
294 Console
.WriteLine(" double8 s8.f5: got {0} but expected {1}", s8
.f5
, 5+9);
298 Console
.WriteLine(" double8 s8.f6: got {0} but expected {1}", s8
.f6
, 6+9);
302 Console
.WriteLine(" double8 s8.f7: got {0} but expected {1}", s8
.f7
, 7+9);
306 Console
.WriteLine(" double8 s8.f8: got {0} but expected {1}", s8
.f8
, 8+9);
320 s9
= mono_return_double9(s9
, 9);
322 Console
.WriteLine(" double9 s9.f1: got {0} but expected {1}", s9
.f1
, 1+9);
326 Console
.WriteLine(" double9 s9.f2: got {0} but expected {1}", s9
.f2
, 2+9);
330 Console
.WriteLine(" double9 s9.f3: got {0} but expected {1}", s9
.f3
, 3+9);
334 Console
.WriteLine(" double9 s9.f4: got {0} but expected {1}", s9
.f4
, 4+9);
338 Console
.WriteLine(" double9 s9.f5: got {0} but expected {1}", s9
.f5
, 5+9);
342 Console
.WriteLine(" double9 s9.f6: got {0} but expected {1}", s9
.f6
, 6+9);
346 Console
.WriteLine(" double9 s9.f7: got {0} but expected {1}", s9
.f7
, 7+9);
350 Console
.WriteLine(" double9 s9.f8: got {0} but expected {1}", s9
.f8
, 8+9);
354 Console
.WriteLine(" double9 s9.f9: got {0} but expected {1}", s9
.f9
, 9+9);
362 sn2
= mono_return_double2_nested(sn2
, 9);
363 if (sn2
.nested1
.f1
!= 1+9) {
364 Console
.WriteLine(" double2_nested sn2.nested1.f1: got {0} but expected {1}", sn2
.nested1
.f1
, 1+9);
367 if (sn2
.nested2
.f2
!= 2+9) {
368 Console
.WriteLine(" double2_nested sn2.nested2.f2: got {0} but expected {1}", sn2
.nested2
.f2
, 2+9);
373 // NOTE: this test does not work properly because mini_type_is_hfa in mini-codegen.c does not handle arrays.
374 // Uncomment this when mini_type_is_hfa is fixed.
379 sa4 = mono_return_double_array4(sa4, 9);
380 if (sa4.f1[0] != 1+9) {
381 Console.WriteLine(" double_array4 sa4.f1[0]: got {0} but expected {1}", sa4.f1[0], 1+9);
384 if (sa4.f1[1] != 2+9) {
385 Console.WriteLine(" double_array4 sa4.f1[1]: got {0} but expected {1}", sa4.f1[1], 2+9);
388 if (sa4.f1[2] != 3+9) {
389 Console.WriteLine(" double_array4 sa4.f1[2]: got {0} but expected {1}", sa4.f1[2], 3+9);
392 if (sa4.f1[3] != 4+9) {
393 Console.WriteLine(" double_array4 sa4.f1[3]: got {0} but expected {1}", sa4.f1[3], 4+9);
401 } // end class Test_double