[ppc] Fix passing of structure parameters as per the ELF ABI v2. Add 5 new test...
[mono.git] / mono / tests / pinvoke_ppcs.cs
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.
10 //
11 // Bill Seurer (seurer@linux.vnet.ibm.com)
12 //
13 // (C) {Copyright holder}
14 //
15
16 using System;
17 using System.Runtime.InteropServices;
18
19
20 public class Test_short {
21
22         [DllImport ("libtest", EntryPoint="mono_return_short1")]
23         public static extern short mono_return_short1 (short1 s, int addend);
24         [StructLayout(LayoutKind.Sequential)]
25         public struct short1 {
26                 public short f1;
27         }
28         [DllImport ("libtest", EntryPoint="mono_return_short2")]
29         public static extern short mono_return_short2 (short2 s, int addend);
30         [StructLayout(LayoutKind.Sequential)]
31         public struct short2 {
32                 public short f1,f2;
33         }
34         [DllImport ("libtest", EntryPoint="mono_return_short3")]
35         public static extern short mono_return_short3 (short3 s, int addend);
36         [StructLayout(LayoutKind.Sequential)]
37         public struct short3 {
38                 public short f1,f2,f3;
39         }
40         [DllImport ("libtest", EntryPoint="mono_return_short4")]
41         public static extern short mono_return_short4 (short4 s, int addend);
42         [StructLayout(LayoutKind.Sequential)]
43         public struct short4 {
44                 public short f1,f2,f3,f4;
45         }
46         [DllImport ("libtest", EntryPoint="mono_return_short5")]
47         public static extern short mono_return_short5 (short5 s, int addend);
48         [StructLayout(LayoutKind.Sequential)]
49         public struct short5 {
50                 public short f1,f2,f3,f4,f5;
51         }
52         [DllImport ("libtest", EntryPoint="mono_return_short6")]
53         public static extern short mono_return_short6 (short6 s, int addend);
54         [StructLayout(LayoutKind.Sequential)]
55         public struct short6 {
56                 public short f1,f2,f3,f4,f5,f6;
57         }
58         [DllImport ("libtest", EntryPoint="mono_return_short7")]
59         public static extern short 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;
63         }
64         [DllImport ("libtest", EntryPoint="mono_return_short8")]
65         public static extern short 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;
69         }
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 short 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;
77         }
78
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;
83         };
84         public struct short8_nested2 {
85                 public short f8;
86         };
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;
94         }
95
96         public static int Main (string[] args) {
97
98                 short1 s1;
99                 s1.f1 = 1;
100                 short retval1 = mono_return_short1(s1, 90);
101                 if (retval1 != 2*90) {
102                         Console.WriteLine("   short1 retval1: got {0} but expected {1}", retval1, 2*90);
103                         return 1;
104                 }
105
106                 short2 s2;
107                 s2.f1 = 1;
108                 s2.f2 = 2;
109                 short retval2 = mono_return_short2(s2, 90);
110                 if (retval2 != 2*90) {
111                         Console.WriteLine("   short2 retval2: got {0} but expected {1}", retval2, 2*90);
112                         return 1;
113                 }
114
115                 short3 s3;
116                 s3.f1 = 1;
117                 s3.f2 = 2;
118                 s3.f3 = 3;
119                 short retval3 = mono_return_short3(s3, 90);
120                 if (retval3 != 2*90) {
121                         Console.WriteLine("   short3 retval3: got {0} but expected {1}", retval3, 2*90);
122                         return 1;
123                 }
124
125                 short4 s4;
126                 s4.f1 = 1;
127                 s4.f2 = 2;
128                 s4.f3 = 3;
129                 s4.f4 = 4;
130                 short retval4 = mono_return_short4(s4, 90);
131                 if (retval4 != 2*90) {
132                         Console.WriteLine("   short4 retval4: got {0} but expected {1}", retval4, 2*90);
133                         return 1;
134                 }
135
136                 short5 s5;
137                 s5.f1 = 1;
138                 s5.f2 = 2;
139                 s5.f3 = 3;
140                 s5.f4 = 4;
141                 s5.f5 = 5;
142                 short retval5 = mono_return_short5(s5, 90);
143                 if (retval5 != 2*90) {
144                         Console.WriteLine("   short5 retval5: got {0} but expected {1}", retval5, 2*90);
145                         return 1;
146                 }
147
148                 short6 s6;
149                 s6.f1 = 1;
150                 s6.f2 = 2;
151                 s6.f3 = 3;
152                 s6.f4 = 4;
153                 s6.f5 = 5;
154                 s6.f6 = 6;
155                 short retval6 = mono_return_short6(s6, 90);
156                 if (retval6 != 2*90) {
157                         Console.WriteLine("   short6 retval6: got {0} but expected {1}", retval6, 2*90);
158                         return 1;
159                 }
160
161                 short7 s7;
162                 s7.f1 = 1;
163                 s7.f2 = 2;
164                 s7.f3 = 3;
165                 s7.f4 = 4;
166                 s7.f5 = 5;
167                 s7.f6 = 6;
168                 s7.f7 = 7;
169                 short retval7 = mono_return_short7(s7, 90);
170                 if (retval7 != 2*90) {
171                         Console.WriteLine("   short7 retval7: got {0} but expected {1}", retval7, 2*90);
172                         return 1;
173                 }
174
175                 short8 s8;
176                 s8.f1 = 1;
177                 s8.f2 = 2;
178                 s8.f3 = 3;
179                 s8.f4 = 4;
180                 s8.f5 = 5;
181                 s8.f6 = 6;
182                 s8.f7 = 7;
183                 s8.f8 = 8;
184                 short retval8 = mono_return_short8(s8, 90);
185                 if (retval8 != 2*90) {
186                         Console.WriteLine("   short8 retval8: got {0} but expected {1}", retval8, 2*90);
187                         return 1;
188                 }
189
190                 short9 s9;
191                 s9.f1 = 1;
192                 s9.f2 = 2;
193                 s9.f3 = 3;
194                 s9.f4 = 4;
195                 s9.f5 = 5;
196                 s9.f6 = 6;
197                 s9.f7 = 7;
198                 s9.f8 = 8;
199                 s9.f9 = 9;
200                 short retval9 = mono_return_short9(s9, 90);
201                 if (retval9 != 2*90) {
202                         Console.WriteLine("   short9 retval9: got {0} but expected {1}", retval9, 2*90);
203                         return 1;
204                 }
205
206
207                 return 0;
208         } // end Main
209 } // end class Test_short
210
211
212
213
214