Debian Codegraph @

libgomp/testsuite/libgomp.c-c++-common/interop-routines-1.c

raw
1 /* { dg-do run } */
2
3 #include <assert.h>
4 #include <stddef.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <omp.h>
8
9 int
10 main ()
11 {
12 omp_interop_t interop = omp_interop_none;
13
14 assert (omp_irc_no_value == 1);
15 assert (omp_irc_success == 0);
16 assert (omp_irc_empty == -1);
17 assert (omp_irc_out_of_range == -2);
18 assert (omp_irc_type_int == -3);
19 assert (omp_irc_type_ptr == -4);
20 assert (omp_irc_type_str == -5);
21 assert (omp_irc_other == -6);
22
23 /* Check values, including invalid values. */
24 for (omp_interop_rc_t ret_code3 = (omp_interop_rc_t)((int)omp_irc_other-1);
25 ret_code3 <= omp_irc_no_value + 1;
26 ret_code3 = (omp_interop_rc_t)((int)ret_code3 + 1))
27 {
28 const char *msg = omp_get_interop_rc_desc (interop, ret_code3);
29 if (ret_code3 < omp_irc_other || ret_code3 > omp_irc_no_value)
30 /* Assume NULL for an invalid value. */
31 assert (msg == NULL);
32 else if (ret_code3 == omp_irc_other)
33 /* Likely not to exist in an implementation; esp. not for
34 omp_interop_none. Thus, expect NULL. */
35 /* In GCC, it is used on the device side, only, to complain about
36 omp_get_interop_{int,ptr,str} usage. */
37 assert (msg == NULL);
38 else
39 /* Assume that omp_get_interop_rc_desc handles all of those and
40 not only omp_irc_empty (and possibly omp_irc_out_of_range),
41 which do occur for omp_interop_none. */
42 assert (msg != NULL && strlen (msg) > 5); /* Some sensible message. */
43 }
44
45 assert (omp_ifr_last >= omp_ifr_hsa);
46
47 for (omp_interop_fr_t fr = omp_ifr_cuda;
48 fr <= omp_ifr_last;
49 fr = (omp_interop_fr_t)((int)fr +1))
50 {
51 switch (fr)
52 {
53 /* Expect the id values from the additional-definition document. */
54 case omp_ifr_cuda:
55 if (fr != 1)
56 abort ();
57 break;
58 case omp_ifr_cuda_driver:
59 if (fr != 2)
60 abort ();
61 break;
62 case omp_ifr_opencl:
63 if (fr != 3)
64 abort ();
65 break;
66 case omp_ifr_sycl:
67 if (fr != 4)
68 abort ();
69 break;
70 case omp_ifr_hip:
71 if (fr != 5)
72 abort ();
73 break;
74 case omp_ifr_level_zero:
75 if (fr != 6)
76 abort ();
77 break;
78 case omp_ifr_hsa:
79 if (fr != 7)
80 abort ();
81 break;
82 default:
83 /* Valid, but unexpected to have more interop types. */
84 abort ();
85 }
86 }
87
88 assert (omp_ipr_first <= omp_ipr_targetsync
89 && omp_get_num_interop_properties (interop) > omp_ipr_fr_id);
90
91 for (omp_interop_property_t ipr = omp_ipr_first;
92 ipr < omp_get_num_interop_properties (interop);
93 ipr = (omp_interop_property_t) ((int) ipr + 1))
94 {
95 /* As interop == omp_interop_none, NULL is permissible;
96 nonetheless, require != NULL for the GCC implementation. */
97 const char *name = omp_get_interop_name (interop, ipr);
98 if (name == NULL)
99 abort ();
100 switch (ipr)
101 {
102 case omp_ipr_fr_id:
103 if (ipr != -1 || !!strcmp (name, "fr_id"))
104 abort ();
105 break;
106 case omp_ipr_fr_name:
107 if (ipr != -2 || !!strcmp (name, "fr_name"))
108 abort ();
109 break;
110 case omp_ipr_vendor:
111 if (ipr != -3 || !!strcmp (name, "vendor"))
112 abort ();
113 break;
114 case omp_ipr_vendor_name:
115 if (ipr != -4 || !!strcmp (name, "vendor_name"))
116 abort ();
117 break;
118 case omp_ipr_device_num:
119 if (ipr != -5 || !!strcmp (name, "device_num"))
120 abort ();
121 break;
122 case omp_ipr_platform:
123 if (ipr != -6 || !!strcmp (name, "platform"))
124 abort ();
125 break;
126 case omp_ipr_device:
127 if (ipr != -7 || !!strcmp (name, "device"))
128 abort ();
129 break;
130 case omp_ipr_device_context:
131 if (ipr != -8 || !!strcmp (name, "device_context"))
132 abort ();
133 break;
134 case omp_ipr_targetsync:
135 if (ipr != -9 || !!strcmp (name, "targetsync"))
136 abort ();
137 break;
138 default:
139 /* Valid, but unexpected to have more interop types,
140 especially not for interop == omp_interop_none. */
141 abort ();
142 }
143
144 /* As interop == omp_interop_none, expect NULL. */
145 if (omp_get_interop_type_desc (interop, ipr) != NULL)
146 abort ();
147
148 omp_interop_rc_t ret_code;
149 const char *err;
150
151 ret_code = omp_irc_success;
152 omp_intptr_t ival = omp_get_interop_int (interop, ipr, &ret_code);
153 assert (ret_code == omp_irc_empty); /* As interop == omp_interop_none. */
154 assert (ival == 0); /* Implementation choice. */
155 err = omp_get_interop_rc_desc (interop, ret_code);
156 assert (err != NULL && strlen (err) > 5); /* Some sensible message. */
157 assert (!strcmp (err, "provided interoperability object is equal to "
158 "omp_interop_none")); /* GCC implementation choice. */
159 omp_intptr_t ival4 = omp_get_interop_int (interop, ipr, NULL);
160 assert(ival4 == ival);
161
162 ret_code = omp_irc_success;
163 void *ptr = omp_get_interop_ptr (interop, ipr, &ret_code);
164 assert (ret_code == omp_irc_empty); /* As interop == omp_interop_none. */
165 assert (ptr == NULL); /* Obvious implementation choice. */
166 err = omp_get_interop_rc_desc (interop, ret_code);
167 assert (err != NULL && strlen (err) > 5); /* Some sensible message. */
168 assert (!strcmp (err, "provided interoperability object is equal to "
169 "omp_interop_none")); /* GCC implementation choice. */
170 void *ptr4 = omp_get_interop_ptr (interop, ipr, NULL);
171 assert (ptr4 == ptr);
172
173 ret_code = omp_irc_success;
174 const char *str = omp_get_interop_str (interop, ipr, &ret_code);
175 assert (ret_code == omp_irc_empty); /* As interop == omp_interop_none. */
176 assert (str == NULL); /* Obvious implementation choice. */
177 err = omp_get_interop_rc_desc (interop, ret_code);
178 assert (err != NULL && strlen (err) > 5); /* Some sensible message. */
179 assert (!strcmp (err, "provided interoperability object is equal to "
180 "omp_interop_none")); /* GCC implementation choice. */
181 const char *str4 = omp_get_interop_str (interop, ipr, NULL);
182 assert (str4 == str);
183 }
184
185 /* Invalid ipr. */
186 /* Valid are either omp_irc_empty (due to omp_interop_none) or
187 omp_irc_out_of_range; assume omp_irc_out_of_range with GCC. */
188
189 omp_interop_rc_t ret_code2;
190 const char *err2;
191 omp_intptr_t ival2;
192 void *ptr2;
193 const char *str2;
194
195 /* omp_ipr_targetsync-1, i.e < lower bound. */
196
197 ret_code2 = omp_irc_success;
198 ival2 = omp_get_interop_int (interop,
199 (omp_interop_property_t) ((int) omp_ipr_targetsync-1), &ret_code2);
200 assert (ret_code2 == omp_irc_out_of_range);
201 assert (ival2 == 0); /* Implementation choice. */
202 err2 = omp_get_interop_rc_desc (interop, ret_code2);
203 assert (err2 != NULL && strlen (err2) > 5); /* Some sensible message. */
204 /* GCC implementation choice. */
205 assert (!strcmp (err2, "property ID is out of range"));
206 omp_intptr_t ival5 = omp_get_interop_int (interop,
207 (omp_interop_property_t) ((int) omp_ipr_targetsync-1), NULL);
208 assert (ival5 == ival2);
209 #ifdef __cplusplus
210 ival5 = omp_get_interop_int (interop,
211 (omp_interop_property_t) ((int) omp_ipr_targetsync-1));
212 assert (ival5 == ival2);
213 #endif
214
215 ret_code2 = omp_irc_success;
216 ptr2 = omp_get_interop_ptr (interop,
217 (omp_interop_property_t) ((int) omp_ipr_targetsync-1), &ret_code2);
218 assert (ret_code2 == omp_irc_out_of_range);
219 assert (ptr2 == NULL); /* Obvious implementation choice. */
220 err2 = omp_get_interop_rc_desc (interop, ret_code2);
221 assert (err2 != NULL && strlen (err2) > 5); /* Some sensible message. */
222 /* GCC implementation choice. */
223 assert (!strcmp (err2, "property ID is out of range"));
224 void *ptr5 = omp_get_interop_ptr (interop,
225 (omp_interop_property_t) ((int) omp_ipr_targetsync-1), NULL);
226 assert (ptr5 == ptr2);
227 #ifdef __cplusplus
228 ptr5 = omp_get_interop_ptr (interop,
229 (omp_interop_property_t) ((int) omp_ipr_targetsync-1));
230 assert (ptr5 == ptr2);
231 #endif
232
233 ret_code2 = omp_irc_success;
234 str2 = omp_get_interop_str (interop,
235 (omp_interop_property_t) ((int) omp_ipr_targetsync-1), &ret_code2);
236 assert (ret_code2 == omp_irc_out_of_range);
237 assert (str2 == NULL); /* Obvious implementation choice. */
238 err2 = omp_get_interop_rc_desc (interop, ret_code2);
239 assert (err2 != NULL && strlen (err2) > 5); /* Some sensible message. */
240 /* GCC implementation choice. */
241 assert (!strcmp (err2, "property ID is out of range"));
242 const char *str5 = omp_get_interop_str (interop,
243 (omp_interop_property_t) ((int) omp_ipr_targetsync-1), NULL);
244 assert (str2 == str5);
245 #ifdef __cplusplus
246 str5 = omp_get_interop_str (interop,
247 (omp_interop_property_t) ((int) omp_ipr_targetsync-1));
248 assert (str2 == str5);
249 #endif
250
251 /* omp_get_num_interop_properties (), i.e > upper bound. */
252
253 ret_code2 = omp_irc_success;
254 ival2 = omp_get_interop_int (interop,
255 (omp_interop_property_t) omp_get_num_interop_properties (interop),
256 &ret_code2);
257 assert (ret_code2 == omp_irc_out_of_range);
258 assert (ival2 == 0); /* Implementation choice. */
259 err2 = omp_get_interop_rc_desc (interop, ret_code2);
260 assert (err2 != NULL && strlen (err2) > 5); /* Some sensible message. */
261 /* GCC implementation choice. */
262 assert (!strcmp (err2, "property ID is out of range"));
263
264 ret_code2 = omp_irc_success;
265 ptr2 = omp_get_interop_ptr (interop,
266 (omp_interop_property_t) omp_get_num_interop_properties (interop),
267 &ret_code2);
268 assert (ret_code2 == omp_irc_out_of_range);
269 assert (ptr2 == NULL); /* Obvious implementation choice. */
270 err2 = omp_get_interop_rc_desc (interop, ret_code2);
271 assert (err2 != NULL && strlen (err2) > 5); /* Some sensible message. */
272 /* GCC implementation choice. */
273 assert (!strcmp (err2, "property ID is out of range"));
274
275 ret_code2 = omp_irc_success;
276 str2 = omp_get_interop_str (interop,
277 (omp_interop_property_t) omp_get_num_interop_properties (interop),
278 &ret_code2);
279 assert (ret_code2 == omp_irc_out_of_range);
280 assert (str2 == NULL); /* Obvious implementation choice. */
281 err2 = omp_get_interop_rc_desc (interop, ret_code2);
282 assert (err2 != NULL && strlen (err2) > 5); /* Some sensible message. */
283 /* GCC implementation choice. */
284 assert (!strcmp (err2, "property ID is out of range"));
285
286 return 0;
287 }