Commit | Line | Data |
---|---|---|
f611d0c3 MD |
1 | // SPDX-License-Identifier: MIT |
2 | /* | |
3 | * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
4 | */ | |
5 | ||
6 | #include <stdint.h> | |
7 | #include <inttypes.h> | |
8 | #include <stdlib.h> | |
9 | #include <stdio.h> | |
4f40d951 | 10 | #include <stdbool.h> |
7a1cb105 | 11 | #include <stddef.h> |
f611d0c3 | 12 | |
67337c4a | 13 | #include <side/trace.h> |
f611d0c3 MD |
14 | |
15 | /* User code example */ | |
16 | ||
67337c4a MD |
17 | side_static_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG, |
18 | side_field_list( | |
a82ffcff MD |
19 | side_field_u32("abc"), |
20 | side_field_s64("def"), | |
21 | side_field_pointer("ptr"), | |
67337c4a MD |
22 | side_field_dynamic("dynamic"), |
23 | side_field_dynamic("dynamic_pointer"), | |
a82ffcff MD |
24 | side_field_null("null"), |
25 | ) | |
f611d0c3 MD |
26 | ); |
27 | ||
28 | static | |
29 | void test_fields(void) | |
30 | { | |
31 | uint32_t uw = 42; | |
32 | int64_t sdw = -500; | |
33 | ||
67337c4a MD |
34 | side_event(my_provider_event, |
35 | side_arg_list( | |
36 | side_arg_u32(uw), | |
37 | side_arg_s64(sdw), | |
38 | side_arg_pointer((void *) 0x1), | |
a82ffcff MD |
39 | side_arg_dynamic_string("zzz"), |
40 | side_arg_dynamic_pointer((void *) 0x1), | |
67337c4a | 41 | side_arg_null(), |
f5e650d7 MD |
42 | ) |
43 | ); | |
f611d0c3 MD |
44 | } |
45 | ||
67337c4a MD |
46 | side_hidden_event(my_provider_event_hidden, "myprovider", "myeventhidden", SIDE_LOGLEVEL_DEBUG, |
47 | side_field_list( | |
a82ffcff MD |
48 | side_field_u32("abc"), |
49 | ) | |
89747802 MD |
50 | ); |
51 | ||
52 | static | |
53 | void test_event_hidden(void) | |
54 | { | |
67337c4a | 55 | side_event(my_provider_event_hidden, side_arg_list(side_arg_u32(2))); |
89747802 MD |
56 | } |
57 | ||
67337c4a | 58 | side_declare_event(my_provider_event_export); |
89747802 | 59 | |
67337c4a MD |
60 | side_export_event(my_provider_event_export, "myprovider", "myeventexport", SIDE_LOGLEVEL_DEBUG, |
61 | side_field_list( | |
a82ffcff MD |
62 | side_field_u32("abc"), |
63 | ) | |
89747802 MD |
64 | ); |
65 | ||
66 | static | |
67 | void test_event_export(void) | |
68 | { | |
67337c4a | 69 | side_event(my_provider_event_export, side_arg_list(side_arg_u32(2))); |
89747802 MD |
70 | } |
71 | ||
67337c4a MD |
72 | side_static_event(my_provider_event_struct_literal, "myprovider", "myeventstructliteral", SIDE_LOGLEVEL_DEBUG, |
73 | side_field_list( | |
74 | side_field_struct("structliteral", | |
75 | side_struct_literal( | |
76 | side_field_list( | |
a82ffcff MD |
77 | side_field_u32("x"), |
78 | side_field_s64("y"), | |
79 | ) | |
c7a14585 | 80 | ) |
f611d0c3 | 81 | ), |
a82ffcff MD |
82 | side_field_u8("z"), |
83 | ) | |
f611d0c3 MD |
84 | ); |
85 | ||
c7a14585 MD |
86 | static |
87 | void test_struct_literal(void) | |
88 | { | |
67337c4a MD |
89 | side_event_cond(my_provider_event_struct_literal) { |
90 | side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22))); | |
91 | side_event_call(my_provider_event_struct_literal, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55))); | |
c7a14585 MD |
92 | } |
93 | } | |
94 | ||
67337c4a MD |
95 | static side_define_struct(mystructdef, |
96 | side_field_list( | |
a82ffcff MD |
97 | side_field_u32("x"), |
98 | side_field_s64("y"), | |
99 | ) | |
c7a14585 MD |
100 | ); |
101 | ||
67337c4a MD |
102 | side_static_event(my_provider_event_struct, "myprovider", "myeventstruct", SIDE_LOGLEVEL_DEBUG, |
103 | side_field_list( | |
104 | side_field_struct("struct", &mystructdef), | |
a82ffcff MD |
105 | side_field_u8("z"), |
106 | ) | |
c7a14585 MD |
107 | ); |
108 | ||
f611d0c3 MD |
109 | static |
110 | void test_struct(void) | |
111 | { | |
67337c4a MD |
112 | side_event_cond(my_provider_event_struct) { |
113 | side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22))); | |
114 | side_event_call(my_provider_event_struct, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55))); | |
f611d0c3 MD |
115 | } |
116 | } | |
117 | ||
67337c4a MD |
118 | side_static_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG, |
119 | side_field_list( | |
a82ffcff MD |
120 | side_field_array("arr", side_elem(side_type_u32()), 3), |
121 | side_field_s64("v"), | |
122 | ) | |
f611d0c3 MD |
123 | ); |
124 | ||
125 | static | |
126 | void test_array(void) | |
127 | { | |
67337c4a MD |
128 | side_event_cond(my_provider_event_array) { |
129 | side_arg_define_vec(myarray, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3))); | |
130 | side_event_call(my_provider_event_array, side_arg_list(side_arg_array(&myarray), side_arg_s64(42))); | |
f611d0c3 MD |
131 | } |
132 | } | |
133 | ||
67337c4a MD |
134 | side_static_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG, |
135 | side_field_list( | |
a82ffcff MD |
136 | side_field_vla("vla", side_elem(side_type_u32())), |
137 | side_field_s64("v"), | |
138 | ) | |
f611d0c3 MD |
139 | ); |
140 | ||
141 | static | |
142 | void test_vla(void) | |
143 | { | |
67337c4a MD |
144 | side_event_cond(my_provider_event_vla) { |
145 | side_arg_define_vec(myvla, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3))); | |
146 | side_event_call(my_provider_event_vla, side_arg_list(side_arg_vla(&myvla), side_arg_s64(42))); | |
f611d0c3 MD |
147 | } |
148 | } | |
149 | ||
cdd6e858 MD |
150 | /* 1D array visitor */ |
151 | ||
f611d0c3 MD |
152 | struct app_visitor_ctx { |
153 | const uint32_t *ptr; | |
352a4b77 | 154 | uint32_t length; |
f611d0c3 MD |
155 | }; |
156 | ||
352a4b77 | 157 | static |
67337c4a | 158 | enum side_visitor_status test_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx) |
f611d0c3 MD |
159 | { |
160 | struct app_visitor_ctx *ctx = (struct app_visitor_ctx *) _ctx; | |
352a4b77 MD |
161 | uint32_t length = ctx->length, i; |
162 | ||
163 | for (i = 0; i < length; i++) { | |
67337c4a | 164 | const struct side_arg elem = side_arg_u32(ctx->ptr[i]); |
ffb5c809 | 165 | |
67337c4a MD |
166 | if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK) |
167 | return SIDE_VISITOR_STATUS_ERROR; | |
352a4b77 | 168 | } |
67337c4a | 169 | return SIDE_VISITOR_STATUS_OK; |
f611d0c3 MD |
170 | } |
171 | ||
172 | static uint32_t testarray[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; | |
173 | ||
67337c4a MD |
174 | side_static_event(my_provider_event_vla_visitor, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG, |
175 | side_field_list( | |
a82ffcff MD |
176 | side_field_vla_visitor("vlavisit", side_elem(side_type_u32()), test_visitor), |
177 | side_field_s64("v"), | |
178 | ) | |
f611d0c3 MD |
179 | ); |
180 | ||
181 | static | |
182 | void test_vla_visitor(void) | |
183 | { | |
67337c4a | 184 | side_event_cond(my_provider_event_vla_visitor) { |
f611d0c3 MD |
185 | struct app_visitor_ctx ctx = { |
186 | .ptr = testarray, | |
67337c4a | 187 | .length = SIDE_ARRAY_SIZE(testarray), |
f611d0c3 | 188 | }; |
67337c4a | 189 | side_event_call(my_provider_event_vla_visitor, side_arg_list(side_arg_vla_visitor(&ctx), side_arg_s64(42))); |
f611d0c3 MD |
190 | } |
191 | } | |
192 | ||
cdd6e858 MD |
193 | /* 2D array visitor */ |
194 | ||
195 | struct app_visitor_2d_inner_ctx { | |
196 | const uint32_t *ptr; | |
197 | uint32_t length; | |
198 | }; | |
199 | ||
200 | static | |
67337c4a | 201 | enum side_visitor_status test_inner_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx) |
cdd6e858 MD |
202 | { |
203 | struct app_visitor_2d_inner_ctx *ctx = (struct app_visitor_2d_inner_ctx *) _ctx; | |
204 | uint32_t length = ctx->length, i; | |
205 | ||
206 | for (i = 0; i < length; i++) { | |
67337c4a | 207 | const struct side_arg elem = side_arg_u32(ctx->ptr[i]); |
ffb5c809 | 208 | |
67337c4a MD |
209 | if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK) |
210 | return SIDE_VISITOR_STATUS_ERROR; | |
cdd6e858 | 211 | } |
67337c4a | 212 | return SIDE_VISITOR_STATUS_OK; |
cdd6e858 MD |
213 | } |
214 | ||
215 | struct app_visitor_2d_outer_ctx { | |
216 | const uint32_t (*ptr)[2]; | |
217 | uint32_t length; | |
218 | }; | |
219 | ||
220 | static | |
67337c4a | 221 | enum side_visitor_status test_outer_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx) |
cdd6e858 MD |
222 | { |
223 | struct app_visitor_2d_outer_ctx *ctx = (struct app_visitor_2d_outer_ctx *) _ctx; | |
224 | uint32_t length = ctx->length, i; | |
225 | ||
226 | for (i = 0; i < length; i++) { | |
227 | struct app_visitor_2d_inner_ctx inner_ctx = { | |
228 | .ptr = ctx->ptr[i], | |
229 | .length = 2, | |
230 | }; | |
67337c4a MD |
231 | const struct side_arg elem = side_arg_vla_visitor(&inner_ctx); |
232 | if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK) | |
233 | return SIDE_VISITOR_STATUS_ERROR; | |
cdd6e858 | 234 | } |
67337c4a | 235 | return SIDE_VISITOR_STATUS_OK; |
cdd6e858 MD |
236 | } |
237 | ||
238 | static uint32_t testarray2d[][2] = { | |
239 | { 1, 2 }, | |
240 | { 33, 44 }, | |
241 | { 55, 66 }, | |
242 | }; | |
243 | ||
67337c4a MD |
244 | side_static_event(my_provider_event_vla_visitor2d, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG, |
245 | side_field_list( | |
246 | side_field_vla_visitor("vlavisit2d", | |
247 | side_elem( | |
248 | side_type_vla_visitor( | |
a82ffcff MD |
249 | side_elem(side_type_u32()), |
250 | test_inner_visitor | |
251 | ) | |
252 | ), test_outer_visitor), | |
253 | side_field_s64("v"), | |
254 | ) | |
cdd6e858 MD |
255 | ); |
256 | ||
257 | static | |
258 | void test_vla_visitor_2d(void) | |
259 | { | |
67337c4a | 260 | side_event_cond(my_provider_event_vla_visitor2d) { |
cdd6e858 MD |
261 | struct app_visitor_2d_outer_ctx ctx = { |
262 | .ptr = testarray2d, | |
67337c4a | 263 | .length = SIDE_ARRAY_SIZE(testarray2d), |
cdd6e858 | 264 | }; |
67337c4a | 265 | side_event_call(my_provider_event_vla_visitor2d, side_arg_list(side_arg_vla_visitor(&ctx), side_arg_s64(42))); |
cdd6e858 MD |
266 | } |
267 | } | |
268 | ||
67337c4a MD |
269 | side_static_event(my_provider_event_dynamic_basic, |
270 | "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG, | |
271 | side_field_list( | |
272 | side_field_dynamic("dynamic"), | |
a82ffcff | 273 | ) |
a2e2357e MD |
274 | ); |
275 | ||
276 | static | |
277 | void test_dynamic_basic_type(void) | |
278 | { | |
67337c4a | 279 | side_event(my_provider_event_dynamic_basic, |
a82ffcff | 280 | side_arg_list(side_arg_dynamic_s16(-33))); |
a2e2357e MD |
281 | } |
282 | ||
67337c4a MD |
283 | side_static_event(my_provider_event_dynamic_vla, |
284 | "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG, | |
285 | side_field_list( | |
286 | side_field_dynamic("dynamic"), | |
a82ffcff | 287 | ) |
a2e2357e MD |
288 | ); |
289 | ||
290 | static | |
291 | void test_dynamic_vla(void) | |
292 | { | |
67337c4a MD |
293 | side_arg_dynamic_define_vec(myvla, |
294 | side_arg_list( | |
a82ffcff MD |
295 | side_arg_dynamic_u32(1), |
296 | side_arg_dynamic_u32(2), | |
297 | side_arg_dynamic_u32(3), | |
298 | ) | |
df075fa5 | 299 | ); |
67337c4a MD |
300 | side_event(my_provider_event_dynamic_vla, |
301 | side_arg_list(side_arg_dynamic_vla(&myvla))); | |
a2e2357e MD |
302 | } |
303 | ||
67337c4a MD |
304 | side_static_event(my_provider_event_dynamic_null, |
305 | "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG, | |
306 | side_field_list( | |
307 | side_field_dynamic("dynamic"), | |
a82ffcff | 308 | ) |
465e5e7e MD |
309 | ); |
310 | ||
311 | static | |
312 | void test_dynamic_null(void) | |
313 | { | |
67337c4a | 314 | side_event(my_provider_event_dynamic_null, |
a82ffcff | 315 | side_arg_list(side_arg_dynamic_null())); |
465e5e7e MD |
316 | } |
317 | ||
67337c4a MD |
318 | side_static_event(my_provider_event_dynamic_struct, |
319 | "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG, | |
320 | side_field_list( | |
321 | side_field_dynamic("dynamic"), | |
a82ffcff | 322 | ) |
465e5e7e MD |
323 | ); |
324 | ||
325 | static | |
c208889e | 326 | void test_dynamic_struct(void) |
465e5e7e | 327 | { |
67337c4a MD |
328 | side_arg_dynamic_define_struct(mystruct, |
329 | side_arg_list( | |
a82ffcff MD |
330 | side_arg_dynamic_field("a", side_arg_dynamic_u32(43)), |
331 | side_arg_dynamic_field("b", side_arg_dynamic_string("zzz")), | |
332 | side_arg_dynamic_field("c", side_arg_dynamic_null()), | |
333 | ) | |
465e5e7e MD |
334 | ); |
335 | ||
67337c4a MD |
336 | side_event(my_provider_event_dynamic_struct, |
337 | side_arg_list(side_arg_dynamic_struct(&mystruct))); | |
465e5e7e MD |
338 | } |
339 | ||
67337c4a MD |
340 | side_static_event(my_provider_event_dynamic_nested_struct, |
341 | "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG, | |
342 | side_field_list( | |
343 | side_field_dynamic("dynamic"), | |
a82ffcff | 344 | ) |
3222d397 MD |
345 | ); |
346 | ||
347 | static | |
c208889e | 348 | void test_dynamic_nested_struct(void) |
3222d397 | 349 | { |
67337c4a MD |
350 | side_arg_dynamic_define_struct(nested, |
351 | side_arg_list( | |
a82ffcff MD |
352 | side_arg_dynamic_field("a", side_arg_dynamic_u32(43)), |
353 | side_arg_dynamic_field("b", side_arg_dynamic_u8(55)), | |
354 | ) | |
3222d397 | 355 | ); |
67337c4a MD |
356 | side_arg_dynamic_define_struct(nested2, |
357 | side_arg_list( | |
a82ffcff MD |
358 | side_arg_dynamic_field("aa", side_arg_dynamic_u64(128)), |
359 | side_arg_dynamic_field("bb", side_arg_dynamic_u16(1)), | |
360 | ) | |
3222d397 | 361 | ); |
67337c4a MD |
362 | side_arg_dynamic_define_struct(mystruct, |
363 | side_arg_list( | |
364 | side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested)), | |
365 | side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2)), | |
a82ffcff | 366 | ) |
3222d397 | 367 | ); |
67337c4a MD |
368 | side_event(my_provider_event_dynamic_nested_struct, |
369 | side_arg_list(side_arg_dynamic_struct(&mystruct))); | |
3222d397 MD |
370 | } |
371 | ||
67337c4a MD |
372 | side_static_event(my_provider_event_dynamic_vla_struct, |
373 | "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG, | |
374 | side_field_list( | |
375 | side_field_dynamic("dynamic"), | |
a82ffcff | 376 | ) |
7ce1b78f MD |
377 | ); |
378 | ||
379 | static | |
c208889e | 380 | void test_dynamic_vla_struct(void) |
7ce1b78f | 381 | { |
67337c4a MD |
382 | side_arg_dynamic_define_struct(nested, |
383 | side_arg_list( | |
a82ffcff MD |
384 | side_arg_dynamic_field("a", side_arg_dynamic_u32(43)), |
385 | side_arg_dynamic_field("b", side_arg_dynamic_u8(55)), | |
386 | ) | |
7ce1b78f | 387 | ); |
67337c4a MD |
388 | side_arg_dynamic_define_vec(myvla, |
389 | side_arg_list( | |
390 | side_arg_dynamic_struct(&nested), | |
391 | side_arg_dynamic_struct(&nested), | |
392 | side_arg_dynamic_struct(&nested), | |
393 | side_arg_dynamic_struct(&nested), | |
a82ffcff | 394 | ) |
7ce1b78f | 395 | ); |
67337c4a MD |
396 | side_event(my_provider_event_dynamic_vla_struct, |
397 | side_arg_list(side_arg_dynamic_vla(&myvla))); | |
7ce1b78f MD |
398 | } |
399 | ||
67337c4a MD |
400 | side_static_event(my_provider_event_dynamic_struct_vla, |
401 | "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG, | |
402 | side_field_list( | |
403 | side_field_dynamic("dynamic"), | |
a82ffcff | 404 | ) |
980bfdc4 MD |
405 | ); |
406 | ||
407 | static | |
c208889e | 408 | void test_dynamic_struct_vla(void) |
980bfdc4 | 409 | { |
67337c4a MD |
410 | side_arg_dynamic_define_vec(myvla, |
411 | side_arg_list( | |
a82ffcff MD |
412 | side_arg_dynamic_u32(1), |
413 | side_arg_dynamic_u32(2), | |
414 | side_arg_dynamic_u32(3), | |
415 | ) | |
df075fa5 | 416 | ); |
67337c4a MD |
417 | side_arg_dynamic_define_vec(myvla2, |
418 | side_arg_list( | |
a82ffcff MD |
419 | side_arg_dynamic_u32(4), |
420 | side_arg_dynamic_u64(5), | |
421 | side_arg_dynamic_u32(6), | |
422 | ) | |
df075fa5 | 423 | ); |
67337c4a MD |
424 | side_arg_dynamic_define_struct(mystruct, |
425 | side_arg_list( | |
426 | side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla)), | |
427 | side_arg_dynamic_field("b", side_arg_dynamic_vla(&myvla2)), | |
a82ffcff | 428 | ) |
980bfdc4 | 429 | ); |
67337c4a MD |
430 | side_event(my_provider_event_dynamic_struct_vla, |
431 | side_arg_list(side_arg_dynamic_struct(&mystruct))); | |
980bfdc4 MD |
432 | } |
433 | ||
67337c4a MD |
434 | side_static_event(my_provider_event_dynamic_nested_vla, |
435 | "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG, | |
436 | side_field_list( | |
437 | side_field_dynamic("dynamic"), | |
a82ffcff | 438 | ) |
948e3e72 MD |
439 | ); |
440 | ||
441 | static | |
442 | void test_dynamic_nested_vla(void) | |
443 | { | |
67337c4a MD |
444 | side_arg_dynamic_define_vec(nestedvla, |
445 | side_arg_list( | |
a82ffcff MD |
446 | side_arg_dynamic_u32(1), |
447 | side_arg_dynamic_u16(2), | |
448 | side_arg_dynamic_u32(3), | |
449 | ) | |
948e3e72 | 450 | ); |
67337c4a MD |
451 | side_arg_dynamic_define_vec(nestedvla2, |
452 | side_arg_list( | |
a82ffcff MD |
453 | side_arg_dynamic_u8(4), |
454 | side_arg_dynamic_u32(5), | |
455 | side_arg_dynamic_u32(6), | |
456 | ) | |
948e3e72 | 457 | ); |
67337c4a MD |
458 | side_arg_dynamic_define_vec(myvla, |
459 | side_arg_list( | |
460 | side_arg_dynamic_vla(&nestedvla), | |
461 | side_arg_dynamic_vla(&nestedvla2), | |
a82ffcff | 462 | ) |
948e3e72 | 463 | ); |
67337c4a MD |
464 | side_event(my_provider_event_dynamic_nested_vla, |
465 | side_arg_list(side_arg_dynamic_vla(&myvla))); | |
948e3e72 MD |
466 | } |
467 | ||
67337c4a MD |
468 | side_static_event_variadic(my_provider_event_variadic, |
469 | "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG, | |
a82ffcff | 470 | side_field_list() |
19fa6aa2 MD |
471 | ); |
472 | ||
473 | static | |
474 | void test_variadic(void) | |
475 | { | |
67337c4a MD |
476 | side_event_variadic(my_provider_event_variadic, |
477 | side_arg_list(), | |
478 | side_arg_list( | |
a82ffcff MD |
479 | side_arg_dynamic_field("a", side_arg_dynamic_u32(55)), |
480 | side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)), | |
481 | ) | |
19fa6aa2 MD |
482 | ); |
483 | } | |
484 | ||
67337c4a MD |
485 | side_static_event_variadic(my_provider_event_static_variadic, |
486 | "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG, | |
487 | side_field_list( | |
a82ffcff MD |
488 | side_field_u32("abc"), |
489 | side_field_u16("def"), | |
490 | ) | |
41c4d119 MD |
491 | ); |
492 | ||
493 | static | |
494 | void test_static_variadic(void) | |
495 | { | |
67337c4a MD |
496 | side_event_variadic(my_provider_event_static_variadic, |
497 | side_arg_list( | |
498 | side_arg_u32(1), | |
499 | side_arg_u16(2), | |
41c4d119 | 500 | ), |
67337c4a | 501 | side_arg_list( |
a82ffcff MD |
502 | side_arg_dynamic_field("a", side_arg_dynamic_u32(55)), |
503 | side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)), | |
504 | ) | |
41c4d119 MD |
505 | ); |
506 | } | |
507 | ||
67337c4a MD |
508 | side_static_event(my_provider_event_bool, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG, |
509 | side_field_list( | |
a82ffcff MD |
510 | side_field_bool("a_false"), |
511 | side_field_bool("b_true"), | |
512 | side_field_bool("c_true"), | |
513 | side_field_bool("d_true"), | |
514 | side_field_bool("e_true"), | |
515 | side_field_bool("f_false"), | |
516 | side_field_bool("g_true"), | |
517 | ) | |
4f40d951 MD |
518 | ); |
519 | ||
520 | static | |
521 | void test_bool(void) | |
522 | { | |
523 | uint32_t a = 0; | |
524 | uint32_t b = 1; | |
525 | uint64_t c = 0x12345678; | |
526 | int16_t d = -32768; | |
527 | bool e = true; | |
528 | bool f = false; | |
529 | uint32_t g = 256; | |
530 | ||
67337c4a MD |
531 | side_event(my_provider_event_bool, |
532 | side_arg_list( | |
533 | side_arg_bool(a), | |
534 | side_arg_bool(b), | |
535 | side_arg_bool(c), | |
536 | side_arg_bool(d), | |
537 | side_arg_bool(e), | |
538 | side_arg_bool(f), | |
539 | side_arg_bool(g), | |
4f40d951 MD |
540 | ) |
541 | ); | |
542 | } | |
543 | ||
67337c4a MD |
544 | side_static_event_variadic(my_provider_event_dynamic_bool, |
545 | "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG, | |
a82ffcff | 546 | side_field_list() |
4f40d951 MD |
547 | ); |
548 | ||
549 | static | |
550 | void test_dynamic_bool(void) | |
551 | { | |
67337c4a MD |
552 | side_event_variadic(my_provider_event_dynamic_bool, |
553 | side_arg_list(), | |
554 | side_arg_list( | |
a82ffcff MD |
555 | side_arg_dynamic_field("a_true", side_arg_dynamic_bool(55)), |
556 | side_arg_dynamic_field("b_true", side_arg_dynamic_bool(-4)), | |
557 | side_arg_dynamic_field("c_false", side_arg_dynamic_bool(0)), | |
558 | side_arg_dynamic_field("d_true", side_arg_dynamic_bool(256)), | |
559 | ) | |
4f40d951 MD |
560 | ); |
561 | } | |
562 | ||
67337c4a MD |
563 | side_static_event(my_provider_event_dynamic_vla_visitor, |
564 | "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG, | |
565 | side_field_list( | |
566 | side_field_dynamic("dynamic"), | |
a82ffcff | 567 | ) |
8ceca0cd MD |
568 | ); |
569 | ||
570 | struct app_dynamic_vla_visitor_ctx { | |
571 | const uint32_t *ptr; | |
572 | uint32_t length; | |
573 | }; | |
574 | ||
575 | static | |
67337c4a | 576 | enum side_visitor_status test_dynamic_vla_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx) |
8ceca0cd MD |
577 | { |
578 | struct app_dynamic_vla_visitor_ctx *ctx = (struct app_dynamic_vla_visitor_ctx *) _ctx; | |
579 | uint32_t length = ctx->length, i; | |
580 | ||
581 | for (i = 0; i < length; i++) { | |
a82ffcff | 582 | const struct side_arg elem = side_arg_dynamic_u32(ctx->ptr[i]); |
67337c4a MD |
583 | if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK) |
584 | return SIDE_VISITOR_STATUS_ERROR; | |
8ceca0cd | 585 | } |
67337c4a | 586 | return SIDE_VISITOR_STATUS_OK; |
8ceca0cd MD |
587 | } |
588 | ||
589 | static uint32_t testarray_dynamic_vla[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; | |
590 | ||
591 | static | |
592 | void test_dynamic_vla_with_visitor(void) | |
593 | { | |
67337c4a | 594 | side_event_cond(my_provider_event_dynamic_vla_visitor) { |
8ceca0cd MD |
595 | struct app_dynamic_vla_visitor_ctx ctx = { |
596 | .ptr = testarray_dynamic_vla, | |
67337c4a | 597 | .length = SIDE_ARRAY_SIZE(testarray_dynamic_vla), |
8ceca0cd | 598 | }; |
67337c4a MD |
599 | side_event_call(my_provider_event_dynamic_vla_visitor, |
600 | side_arg_list( | |
a82ffcff | 601 | side_arg_dynamic_vla_visitor(test_dynamic_vla_visitor, &ctx) |
8ceca0cd MD |
602 | ) |
603 | ); | |
604 | } | |
605 | } | |
606 | ||
67337c4a MD |
607 | side_static_event(my_provider_event_dynamic_struct_visitor, |
608 | "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG, | |
609 | side_field_list( | |
610 | side_field_dynamic("dynamic"), | |
a82ffcff | 611 | ) |
2b359235 MD |
612 | ); |
613 | ||
614 | struct struct_visitor_pair { | |
615 | const char *name; | |
616 | uint32_t value; | |
617 | }; | |
618 | ||
619 | struct app_dynamic_struct_visitor_ctx { | |
620 | const struct struct_visitor_pair *ptr; | |
621 | uint32_t length; | |
622 | }; | |
623 | ||
624 | static | |
67337c4a | 625 | enum side_visitor_status test_dynamic_struct_visitor(const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, void *_ctx) |
2b359235 MD |
626 | { |
627 | struct app_dynamic_struct_visitor_ctx *ctx = (struct app_dynamic_struct_visitor_ctx *) _ctx; | |
628 | uint32_t length = ctx->length, i; | |
629 | ||
630 | for (i = 0; i < length; i++) { | |
67337c4a | 631 | struct side_arg_dynamic_field dynamic_field = { |
2b359235 | 632 | .field_name = ctx->ptr[i].name, |
a82ffcff | 633 | .elem = side_arg_dynamic_u32(ctx->ptr[i].value), |
2b359235 | 634 | }; |
67337c4a MD |
635 | if (tracer_ctx->write_field(tracer_ctx, &dynamic_field) != SIDE_VISITOR_STATUS_OK) |
636 | return SIDE_VISITOR_STATUS_ERROR; | |
2b359235 | 637 | } |
67337c4a | 638 | return SIDE_VISITOR_STATUS_OK; |
2b359235 MD |
639 | } |
640 | ||
641 | static struct struct_visitor_pair testarray_dynamic_struct[] = { | |
642 | { "a", 1, }, | |
643 | { "b", 2, }, | |
644 | { "c", 3, }, | |
645 | { "d", 4, }, | |
646 | }; | |
647 | ||
648 | static | |
649 | void test_dynamic_struct_with_visitor(void) | |
650 | { | |
67337c4a | 651 | side_event_cond(my_provider_event_dynamic_struct_visitor) { |
2b359235 MD |
652 | struct app_dynamic_struct_visitor_ctx ctx = { |
653 | .ptr = testarray_dynamic_struct, | |
67337c4a | 654 | .length = SIDE_ARRAY_SIZE(testarray_dynamic_struct), |
2b359235 | 655 | }; |
67337c4a MD |
656 | side_event_call(my_provider_event_dynamic_struct_visitor, |
657 | side_arg_list( | |
a82ffcff | 658 | side_arg_dynamic_struct_visitor(test_dynamic_struct_visitor, &ctx) |
2b359235 MD |
659 | ) |
660 | ); | |
661 | } | |
662 | } | |
663 | ||
67337c4a MD |
664 | side_static_event(my_provider_event_user_attribute, "myprovider", "myevent_user_attribute", SIDE_LOGLEVEL_DEBUG, |
665 | side_field_list( | |
a82ffcff MD |
666 | side_field_u32("abc"), |
667 | side_field_s64("def"), | |
399c836b | 668 | ), |
67337c4a MD |
669 | side_attr_list( |
670 | side_attr("user_attribute_a", side_attr_string("val1")), | |
671 | side_attr("user_attribute_b", side_attr_string("val2")), | |
65010f43 MD |
672 | ) |
673 | ); | |
674 | ||
675 | static | |
676 | void test_event_user_attribute(void) | |
677 | { | |
67337c4a | 678 | side_event(my_provider_event_user_attribute, side_arg_list(side_arg_u32(1), side_arg_s64(2))); |
65010f43 MD |
679 | } |
680 | ||
67337c4a MD |
681 | side_static_event(my_provider_field_user_attribute, "myprovider", "myevent_field_attribute", SIDE_LOGLEVEL_DEBUG, |
682 | side_field_list( | |
683 | side_field_u32("abc", | |
684 | side_attr_list( | |
685 | side_attr("user_attribute_a", side_attr_string("val1")), | |
686 | side_attr("user_attribute_b", side_attr_u32(2)), | |
a848763d MD |
687 | ) |
688 | ), | |
67337c4a MD |
689 | side_field_s64("def", |
690 | side_attr_list( | |
691 | side_attr("user_attribute_c", side_attr_string("val3")), | |
692 | side_attr("user_attribute_d", side_attr_s64(-5)), | |
a848763d MD |
693 | ) |
694 | ), | |
a82ffcff | 695 | ) |
a848763d MD |
696 | ); |
697 | ||
698 | static | |
699 | void test_field_user_attribute(void) | |
700 | { | |
67337c4a | 701 | side_event(my_provider_field_user_attribute, side_arg_list(side_arg_u32(1), side_arg_s64(2))); |
a848763d MD |
702 | } |
703 | ||
67337c4a MD |
704 | side_static_event_variadic(my_provider_event_variadic_attr, |
705 | "myprovider", "myvariadiceventattr", SIDE_LOGLEVEL_DEBUG, | |
a82ffcff | 706 | side_field_list() |
808bd9bf MD |
707 | ); |
708 | ||
709 | static | |
710 | void test_variadic_attr(void) | |
711 | { | |
67337c4a MD |
712 | side_event_variadic(my_provider_event_variadic_attr, |
713 | side_arg_list(), | |
714 | side_arg_list( | |
715 | side_arg_dynamic_field("a", | |
716 | side_arg_dynamic_u32(55, | |
717 | side_attr_list( | |
718 | side_attr("user_attribute_c", side_attr_string("valX")), | |
719 | side_attr("user_attribute_d", side_attr_u8(55)), | |
808bd9bf MD |
720 | ) |
721 | ) | |
722 | ), | |
67337c4a MD |
723 | side_arg_dynamic_field("b", |
724 | side_arg_dynamic_s8(-4, | |
725 | side_attr_list( | |
726 | side_attr("X", side_attr_u8(1)), | |
727 | side_attr("Y", side_attr_s8(2)), | |
808bd9bf MD |
728 | ) |
729 | ) | |
730 | ), | |
a82ffcff | 731 | ) |
808bd9bf MD |
732 | ); |
733 | } | |
734 | ||
67337c4a MD |
735 | side_static_event_variadic(my_provider_event_variadic_vla_attr, |
736 | "myprovider", "myvariadiceventvlaattr", SIDE_LOGLEVEL_DEBUG, | |
a82ffcff | 737 | side_field_list() |
808bd9bf MD |
738 | ); |
739 | ||
740 | static | |
741 | void test_variadic_vla_attr(void) | |
742 | { | |
67337c4a MD |
743 | side_arg_dynamic_define_vec(myvla, |
744 | side_arg_list( | |
745 | side_arg_dynamic_u32(1, | |
746 | side_attr_list( | |
747 | side_attr("Z", side_attr_u8(0)), | |
748 | side_attr("A", side_attr_u8(123)), | |
808bd9bf MD |
749 | ) |
750 | ), | |
a82ffcff MD |
751 | side_arg_dynamic_u32(2), |
752 | side_arg_dynamic_u32(3), | |
8d20e708 | 753 | ), |
67337c4a MD |
754 | side_attr_list( |
755 | side_attr("X", side_attr_u8(1)), | |
756 | side_attr("Y", side_attr_u8(2)), | |
808bd9bf MD |
757 | ) |
758 | ); | |
67337c4a MD |
759 | side_event_variadic(my_provider_event_variadic_vla_attr, |
760 | side_arg_list(), | |
761 | side_arg_list( | |
762 | side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla)), | |
a82ffcff | 763 | ) |
808bd9bf MD |
764 | ); |
765 | } | |
766 | ||
67337c4a MD |
767 | side_static_event_variadic(my_provider_event_variadic_struct_attr, |
768 | "myprovider", "myvariadiceventstructattr", SIDE_LOGLEVEL_DEBUG, | |
a82ffcff | 769 | side_field_list() |
808bd9bf MD |
770 | ); |
771 | ||
772 | static | |
773 | void test_variadic_struct_attr(void) | |
774 | { | |
67337c4a MD |
775 | side_event_cond(my_provider_event_variadic_struct_attr) { |
776 | side_arg_dynamic_define_struct(mystruct, | |
777 | side_arg_list( | |
778 | side_arg_dynamic_field("a", | |
779 | side_arg_dynamic_u32(43, | |
780 | side_attr_list( | |
781 | side_attr("A", side_attr_bool(true)), | |
808bd9bf MD |
782 | ) |
783 | ) | |
784 | ), | |
a82ffcff | 785 | side_arg_dynamic_field("b", side_arg_dynamic_u8(55)), |
8d20e708 | 786 | ), |
67337c4a MD |
787 | side_attr_list( |
788 | side_attr("X", side_attr_u8(1)), | |
789 | side_attr("Y", side_attr_u8(2)), | |
808bd9bf MD |
790 | ) |
791 | ); | |
67337c4a MD |
792 | side_event_call_variadic(my_provider_event_variadic_struct_attr, |
793 | side_arg_list(), | |
794 | side_arg_list( | |
795 | side_arg_dynamic_field("a", side_arg_dynamic_struct(&mystruct)), | |
a82ffcff | 796 | ) |
808bd9bf MD |
797 | ); |
798 | } | |
799 | } | |
800 | ||
67337c4a MD |
801 | side_static_event(my_provider_event_float, "myprovider", "myeventfloat", SIDE_LOGLEVEL_DEBUG, |
802 | side_field_list( | |
fb25b355 | 803 | #if __HAVE_FLOAT16 |
a82ffcff MD |
804 | side_field_float_binary16("binary16"), |
805 | side_field_float_binary16_le("binary16_le"), | |
806 | side_field_float_binary16_be("binary16_be"), | |
fb25b355 MD |
807 | #endif |
808 | #if __HAVE_FLOAT32 | |
a82ffcff MD |
809 | side_field_float_binary32("binary32"), |
810 | side_field_float_binary32_le("binary32_le"), | |
811 | side_field_float_binary32_be("binary32_be"), | |
fb25b355 MD |
812 | #endif |
813 | #if __HAVE_FLOAT64 | |
a82ffcff MD |
814 | side_field_float_binary64("binary64"), |
815 | side_field_float_binary64_le("binary64_le"), | |
816 | side_field_float_binary64_be("binary64_be"), | |
fb25b355 MD |
817 | #endif |
818 | #if __HAVE_FLOAT128 | |
a82ffcff MD |
819 | side_field_float_binary128("binary128"), |
820 | side_field_float_binary128_le("binary128_le"), | |
821 | side_field_float_binary128_be("binary128_be"), | |
fb25b355 | 822 | #endif |
a82ffcff | 823 | ) |
fb25b355 MD |
824 | ); |
825 | ||
826 | static | |
827 | void test_float(void) | |
828 | { | |
8bdd5c12 MD |
829 | #if __HAVE_FLOAT16 |
830 | union { | |
831 | _Float16 f; | |
832 | uint16_t u; | |
833 | } float16 = { | |
834 | .f = 1.1, | |
835 | }; | |
836 | #endif | |
837 | #if __HAVE_FLOAT32 | |
838 | union { | |
839 | _Float32 f; | |
840 | uint32_t u; | |
841 | } float32 = { | |
842 | .f = 2.2, | |
843 | }; | |
844 | #endif | |
845 | #if __HAVE_FLOAT64 | |
846 | union { | |
847 | _Float64 f; | |
848 | uint64_t u; | |
849 | } float64 = { | |
850 | .f = 3.3, | |
851 | }; | |
852 | #endif | |
853 | #if __HAVE_FLOAT128 | |
854 | union { | |
855 | _Float128 f; | |
856 | char arr[16]; | |
857 | } float128 = { | |
858 | .f = 4.4, | |
859 | }; | |
860 | #endif | |
861 | ||
862 | #if __HAVE_FLOAT16 | |
67337c4a | 863 | float16.u = side_bswap_16(float16.u); |
8bdd5c12 MD |
864 | #endif |
865 | #if __HAVE_FLOAT32 | |
67337c4a | 866 | float32.u = side_bswap_32(float32.u); |
8bdd5c12 MD |
867 | #endif |
868 | #if __HAVE_FLOAT64 | |
67337c4a | 869 | float64.u = side_bswap_64(float64.u); |
8bdd5c12 MD |
870 | #endif |
871 | #if __HAVE_FLOAT128 | |
67337c4a | 872 | side_bswap_128p(float128.arr); |
8bdd5c12 MD |
873 | #endif |
874 | ||
67337c4a MD |
875 | side_event(my_provider_event_float, |
876 | side_arg_list( | |
fb25b355 | 877 | #if __HAVE_FLOAT16 |
67337c4a MD |
878 | side_arg_float_binary16(1.1), |
879 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN | |
880 | side_arg_float_binary16(1.1), | |
881 | side_arg_float_binary16(float16.f), | |
8bdd5c12 | 882 | # else |
67337c4a MD |
883 | side_arg_float_binary16(float16.f), |
884 | side_arg_float_binary16(1.1), | |
8bdd5c12 | 885 | # endif |
fb25b355 MD |
886 | #endif |
887 | #if __HAVE_FLOAT32 | |
67337c4a MD |
888 | side_arg_float_binary32(2.2), |
889 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN | |
890 | side_arg_float_binary32(2.2), | |
891 | side_arg_float_binary32(float32.f), | |
8bdd5c12 | 892 | # else |
67337c4a MD |
893 | side_arg_float_binary32(float32.f), |
894 | side_arg_float_binary32(2.2), | |
8bdd5c12 | 895 | # endif |
fb25b355 MD |
896 | #endif |
897 | #if __HAVE_FLOAT64 | |
67337c4a MD |
898 | side_arg_float_binary64(3.3), |
899 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN | |
900 | side_arg_float_binary64(3.3), | |
901 | side_arg_float_binary64(float64.f), | |
8bdd5c12 | 902 | # else |
67337c4a MD |
903 | side_arg_float_binary64(float64.f), |
904 | side_arg_float_binary64(3.3), | |
8bdd5c12 | 905 | # endif |
fb25b355 MD |
906 | #endif |
907 | #if __HAVE_FLOAT128 | |
67337c4a MD |
908 | side_arg_float_binary128(4.4), |
909 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN | |
910 | side_arg_float_binary128(4.4), | |
911 | side_arg_float_binary128(float128.f), | |
8bdd5c12 | 912 | # else |
67337c4a MD |
913 | side_arg_float_binary128(float128.f), |
914 | side_arg_float_binary128(4.4), | |
8bdd5c12 | 915 | # endif |
fb25b355 MD |
916 | #endif |
917 | ) | |
918 | ); | |
919 | } | |
920 | ||
67337c4a MD |
921 | side_static_event_variadic(my_provider_event_variadic_float, |
922 | "myprovider", "myvariadicfloat", SIDE_LOGLEVEL_DEBUG, | |
a82ffcff | 923 | side_field_list() |
fb25b355 MD |
924 | ); |
925 | ||
926 | static | |
927 | void test_variadic_float(void) | |
928 | { | |
8bdd5c12 MD |
929 | #if __HAVE_FLOAT16 |
930 | union { | |
931 | _Float16 f; | |
932 | uint16_t u; | |
933 | } float16 = { | |
934 | .f = 1.1, | |
935 | }; | |
936 | #endif | |
937 | #if __HAVE_FLOAT32 | |
938 | union { | |
939 | _Float32 f; | |
940 | uint32_t u; | |
941 | } float32 = { | |
942 | .f = 2.2, | |
943 | }; | |
944 | #endif | |
945 | #if __HAVE_FLOAT64 | |
946 | union { | |
947 | _Float64 f; | |
948 | uint64_t u; | |
949 | } float64 = { | |
950 | .f = 3.3, | |
951 | }; | |
952 | #endif | |
953 | #if __HAVE_FLOAT128 | |
954 | union { | |
955 | _Float128 f; | |
956 | char arr[16]; | |
957 | } float128 = { | |
958 | .f = 4.4, | |
959 | }; | |
960 | #endif | |
961 | ||
962 | #if __HAVE_FLOAT16 | |
67337c4a | 963 | float16.u = side_bswap_16(float16.u); |
8bdd5c12 MD |
964 | #endif |
965 | #if __HAVE_FLOAT32 | |
67337c4a | 966 | float32.u = side_bswap_32(float32.u); |
8bdd5c12 MD |
967 | #endif |
968 | #if __HAVE_FLOAT64 | |
67337c4a | 969 | float64.u = side_bswap_64(float64.u); |
8bdd5c12 MD |
970 | #endif |
971 | #if __HAVE_FLOAT128 | |
67337c4a | 972 | side_bswap_128p(float128.arr); |
8bdd5c12 MD |
973 | #endif |
974 | ||
67337c4a MD |
975 | side_event_variadic(my_provider_event_variadic_float, |
976 | side_arg_list(), | |
977 | side_arg_list( | |
fb25b355 | 978 | #if __HAVE_FLOAT16 |
a82ffcff | 979 | side_arg_dynamic_field("binary16", side_arg_dynamic_float_binary16(1.1)), |
67337c4a | 980 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN |
a82ffcff MD |
981 | side_arg_dynamic_field("binary16_le", side_arg_dynamic_float_binary16_le(1.1)), |
982 | side_arg_dynamic_field("binary16_be", side_arg_dynamic_float_binary16_be(float16.f)), | |
8bdd5c12 | 983 | # else |
a82ffcff MD |
984 | side_arg_dynamic_field("binary16_le", side_arg_dynamic_float_binary16_le(float16.f)), |
985 | side_arg_dynamic_field("binary16_be", side_arg_dynamic_float_binary16_be(1.1)), | |
8bdd5c12 | 986 | # endif |
fb25b355 MD |
987 | #endif |
988 | #if __HAVE_FLOAT32 | |
a82ffcff | 989 | side_arg_dynamic_field("binary32", side_arg_dynamic_float_binary32(2.2)), |
67337c4a | 990 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN |
a82ffcff MD |
991 | side_arg_dynamic_field("binary32_le", side_arg_dynamic_float_binary32_le(2.2)), |
992 | side_arg_dynamic_field("binary32_be", side_arg_dynamic_float_binary32_be(float32.f)), | |
8bdd5c12 | 993 | # else |
a82ffcff MD |
994 | side_arg_dynamic_field("binary32_le", side_arg_dynamic_float_binary32_le(float32.f)), |
995 | side_arg_dynamic_field("binary32_be", side_arg_dynamic_float_binary32_be(2.2)), | |
8bdd5c12 | 996 | # endif |
fb25b355 MD |
997 | #endif |
998 | #if __HAVE_FLOAT64 | |
a82ffcff | 999 | side_arg_dynamic_field("binary64", side_arg_dynamic_float_binary64(3.3)), |
67337c4a | 1000 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN |
a82ffcff MD |
1001 | side_arg_dynamic_field("binary64_le", side_arg_dynamic_float_binary64_le(3.3)), |
1002 | side_arg_dynamic_field("binary64_be", side_arg_dynamic_float_binary64_be(float64.f)), | |
8bdd5c12 | 1003 | # else |
a82ffcff MD |
1004 | side_arg_dynamic_field("binary64_le", side_arg_dynamic_float_binary64_le(float64.f)), |
1005 | side_arg_dynamic_field("binary64_be", side_arg_dynamic_float_binary64_be(3.3)), | |
8bdd5c12 | 1006 | # endif |
fb25b355 MD |
1007 | #endif |
1008 | #if __HAVE_FLOAT128 | |
a82ffcff | 1009 | side_arg_dynamic_field("binary128", side_arg_dynamic_float_binary128(4.4)), |
67337c4a | 1010 | # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN |
a82ffcff MD |
1011 | side_arg_dynamic_field("binary128_le", side_arg_dynamic_float_binary128_le(4.4)), |
1012 | side_arg_dynamic_field("binary128_be", side_arg_dynamic_float_binary128_be(float128.f)), | |
8bdd5c12 | 1013 | # else |
a82ffcff MD |
1014 | side_arg_dynamic_field("binary128_le", side_arg_dynamic_float_binary128_le(float128.f)), |
1015 | side_arg_dynamic_field("binary128_be", side_arg_dynamic_float_binary128_be(4.4)), | |
8bdd5c12 | 1016 | # endif |
fb25b355 | 1017 | #endif |
a82ffcff | 1018 | ) |
fb25b355 MD |
1019 | ); |
1020 | } | |
1021 | ||
67337c4a MD |
1022 | static side_define_enum(myenum, |
1023 | side_enum_mapping_list( | |
1024 | side_enum_mapping_range("one-ten", 1, 10), | |
1025 | side_enum_mapping_range("100-200", 100, 200), | |
1026 | side_enum_mapping_value("200", 200), | |
1027 | side_enum_mapping_value("300", 300), | |
a82ffcff | 1028 | ) |
79f677ba MD |
1029 | ); |
1030 | ||
67337c4a MD |
1031 | side_static_event(my_provider_event_enum, "myprovider", "myeventenum", SIDE_LOGLEVEL_DEBUG, |
1032 | side_field_list( | |
a82ffcff MD |
1033 | side_field_enum("5", &myenum, side_elem(side_type_u32())), |
1034 | side_field_enum("400", &myenum, side_elem(side_type_u64())), | |
1035 | side_field_enum("200", &myenum, side_elem(side_type_u8())), | |
1036 | side_field_enum("-100", &myenum, side_elem(side_type_s8())), | |
1037 | side_field_enum("6_be", &myenum, side_elem(side_type_u32_be())), | |
1038 | side_field_enum("6_le", &myenum, side_elem(side_type_u32_le())), | |
1039 | ) | |
79f677ba MD |
1040 | ); |
1041 | ||
1042 | static | |
1043 | void test_enum(void) | |
1044 | { | |
67337c4a MD |
1045 | side_event(my_provider_event_enum, |
1046 | side_arg_list( | |
1047 | side_arg_u32(5), | |
1048 | side_arg_u64(400), | |
1049 | side_arg_u8(200), | |
1050 | side_arg_s8(-100), | |
1051 | #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN | |
1052 | side_arg_u32(side_bswap_32(6)), | |
1053 | side_arg_u32(6), | |
8bdd5c12 | 1054 | #else |
67337c4a MD |
1055 | side_arg_u32(6), |
1056 | side_arg_u32(side_bswap_32(6)), | |
8bdd5c12 | 1057 | #endif |
79f677ba MD |
1058 | ) |
1059 | ); | |
1060 | } | |
1061 | ||
ea32e5fc | 1062 | /* A bitmap enum maps bits to labels. */ |
67337c4a MD |
1063 | static side_define_enum_bitmap(myenum_bitmap, |
1064 | side_enum_bitmap_mapping_list( | |
1065 | side_enum_bitmap_mapping_value("0", 0), | |
1066 | side_enum_bitmap_mapping_range("1-2", 1, 2), | |
1067 | side_enum_bitmap_mapping_range("2-4", 2, 4), | |
1068 | side_enum_bitmap_mapping_value("3", 3), | |
1069 | side_enum_bitmap_mapping_value("30", 30), | |
1070 | side_enum_bitmap_mapping_value("63", 63), | |
1071 | side_enum_bitmap_mapping_range("158-160", 158, 160), | |
1072 | side_enum_bitmap_mapping_value("159", 159), | |
1073 | side_enum_bitmap_mapping_range("500-700", 500, 700), | |
a82ffcff | 1074 | ) |
ea32e5fc MD |
1075 | ); |
1076 | ||
67337c4a MD |
1077 | side_static_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitmap", SIDE_LOGLEVEL_DEBUG, |
1078 | side_field_list( | |
a82ffcff MD |
1079 | side_field_enum_bitmap("bit_0", &myenum_bitmap, side_elem(side_type_u32())), |
1080 | side_field_enum_bitmap("bit_1", &myenum_bitmap, side_elem(side_type_u32())), | |
1081 | side_field_enum_bitmap("bit_2", &myenum_bitmap, side_elem(side_type_u8())), | |
1082 | side_field_enum_bitmap("bit_3", &myenum_bitmap, side_elem(side_type_u8())), | |
1083 | side_field_enum_bitmap("bit_30", &myenum_bitmap, side_elem(side_type_u32())), | |
1084 | side_field_enum_bitmap("bit_31", &myenum_bitmap, side_elem(side_type_u32())), | |
1085 | side_field_enum_bitmap("bit_63", &myenum_bitmap, side_elem(side_type_u64())), | |
1086 | side_field_enum_bitmap("bits_1+63", &myenum_bitmap, side_elem(side_type_u64())), | |
1087 | side_field_enum_bitmap("byte_bit_2", &myenum_bitmap, side_elem(side_type_byte())), | |
67337c4a | 1088 | side_field_enum_bitmap("bit_159", &myenum_bitmap, |
a82ffcff | 1089 | side_elem(side_type_array(side_elem(side_type_u32()), 5))), |
67337c4a | 1090 | side_field_enum_bitmap("bit_159", &myenum_bitmap, |
a82ffcff MD |
1091 | side_elem(side_type_vla(side_elem(side_type_u32())))), |
1092 | side_field_enum_bitmap("bit_2_be", &myenum_bitmap, side_elem(side_type_u32_be())), | |
1093 | side_field_enum_bitmap("bit_2_le", &myenum_bitmap, side_elem(side_type_u32_le())), | |
1094 | ) | |
ea32e5fc MD |
1095 | ); |
1096 | ||
1097 | static | |
1098 | void test_enum_bitmap(void) | |
1099 | { | |
67337c4a MD |
1100 | side_event_cond(my_provider_event_enum_bitmap) { |
1101 | side_arg_define_vec(myarray, | |
1102 | side_arg_list( | |
1103 | side_arg_u32(0), | |
1104 | side_arg_u32(0), | |
1105 | side_arg_u32(0), | |
1106 | side_arg_u32(0), | |
1107 | side_arg_u32(0x80000000), /* bit 159 */ | |
af6aa6e1 MD |
1108 | ) |
1109 | ); | |
67337c4a MD |
1110 | side_event_call(my_provider_event_enum_bitmap, |
1111 | side_arg_list( | |
1112 | side_arg_u32(1U << 0), | |
1113 | side_arg_u32(1U << 1), | |
1114 | side_arg_u8(1U << 2), | |
1115 | side_arg_u8(1U << 3), | |
1116 | side_arg_u32(1U << 30), | |
1117 | side_arg_u32(1U << 31), | |
1118 | side_arg_u64(1ULL << 63), | |
1119 | side_arg_u64((1ULL << 1) | (1ULL << 63)), | |
1120 | side_arg_byte(1U << 2), | |
1121 | side_arg_array(&myarray), | |
1122 | side_arg_vla(&myarray), | |
1123 | #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN | |
1124 | side_arg_u32(side_bswap_32(1U << 2)), | |
1125 | side_arg_u32(1U << 2), | |
8bdd5c12 | 1126 | #else |
67337c4a MD |
1127 | side_arg_u32(1U << 2), |
1128 | side_arg_u32(side_bswap_32(1U << 2)), | |
8bdd5c12 | 1129 | #endif |
af6aa6e1 MD |
1130 | ) |
1131 | ); | |
1132 | } | |
ea32e5fc MD |
1133 | } |
1134 | ||
67337c4a MD |
1135 | side_static_event_variadic(my_provider_event_blob, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG, |
1136 | side_field_list( | |
a82ffcff MD |
1137 | side_field_byte("blobfield"), |
1138 | side_field_array("arrayblob", side_elem(side_type_byte()), 3), | |
1139 | ) | |
7aec0d09 MD |
1140 | ); |
1141 | ||
1142 | static | |
1143 | void test_blob(void) | |
1144 | { | |
67337c4a MD |
1145 | side_event_cond(my_provider_event_blob) { |
1146 | side_arg_define_vec(myarray, side_arg_list(side_arg_byte(1), side_arg_byte(2), side_arg_byte(3))); | |
1147 | side_arg_dynamic_define_vec(myvla, | |
1148 | side_arg_list( | |
a82ffcff MD |
1149 | side_arg_dynamic_byte(0x22), |
1150 | side_arg_dynamic_byte(0x33), | |
1151 | ) | |
199e7aa9 | 1152 | ); |
67337c4a MD |
1153 | side_event_call_variadic(my_provider_event_blob, |
1154 | side_arg_list( | |
1155 | side_arg_byte(0x55), | |
1156 | side_arg_array(&myarray), | |
199e7aa9 | 1157 | ), |
67337c4a MD |
1158 | side_arg_list( |
1159 | side_arg_dynamic_field("varblobfield", | |
a82ffcff | 1160 | side_arg_dynamic_byte(0x55) |
199e7aa9 | 1161 | ), |
67337c4a | 1162 | side_arg_dynamic_field("varblobvla", side_arg_dynamic_vla(&myvla)), |
a82ffcff | 1163 | ) |
7aec0d09 MD |
1164 | ); |
1165 | } | |
1166 | } | |
ea32e5fc | 1167 | |
67337c4a MD |
1168 | side_static_event_variadic(my_provider_event_format_string, |
1169 | "myprovider", "myeventformatstring", SIDE_LOGLEVEL_DEBUG, | |
1170 | side_field_list( | |
a82ffcff | 1171 | side_field_string("fmt"), |
71aa8975 | 1172 | ), |
67337c4a MD |
1173 | side_attr_list( |
1174 | side_attr("lang.c.format_string", side_attr_bool(true)), | |
71aa8975 MD |
1175 | ) |
1176 | ); | |
1177 | ||
1178 | static | |
1179 | void test_fmt_string(void) | |
1180 | { | |
67337c4a MD |
1181 | side_event_cond(my_provider_event_format_string) { |
1182 | side_arg_dynamic_define_vec(args, | |
1183 | side_arg_list( | |
a82ffcff MD |
1184 | side_arg_dynamic_string("blah"), |
1185 | side_arg_dynamic_s32(123), | |
1186 | ) | |
71aa8975 | 1187 | ); |
67337c4a MD |
1188 | side_event_call_variadic(my_provider_event_format_string, |
1189 | side_arg_list( | |
1190 | side_arg_string("This is a formatted string with str: %s int: %d"), | |
71aa8975 | 1191 | ), |
67337c4a MD |
1192 | side_arg_list( |
1193 | side_arg_dynamic_field("arguments", side_arg_dynamic_vla(&args)), | |
a82ffcff | 1194 | ) |
71aa8975 MD |
1195 | ); |
1196 | } | |
1197 | } | |
1198 | ||
67337c4a MD |
1199 | side_static_event_variadic(my_provider_event_endian, "myprovider", "myevent_endian", SIDE_LOGLEVEL_DEBUG, |
1200 | side_field_list( | |
a82ffcff MD |
1201 | side_field_u16_le("u16_le"), |
1202 | side_field_u32_le("u32_le"), | |
1203 | side_field_u64_le("u64_le"), | |
1204 | side_field_s16_le("s16_le"), | |
1205 | side_field_s32_le("s32_le"), | |
1206 | side_field_s64_le("s64_le"), | |
1207 | side_field_u16_be("u16_be"), | |
1208 | side_field_u32_be("u32_be"), | |
1209 | side_field_u64_be("u64_be"), | |
1210 | side_field_s16_be("s16_be"), | |
1211 | side_field_s32_be("s32_be"), | |
1212 | side_field_s64_be("s64_be"), | |
1213 | ) | |
8bdd5c12 MD |
1214 | ); |
1215 | ||
1216 | static | |
1217 | void test_endian(void) | |
1218 | { | |
67337c4a MD |
1219 | side_event_variadic(my_provider_event_endian, |
1220 | side_arg_list( | |
1221 | #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN | |
1222 | side_arg_u16(1), | |
1223 | side_arg_u32(1), | |
1224 | side_arg_u64(1), | |
1225 | side_arg_s16(1), | |
1226 | side_arg_s32(1), | |
1227 | side_arg_s64(1), | |
1228 | side_arg_u16(side_bswap_16(1)), | |
1229 | side_arg_u32(side_bswap_32(1)), | |
1230 | side_arg_u64(side_bswap_64(1)), | |
1231 | side_arg_s16(side_bswap_16(1)), | |
1232 | side_arg_s32(side_bswap_32(1)), | |
1233 | side_arg_s64(side_bswap_64(1)), | |
8bdd5c12 | 1234 | #else |
67337c4a MD |
1235 | side_arg_u16(side_bswap_16(1)), |
1236 | side_arg_u32(side_bswap_32(1)), | |
1237 | side_arg_u64(side_bswap_64(1)), | |
1238 | side_arg_s16(side_bswap_16(1)), | |
1239 | side_arg_s32(side_bswap_32(1)), | |
1240 | side_arg_s64(side_bswap_64(1)), | |
1241 | side_arg_u16(1), | |
1242 | side_arg_u32(1), | |
1243 | side_arg_u64(1), | |
1244 | side_arg_s16(1), | |
1245 | side_arg_s32(1), | |
1246 | side_arg_s64(1), | |
8bdd5c12 MD |
1247 | #endif |
1248 | ), | |
67337c4a MD |
1249 | side_arg_list( |
1250 | #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN | |
a82ffcff MD |
1251 | side_arg_dynamic_field("u16_le", side_arg_dynamic_u16_le(1)), |
1252 | side_arg_dynamic_field("u32_le", side_arg_dynamic_u32_le(1)), | |
1253 | side_arg_dynamic_field("u64_le", side_arg_dynamic_u64_le(1)), | |
1254 | side_arg_dynamic_field("s16_le", side_arg_dynamic_s16_le(1)), | |
1255 | side_arg_dynamic_field("s32_le", side_arg_dynamic_s32_le(1)), | |
1256 | side_arg_dynamic_field("s64_le", side_arg_dynamic_s64_le(1)), | |
1257 | side_arg_dynamic_field("u16_be", side_arg_dynamic_u16_be(side_bswap_16(1))), | |
1258 | side_arg_dynamic_field("u32_be", side_arg_dynamic_u32_be(side_bswap_32(1))), | |
1259 | side_arg_dynamic_field("u64_be", side_arg_dynamic_u64_be(side_bswap_64(1))), | |
1260 | side_arg_dynamic_field("s16_be", side_arg_dynamic_s16_be(side_bswap_16(1))), | |
1261 | side_arg_dynamic_field("s32_be", side_arg_dynamic_s32_be(side_bswap_32(1))), | |
1262 | side_arg_dynamic_field("s64_be", side_arg_dynamic_s64_be(side_bswap_64(1))), | |
8bdd5c12 | 1263 | #else |
a82ffcff MD |
1264 | side_arg_dynamic_field("u16_le", side_arg_dynamic_u16_le(side_bswap_16(1))), |
1265 | side_arg_dynamic_field("u32_le", side_arg_dynamic_u32_le(side_bswap_32(1))), | |
1266 | side_arg_dynamic_field("u64_le", side_arg_dynamic_u64_le(side_bswap_64(1))), | |
1267 | side_arg_dynamic_field("s16_le", side_arg_dynamic_s16_le(side_bswap_16(1))), | |
1268 | side_arg_dynamic_field("s32_le", side_arg_dynamic_s32_le(side_bswap_32(1))), | |
1269 | side_arg_dynamic_field("s64_le", side_arg_dynamic_s64_le(side_bswap_64(1))), | |
1270 | side_arg_dynamic_field("u16_be", side_arg_dynamic_u16_be(1)), | |
1271 | side_arg_dynamic_field("u32_be", side_arg_dynamic_u32_be(1)), | |
1272 | side_arg_dynamic_field("u64_be", side_arg_dynamic_u64_be(1)), | |
1273 | side_arg_dynamic_field("s16_be", side_arg_dynamic_s16_be(1)), | |
1274 | side_arg_dynamic_field("s32_be", side_arg_dynamic_s32_be(1)), | |
1275 | side_arg_dynamic_field("s64_be", side_arg_dynamic_s64_be(1)), | |
8bdd5c12 | 1276 | #endif |
a82ffcff | 1277 | ) |
8bdd5c12 MD |
1278 | ); |
1279 | } | |
1280 | ||
67337c4a MD |
1281 | side_static_event(my_provider_event_base, "myprovider", "myevent_base", SIDE_LOGLEVEL_DEBUG, |
1282 | side_field_list( | |
1283 | side_field_u8("u8base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1284 | side_field_u8("u8base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1285 | side_field_u8("u8base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1286 | side_field_u8("u8base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1287 | side_field_u16("u16base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1288 | side_field_u16("u16base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1289 | side_field_u16("u16base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1290 | side_field_u16("u16base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1291 | side_field_u32("u32base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1292 | side_field_u32("u32base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1293 | side_field_u32("u32base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1294 | side_field_u32("u32base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1295 | side_field_u64("u64base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1296 | side_field_u64("u64base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1297 | side_field_u64("u64base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1298 | side_field_u64("u64base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1299 | side_field_s8("s8base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1300 | side_field_s8("s8base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1301 | side_field_s8("s8base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1302 | side_field_s8("s8base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1303 | side_field_s16("s16base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1304 | side_field_s16("s16base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1305 | side_field_s16("s16base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1306 | side_field_s16("s16base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1307 | side_field_s32("s32base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1308 | side_field_s32("s32base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1309 | side_field_s32("s32base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1310 | side_field_s32("s32base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1311 | side_field_s64("s64base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))), | |
1312 | side_field_s64("s64base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))), | |
1313 | side_field_s64("s64base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1314 | side_field_s64("s64base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
a82ffcff | 1315 | ) |
1d9c515c MD |
1316 | ); |
1317 | ||
1318 | static | |
1319 | void test_base(void) | |
1320 | { | |
67337c4a MD |
1321 | side_event(my_provider_event_base, |
1322 | side_arg_list( | |
1323 | side_arg_u8(55), | |
1324 | side_arg_u8(55), | |
1325 | side_arg_u8(55), | |
1326 | side_arg_u8(55), | |
1327 | side_arg_u16(55), | |
1328 | side_arg_u16(55), | |
1329 | side_arg_u16(55), | |
1330 | side_arg_u16(55), | |
1331 | side_arg_u32(55), | |
1332 | side_arg_u32(55), | |
1333 | side_arg_u32(55), | |
1334 | side_arg_u32(55), | |
1335 | side_arg_u64(55), | |
1336 | side_arg_u64(55), | |
1337 | side_arg_u64(55), | |
1338 | side_arg_u64(55), | |
1339 | side_arg_s8(-55), | |
1340 | side_arg_s8(-55), | |
1341 | side_arg_s8(-55), | |
1342 | side_arg_s8(-55), | |
1343 | side_arg_s16(-55), | |
1344 | side_arg_s16(-55), | |
1345 | side_arg_s16(-55), | |
1346 | side_arg_s16(-55), | |
1347 | side_arg_s32(-55), | |
1348 | side_arg_s32(-55), | |
1349 | side_arg_s32(-55), | |
1350 | side_arg_s32(-55), | |
1351 | side_arg_s64(-55), | |
1352 | side_arg_s64(-55), | |
1353 | side_arg_s64(-55), | |
1354 | side_arg_s64(-55), | |
1d9c515c MD |
1355 | ) |
1356 | ); | |
1357 | } | |
1358 | ||
7a1cb105 MD |
1359 | struct test { |
1360 | uint32_t a; | |
1361 | uint64_t b; | |
1362 | uint8_t c; | |
1363 | int32_t d; | |
1364 | uint16_t e; | |
bc0b21eb MD |
1365 | int8_t f; |
1366 | int16_t g; | |
1367 | int32_t h; | |
1368 | int64_t i; | |
1369 | int64_t j; | |
1370 | int64_t k; | |
c1723f3c | 1371 | uint64_t test; |
7a1cb105 MD |
1372 | }; |
1373 | ||
67337c4a MD |
1374 | static side_define_struct(mystructgatherdef, |
1375 | side_field_list( | |
1376 | side_field_gather_unsigned_integer("a", offsetof(struct test, a), | |
1377 | side_struct_field_sizeof(struct test, a), 0, 0, | |
a82ffcff | 1378 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a MD |
1379 | side_field_gather_signed_integer("d", offsetof(struct test, d), |
1380 | side_struct_field_sizeof(struct test, d), 0, 0, | |
a82ffcff | 1381 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a MD |
1382 | side_field_gather_unsigned_integer("e", offsetof(struct test, e), |
1383 | side_struct_field_sizeof(struct test, e), 8, 4, | |
1384 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1385 | side_field_gather_signed_integer("f", offsetof(struct test, f), | |
1386 | side_struct_field_sizeof(struct test, f), 1, 4, | |
1387 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1388 | side_field_gather_signed_integer("g", offsetof(struct test, g), | |
1389 | side_struct_field_sizeof(struct test, g), 11, 4, | |
1390 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1391 | side_field_gather_signed_integer("h", offsetof(struct test, h), | |
1392 | side_struct_field_sizeof(struct test, h), 1, 31, | |
1393 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1394 | side_field_gather_signed_integer("i", offsetof(struct test, i), | |
1395 | side_struct_field_sizeof(struct test, i), 33, 20, | |
1396 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1397 | side_field_gather_signed_integer("j", offsetof(struct test, j), | |
1398 | side_struct_field_sizeof(struct test, j), 63, 1, | |
1399 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1400 | side_field_gather_signed_integer("k", offsetof(struct test, k), | |
1401 | side_struct_field_sizeof(struct test, k), 1, 63, | |
1402 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
1403 | side_field_gather_unsigned_integer_le("test", offsetof(struct test, test), | |
1404 | side_struct_field_sizeof(struct test, test), 0, 64, | |
1405 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1406 | side_field_gather_unsigned_integer_le("test_le", offsetof(struct test, test), | |
1407 | side_struct_field_sizeof(struct test, test), 0, 64, | |
1408 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
1409 | side_field_gather_unsigned_integer_be("test_be", offsetof(struct test, test), | |
1410 | side_struct_field_sizeof(struct test, test), 0, 64, | |
1411 | SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))), | |
a82ffcff | 1412 | ) |
7a1cb105 MD |
1413 | ); |
1414 | ||
67337c4a MD |
1415 | side_static_event(my_provider_event_structgather, "myprovider", "myeventstructgather", SIDE_LOGLEVEL_DEBUG, |
1416 | side_field_list( | |
1417 | side_field_gather_struct("structgather", &mystructgatherdef, 0, sizeof(struct test), | |
1418 | SIDE_TYPE_GATHER_ACCESS_DIRECT), | |
1419 | side_field_gather_signed_integer("intgather", 0, sizeof(int32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT, | |
1420 | side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))), | |
13d97eca | 1421 | #if __HAVE_FLOAT32 |
a82ffcff | 1422 | side_field_gather_float("f32", 0, sizeof(_Float32), SIDE_TYPE_GATHER_ACCESS_DIRECT), |
13d97eca | 1423 | #endif |
a82ffcff | 1424 | ) |
7a1cb105 MD |
1425 | ); |
1426 | ||
1427 | static | |
d41cb7ee | 1428 | void test_struct_gather(void) |
7a1cb105 | 1429 | { |
67337c4a | 1430 | side_event_cond(my_provider_event_structgather) { |
7a1cb105 MD |
1431 | struct test mystruct = { |
1432 | .a = 55, | |
1433 | .b = 123, | |
1434 | .c = 2, | |
1435 | .d = -55, | |
1436 | .e = 0xABCD, | |
bc0b21eb MD |
1437 | .f = -1, |
1438 | .g = -1, | |
1439 | .h = -1, | |
1440 | .i = -1, | |
1441 | .j = -1, | |
1442 | .k = -1, | |
c1723f3c | 1443 | .test = 0xFF, |
7a1cb105 | 1444 | }; |
33956c71 | 1445 | int32_t val = -66; |
13d97eca MD |
1446 | #if __HAVE_FLOAT32 |
1447 | _Float32 f32 = 1.1; | |
1448 | #endif | |
67337c4a MD |
1449 | side_event_call(my_provider_event_structgather, |
1450 | side_arg_list( | |
1451 | side_arg_gather_struct(&mystruct), | |
1452 | side_arg_gather_integer(&val), | |
13d97eca | 1453 | #if __HAVE_FLOAT32 |
67337c4a | 1454 | side_arg_gather_float(&f32), |
13d97eca | 1455 | #endif |
33956c71 MD |
1456 | ) |
1457 | ); | |
7a1cb105 MD |
1458 | } |
1459 | } | |
1460 | ||
7394a8b8 MD |
1461 | struct testnest2 { |
1462 | uint8_t c; | |
1463 | }; | |
1464 | ||
1465 | struct testnest1 { | |
1466 | uint64_t b; | |
1467 | struct testnest2 *nest; | |
1468 | }; | |
1469 | ||
1470 | struct testnest0 { | |
1471 | uint32_t a; | |
1472 | struct testnest1 *nest; | |
1473 | }; | |
1474 | ||
67337c4a MD |
1475 | static side_define_struct(mystructgathernest2, |
1476 | side_field_list( | |
1477 | side_field_gather_unsigned_integer("c", offsetof(struct testnest2, c), | |
1478 | side_struct_field_sizeof(struct testnest2, c), 0, 0, | |
a82ffcff MD |
1479 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
1480 | ) | |
7394a8b8 MD |
1481 | ); |
1482 | ||
67337c4a MD |
1483 | static side_define_struct(mystructgathernest1, |
1484 | side_field_list( | |
1485 | side_field_gather_unsigned_integer("b", offsetof(struct testnest1, b), | |
1486 | side_struct_field_sizeof(struct testnest1, b), 0, 0, | |
a82ffcff | 1487 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1488 | side_field_gather_struct("nest2", &mystructgathernest2, |
dd7947bf | 1489 | offsetof(struct testnest1, nest), sizeof(struct testnest2), |
67337c4a | 1490 | SIDE_TYPE_GATHER_ACCESS_POINTER), |
a82ffcff | 1491 | ) |
7394a8b8 MD |
1492 | ); |
1493 | ||
67337c4a MD |
1494 | static side_define_struct(mystructgathernest0, |
1495 | side_field_list( | |
1496 | side_field_gather_unsigned_integer("a", offsetof(struct testnest0, a), | |
1497 | side_struct_field_sizeof(struct testnest0, a), 0, 0, | |
a82ffcff | 1498 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1499 | side_field_gather_struct("nest1", &mystructgathernest1, |
dd7947bf | 1500 | offsetof(struct testnest0, nest), sizeof(struct testnest1), |
67337c4a | 1501 | SIDE_TYPE_GATHER_ACCESS_POINTER), |
a82ffcff | 1502 | ) |
7394a8b8 MD |
1503 | ); |
1504 | ||
67337c4a MD |
1505 | side_static_event(my_provider_event_structgather_nest, |
1506 | "myprovider", "myeventstructgathernest", SIDE_LOGLEVEL_DEBUG, | |
1507 | side_field_list( | |
1508 | side_field_gather_struct("nest0", &mystructgathernest0, 0, | |
1509 | sizeof(struct testnest0), SIDE_TYPE_GATHER_ACCESS_DIRECT), | |
a82ffcff | 1510 | ) |
7394a8b8 MD |
1511 | ); |
1512 | ||
1513 | static | |
d41cb7ee | 1514 | void test_struct_gather_nest_ptr(void) |
7394a8b8 | 1515 | { |
67337c4a | 1516 | side_event_cond(my_provider_event_structgather_nest) { |
7394a8b8 MD |
1517 | struct testnest2 mystruct2 = { |
1518 | .c = 77, | |
1519 | }; | |
1520 | struct testnest1 mystruct1 = { | |
1521 | .b = 66, | |
1522 | .nest = &mystruct2, | |
1523 | }; | |
1524 | struct testnest0 mystruct = { | |
1525 | .a = 55, | |
1526 | .nest = &mystruct1, | |
1527 | }; | |
67337c4a MD |
1528 | side_event_call(my_provider_event_structgather_nest, |
1529 | side_arg_list( | |
1530 | side_arg_gather_struct(&mystruct), | |
7394a8b8 MD |
1531 | ) |
1532 | ); | |
1533 | } | |
1534 | } | |
1535 | ||
905f68e3 MD |
1536 | struct testfloat { |
1537 | #if __HAVE_FLOAT16 | |
1538 | _Float16 f16; | |
1539 | #endif | |
1540 | #if __HAVE_FLOAT32 | |
1541 | _Float32 f32; | |
1542 | #endif | |
1543 | #if __HAVE_FLOAT64 | |
1544 | _Float64 f64; | |
1545 | #endif | |
1546 | #if __HAVE_FLOAT128 | |
1547 | _Float128 f128; | |
1548 | #endif | |
1549 | }; | |
1550 | ||
67337c4a MD |
1551 | static side_define_struct(mystructgatherfloat, |
1552 | side_field_list( | |
905f68e3 | 1553 | #if __HAVE_FLOAT16 |
67337c4a | 1554 | side_field_gather_float("f16", offsetof(struct testfloat, f16), side_struct_field_sizeof(struct testfloat, f16), |
a82ffcff | 1555 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
905f68e3 MD |
1556 | #endif |
1557 | #if __HAVE_FLOAT32 | |
67337c4a | 1558 | side_field_gather_float("f32", offsetof(struct testfloat, f32), side_struct_field_sizeof(struct testfloat, f32), |
a82ffcff | 1559 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
905f68e3 MD |
1560 | #endif |
1561 | #if __HAVE_FLOAT64 | |
67337c4a | 1562 | side_field_gather_float("f64", offsetof(struct testfloat, f64), side_struct_field_sizeof(struct testfloat, f64), |
a82ffcff | 1563 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
905f68e3 MD |
1564 | #endif |
1565 | #if __HAVE_FLOAT128 | |
67337c4a | 1566 | side_field_gather_float("f128", offsetof(struct testfloat, f128), side_struct_field_sizeof(struct testfloat, f128), |
a82ffcff | 1567 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
905f68e3 | 1568 | #endif |
a82ffcff | 1569 | ) |
905f68e3 MD |
1570 | ); |
1571 | ||
67337c4a MD |
1572 | side_static_event(my_provider_event_structgatherfloat, |
1573 | "myprovider", "myeventstructgatherfloat", SIDE_LOGLEVEL_DEBUG, | |
1574 | side_field_list( | |
1575 | side_field_gather_struct("structgatherfloat", &mystructgatherfloat, 0, | |
1576 | sizeof(struct testfloat), SIDE_TYPE_GATHER_ACCESS_DIRECT), | |
a82ffcff | 1577 | ) |
905f68e3 MD |
1578 | ); |
1579 | ||
1580 | static | |
d41cb7ee | 1581 | void test_struct_gather_float(void) |
905f68e3 | 1582 | { |
67337c4a | 1583 | side_event_cond(my_provider_event_structgatherfloat) { |
905f68e3 MD |
1584 | struct testfloat mystruct = { |
1585 | #if __HAVE_FLOAT16 | |
1586 | .f16 = 1.1, | |
1587 | #endif | |
1588 | #if __HAVE_FLOAT32 | |
1589 | .f32 = 2.2, | |
1590 | #endif | |
1591 | #if __HAVE_FLOAT64 | |
1592 | .f64 = 3.3, | |
1593 | #endif | |
1594 | #if __HAVE_FLOAT128 | |
1595 | .f128 = 4.4, | |
1596 | #endif | |
1597 | }; | |
67337c4a MD |
1598 | side_event_call(my_provider_event_structgatherfloat, |
1599 | side_arg_list( | |
1600 | side_arg_gather_struct(&mystruct), | |
905f68e3 MD |
1601 | ) |
1602 | ); | |
1603 | } | |
1604 | } | |
1605 | ||
d41cb7ee | 1606 | uint32_t mygatherarray[] = { 1, 2, 3, 4, 5 }; |
d9359cfa | 1607 | |
d41cb7ee | 1608 | uint16_t mygatherarray2[] = { 6, 7, 8, 9 }; |
d9359cfa MD |
1609 | |
1610 | struct testarray { | |
1611 | int a; | |
1612 | uint32_t *ptr; | |
1613 | }; | |
1614 | ||
67337c4a MD |
1615 | static side_define_struct(mystructgatherarray, |
1616 | side_field_list( | |
1617 | side_field_gather_array("array", | |
a82ffcff | 1618 | side_elem(side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
67337c4a | 1619 | SIDE_ARRAY_SIZE(mygatherarray), |
d9359cfa | 1620 | offsetof(struct testarray, ptr), |
a82ffcff MD |
1621 | SIDE_TYPE_GATHER_ACCESS_POINTER |
1622 | ), | |
1623 | ) | |
d9359cfa MD |
1624 | ); |
1625 | ||
67337c4a MD |
1626 | side_static_event(my_provider_event_structgatherarray, |
1627 | "myprovider", "myeventstructgatherarray", SIDE_LOGLEVEL_DEBUG, | |
1628 | side_field_list( | |
1629 | side_field_gather_struct("structgatherarray", &mystructgatherarray, 0, | |
1630 | sizeof(struct testarray), SIDE_TYPE_GATHER_ACCESS_DIRECT), | |
1631 | side_field_gather_array("array2", | |
a82ffcff | 1632 | side_elem(side_type_gather_unsigned_integer(0, sizeof(uint16_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
67337c4a | 1633 | SIDE_ARRAY_SIZE(mygatherarray2), 0, |
a82ffcff | 1634 | SIDE_TYPE_GATHER_ACCESS_DIRECT |
d9359cfa | 1635 | ), |
a82ffcff | 1636 | ) |
d9359cfa MD |
1637 | ); |
1638 | ||
1639 | static | |
d41cb7ee | 1640 | void test_array_gather(void) |
d9359cfa | 1641 | { |
67337c4a | 1642 | side_event_cond(my_provider_event_structgatherarray) { |
d9359cfa MD |
1643 | struct testarray mystruct = { |
1644 | .a = 55, | |
d41cb7ee | 1645 | .ptr = mygatherarray, |
d9359cfa | 1646 | }; |
67337c4a MD |
1647 | side_event_call(my_provider_event_structgatherarray, |
1648 | side_arg_list( | |
1649 | side_arg_gather_struct(&mystruct), | |
1650 | side_arg_gather_array(&mygatherarray2), | |
d9359cfa MD |
1651 | ) |
1652 | ); | |
1653 | } | |
1654 | } | |
1655 | ||
dd7947bf | 1656 | #define TESTSGNESTARRAY_LEN 4 |
d41cb7ee | 1657 | struct testgatherstructnest1 { |
dd7947bf MD |
1658 | int b; |
1659 | int c[TESTSGNESTARRAY_LEN]; | |
1660 | }; | |
1661 | ||
d41cb7ee MD |
1662 | struct testgatherstructnest0 { |
1663 | struct testgatherstructnest1 nest; | |
1664 | struct testgatherstructnest1 nestarray[2]; | |
dd7947bf MD |
1665 | int a; |
1666 | }; | |
1667 | ||
67337c4a MD |
1668 | static side_define_struct(mystructgatherstructnest1, |
1669 | side_field_list( | |
1670 | side_field_gather_signed_integer("b", offsetof(struct testgatherstructnest1, b), | |
1671 | side_struct_field_sizeof(struct testgatherstructnest1, b), 0, 0, | |
a82ffcff | 1672 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a MD |
1673 | side_field_gather_array("c", |
1674 | side_elem( | |
1675 | side_type_gather_signed_integer(0, sizeof(uint32_t), 0, 0, | |
a82ffcff | 1676 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
dd7947bf MD |
1677 | ), |
1678 | TESTSGNESTARRAY_LEN, | |
d41cb7ee | 1679 | offsetof(struct testgatherstructnest1, c), |
a82ffcff MD |
1680 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
1681 | ) | |
dd7947bf MD |
1682 | ); |
1683 | ||
67337c4a MD |
1684 | static side_define_struct(mystructgatherstructnest0, |
1685 | side_field_list( | |
1686 | side_field_gather_signed_integer("a", offsetof(struct testgatherstructnest0, a), | |
1687 | side_struct_field_sizeof(struct testgatherstructnest0, a), 0, 0, | |
a82ffcff | 1688 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1689 | side_field_gather_struct("structnest0", &mystructgatherstructnest1, |
d41cb7ee MD |
1690 | offsetof(struct testgatherstructnest0, nest), |
1691 | sizeof(struct testgatherstructnest1), | |
67337c4a MD |
1692 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
1693 | side_field_gather_array("nestarray", | |
1694 | side_elem( | |
1695 | side_type_gather_struct(&mystructgatherstructnest1, | |
dd7947bf | 1696 | 0, |
d41cb7ee | 1697 | sizeof(struct testgatherstructnest1), |
a82ffcff | 1698 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
dd7947bf MD |
1699 | ), |
1700 | 2, | |
d41cb7ee | 1701 | offsetof(struct testgatherstructnest0, nestarray), |
a82ffcff MD |
1702 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
1703 | ) | |
dd7947bf MD |
1704 | ); |
1705 | ||
67337c4a MD |
1706 | side_static_event(my_provider_event_gatherstructnest, |
1707 | "myprovider", "myeventgatherstructnest", SIDE_LOGLEVEL_DEBUG, | |
1708 | side_field_list( | |
1709 | side_field_gather_struct("structgather", &mystructgatherstructnest0, 0, | |
1710 | sizeof(struct testgatherstructnest0), SIDE_TYPE_GATHER_ACCESS_DIRECT), | |
a82ffcff | 1711 | ) |
dd7947bf MD |
1712 | ); |
1713 | ||
1714 | static | |
d41cb7ee | 1715 | void test_gather_structnest(void) |
dd7947bf | 1716 | { |
67337c4a | 1717 | side_event_cond(my_provider_event_gatherstructnest) { |
d41cb7ee | 1718 | struct testgatherstructnest0 mystruct = { |
dd7947bf MD |
1719 | .nest = { |
1720 | .b = 66, | |
1721 | .c = { 0, 1, 2, 3 }, | |
1722 | }, | |
1723 | .nestarray = { | |
1724 | [0] = { | |
1725 | .b = 77, | |
1726 | .c = { 11, 12, 13, 14 }, | |
1727 | }, | |
1728 | [1] = { | |
1729 | .b = 88, | |
1730 | .c = { 15, 16, 17, 18 }, | |
1731 | }, | |
1732 | }, | |
1733 | .a = 55, | |
1734 | }; | |
67337c4a MD |
1735 | side_event_call(my_provider_event_gatherstructnest, |
1736 | side_arg_list( | |
1737 | side_arg_gather_struct(&mystruct), | |
dd7947bf MD |
1738 | ) |
1739 | ); | |
1740 | } | |
1741 | } | |
1742 | ||
d41cb7ee | 1743 | uint32_t gathervla[] = { 1, 2, 3, 4 }; |
80429681 | 1744 | uint32_t gathervla2[] = { 5, 6, 7, 8, 9 }; |
65b8734a | 1745 | |
d41cb7ee | 1746 | struct testgathervla { |
65b8734a MD |
1747 | int a; |
1748 | uint16_t len; | |
1749 | uint32_t *p; | |
1750 | }; | |
1751 | ||
67337c4a MD |
1752 | static side_define_struct(mystructgathervla, |
1753 | side_field_list( | |
1754 | side_field_gather_signed_integer("a", offsetof(struct testgathervla, a), | |
1755 | side_struct_field_sizeof(struct testgathervla, a), 0, 0, | |
a82ffcff | 1756 | SIDE_TYPE_GATHER_ACCESS_DIRECT |
65b8734a | 1757 | ), |
67337c4a | 1758 | side_field_gather_vla("nestvla", |
a82ffcff | 1759 | side_elem(side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
d41cb7ee | 1760 | offsetof(struct testgathervla, p), |
67337c4a MD |
1761 | SIDE_TYPE_GATHER_ACCESS_POINTER, |
1762 | side_length(side_type_gather_unsigned_integer(offsetof(struct testgathervla, len), | |
a82ffcff | 1763 | sizeof(uint16_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)) |
65b8734a | 1764 | ), |
a82ffcff | 1765 | ) |
65b8734a MD |
1766 | ); |
1767 | ||
67337c4a MD |
1768 | side_static_event(my_provider_event_gathervla, |
1769 | "myprovider", "myeventgathervla", SIDE_LOGLEVEL_DEBUG, | |
1770 | side_field_list( | |
1771 | side_field_gather_struct("structgathervla", &mystructgathervla, 0, | |
1772 | sizeof(struct testgathervla), SIDE_TYPE_GATHER_ACCESS_DIRECT), | |
1773 | side_field_gather_vla("vla", | |
a82ffcff | 1774 | side_elem(side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
67337c4a | 1775 | 0, SIDE_TYPE_GATHER_ACCESS_DIRECT, |
a82ffcff | 1776 | side_length(side_type_gather_unsigned_integer(0, sizeof(uint16_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)) |
80429681 | 1777 | ), |
a82ffcff | 1778 | ) |
65b8734a MD |
1779 | ); |
1780 | ||
1781 | static | |
d41cb7ee | 1782 | void test_gather_vla(void) |
65b8734a | 1783 | { |
67337c4a | 1784 | side_event_cond(my_provider_event_gathervla) { |
d41cb7ee | 1785 | struct testgathervla mystruct = { |
65b8734a | 1786 | .a = 55, |
67337c4a | 1787 | .len = SIDE_ARRAY_SIZE(gathervla), |
d41cb7ee | 1788 | .p = gathervla, |
65b8734a | 1789 | }; |
80429681 | 1790 | uint16_t vla2_len = 5; |
67337c4a MD |
1791 | side_event_call(my_provider_event_gathervla, |
1792 | side_arg_list( | |
1793 | side_arg_gather_struct(&mystruct), | |
1794 | side_arg_gather_vla(gathervla2, &vla2_len), | |
65b8734a MD |
1795 | ) |
1796 | ); | |
1797 | } | |
1798 | } | |
1799 | ||
d41cb7ee | 1800 | struct testgathervlaflex { |
65b8734a MD |
1801 | uint8_t len; |
1802 | uint32_t otherfield; | |
1803 | uint64_t array[]; | |
1804 | }; | |
1805 | ||
67337c4a MD |
1806 | static side_define_struct(mystructgathervlaflex, |
1807 | side_field_list( | |
1808 | side_field_gather_vla("vlaflex", | |
a82ffcff | 1809 | side_elem(side_type_gather_unsigned_integer(0, sizeof(uint64_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
d41cb7ee | 1810 | offsetof(struct testgathervlaflex, array), |
67337c4a MD |
1811 | SIDE_TYPE_GATHER_ACCESS_DIRECT, |
1812 | side_length(side_type_gather_unsigned_integer(offsetof(struct testgathervlaflex, len), | |
a82ffcff | 1813 | side_struct_field_sizeof(struct testgathervlaflex, len), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)) |
65b8734a | 1814 | ), |
a82ffcff | 1815 | ) |
65b8734a MD |
1816 | ); |
1817 | ||
67337c4a MD |
1818 | side_static_event(my_provider_event_gathervlaflex, |
1819 | "myprovider", "myeventgathervlaflex", SIDE_LOGLEVEL_DEBUG, | |
1820 | side_field_list( | |
1821 | side_field_gather_struct("structgathervlaflex", &mystructgathervlaflex, 0, | |
a82ffcff MD |
1822 | sizeof(struct testgathervlaflex), SIDE_TYPE_GATHER_ACCESS_DIRECT) |
1823 | ) | |
65b8734a MD |
1824 | ); |
1825 | ||
1826 | #define VLAFLEXLEN 6 | |
1827 | static | |
d41cb7ee | 1828 | void test_gather_vla_flex(void) |
65b8734a | 1829 | { |
67337c4a | 1830 | side_event_cond(my_provider_event_gathervlaflex) { |
358281a1 | 1831 | struct testgathervlaflex *mystruct = |
150b5c1d | 1832 | (struct testgathervlaflex *) malloc(sizeof(*mystruct) + VLAFLEXLEN * sizeof(uint64_t)); |
65b8734a MD |
1833 | |
1834 | mystruct->len = VLAFLEXLEN; | |
1835 | mystruct->otherfield = 0; | |
1836 | mystruct->array[0] = 1; | |
1837 | mystruct->array[1] = 2; | |
1838 | mystruct->array[2] = 3; | |
1839 | mystruct->array[3] = 4; | |
1840 | mystruct->array[4] = 5; | |
1841 | mystruct->array[5] = 6; | |
67337c4a MD |
1842 | side_event_call(my_provider_event_gathervlaflex, |
1843 | side_arg_list( | |
1844 | side_arg_gather_struct(mystruct), | |
65b8734a MD |
1845 | ) |
1846 | ); | |
1847 | free(mystruct); | |
1848 | } | |
1849 | } | |
1850 | ||
67337c4a MD |
1851 | side_static_event(my_provider_event_gatherbyte, |
1852 | "myprovider", "myeventgatherbyte", SIDE_LOGLEVEL_DEBUG, | |
1853 | side_field_list( | |
a82ffcff | 1854 | side_field_gather_byte("byte", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1855 | side_field_gather_array("array", |
a82ffcff MD |
1856 | side_elem(side_type_gather_byte(0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
1857 | 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT | |
d69918cc | 1858 | ), |
a82ffcff | 1859 | ) |
d69918cc MD |
1860 | ); |
1861 | ||
1862 | static | |
1863 | void test_gather_byte(void) | |
1864 | { | |
67337c4a | 1865 | side_event_cond(my_provider_event_gatherbyte) { |
d69918cc MD |
1866 | uint8_t v = 0x44; |
1867 | uint8_t array[3] = { 0x1, 0x2, 0x3 }; | |
1868 | ||
67337c4a MD |
1869 | side_event_call(my_provider_event_gatherbyte, |
1870 | side_arg_list( | |
1871 | side_arg_gather_byte(&v), | |
1872 | side_arg_gather_array(array), | |
d69918cc MD |
1873 | ) |
1874 | ); | |
1875 | } | |
1876 | } | |
1877 | ||
8ad2f385 MD |
1878 | #define ARRAYBOOLLEN 4 |
1879 | static bool arraybool[ARRAYBOOLLEN] = { false, true, false, true }; | |
1880 | ||
67337c4a MD |
1881 | side_static_event(my_provider_event_gatherbool, |
1882 | "myprovider", "myeventgatherbool", SIDE_LOGLEVEL_DEBUG, | |
1883 | side_field_list( | |
1884 | side_field_gather_bool("v1_true", 0, sizeof(bool), 0, 0, | |
a82ffcff | 1885 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1886 | side_field_gather_bool("v2_false", 0, sizeof(bool), 0, 0, |
a82ffcff | 1887 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1888 | side_field_gather_bool("v3_true", 0, sizeof(uint16_t), 1, 1, |
a82ffcff | 1889 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1890 | side_field_gather_bool("v4_false", 0, sizeof(uint16_t), 1, 1, |
a82ffcff | 1891 | SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a MD |
1892 | side_field_gather_array("arraybool", |
1893 | side_elem(side_type_gather_bool(0, sizeof(bool), 0, 0, | |
a82ffcff MD |
1894 | SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
1895 | ARRAYBOOLLEN, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT | |
8ad2f385 | 1896 | ), |
a82ffcff | 1897 | ) |
8ad2f385 MD |
1898 | ); |
1899 | ||
1900 | static | |
1901 | void test_gather_bool(void) | |
1902 | { | |
67337c4a | 1903 | side_event_cond(my_provider_event_structgatherarray) { |
8ad2f385 MD |
1904 | bool v1 = true; |
1905 | bool v2 = false; | |
1906 | uint16_t v3 = 1U << 1; | |
1907 | uint16_t v4 = 1U << 2; | |
1908 | ||
67337c4a MD |
1909 | side_event_call(my_provider_event_gatherbool, |
1910 | side_arg_list( | |
1911 | side_arg_gather_bool(&v1), | |
1912 | side_arg_gather_bool(&v2), | |
1913 | side_arg_gather_bool(&v3), | |
1914 | side_arg_gather_bool(&v4), | |
1915 | side_arg_gather_array(arraybool), | |
8ad2f385 MD |
1916 | ) |
1917 | ); | |
1918 | } | |
1919 | } | |
1920 | ||
67337c4a MD |
1921 | side_static_event(my_provider_event_gatherpointer, |
1922 | "myprovider", "myeventgatherpointer", SIDE_LOGLEVEL_DEBUG, | |
1923 | side_field_list( | |
a82ffcff | 1924 | side_field_gather_pointer("ptr", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 1925 | side_field_gather_array("array", |
a82ffcff MD |
1926 | side_elem(side_type_gather_pointer(0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
1927 | 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT | |
4e1b0e0e | 1928 | ), |
a82ffcff | 1929 | ) |
4e1b0e0e MD |
1930 | ); |
1931 | ||
1932 | static | |
1933 | void test_gather_pointer(void) | |
1934 | { | |
67337c4a | 1935 | side_event_cond(my_provider_event_structgatherarray) { |
4e1b0e0e MD |
1936 | void *v = (void *)0x44; |
1937 | void *array[3] = { (void *)0x1, (void *)0x2, (void *)0x3 }; | |
1938 | ||
67337c4a MD |
1939 | side_event_call(my_provider_event_gatherpointer, |
1940 | side_arg_list( | |
1941 | side_arg_gather_pointer(&v), | |
1942 | side_arg_gather_array(array), | |
4e1b0e0e MD |
1943 | ) |
1944 | ); | |
1945 | } | |
1946 | } | |
0519cb86 | 1947 | |
67337c4a MD |
1948 | static side_define_enum(myenumgather, |
1949 | side_enum_mapping_list( | |
1950 | side_enum_mapping_range("one-ten", 1, 10), | |
1951 | side_enum_mapping_range("100-200", 100, 200), | |
1952 | side_enum_mapping_value("200", 200), | |
1953 | side_enum_mapping_value("300", 300), | |
a82ffcff | 1954 | ) |
0519cb86 MD |
1955 | ); |
1956 | ||
67337c4a MD |
1957 | side_static_event(my_provider_event_enum_gather, "myprovider", "myeventenumgather", SIDE_LOGLEVEL_DEBUG, |
1958 | side_field_list( | |
1959 | side_field_gather_enum("5", &myenumgather, | |
1960 | side_elem( | |
1961 | side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0, | |
a82ffcff | 1962 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
0519cb86 MD |
1963 | ) |
1964 | ), | |
67337c4a MD |
1965 | side_field_gather_enum("400", &myenumgather, |
1966 | side_elem( | |
1967 | side_type_gather_unsigned_integer(0, sizeof(uint64_t), 0, 0, | |
a82ffcff | 1968 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
0519cb86 MD |
1969 | ) |
1970 | ), | |
67337c4a MD |
1971 | side_field_gather_enum("200", &myenumgather, |
1972 | side_elem( | |
1973 | side_type_gather_unsigned_integer(0, sizeof(uint8_t), 0, 0, | |
a82ffcff | 1974 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
0519cb86 MD |
1975 | ) |
1976 | ), | |
67337c4a MD |
1977 | side_field_gather_enum("-100", &myenumgather, |
1978 | side_elem( | |
1979 | side_type_gather_signed_integer(0, sizeof(int8_t), 0, 0, | |
a82ffcff | 1980 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
0519cb86 MD |
1981 | ) |
1982 | ), | |
67337c4a MD |
1983 | side_field_gather_enum("6_be", &myenumgather, |
1984 | side_elem( | |
1985 | side_type_gather_unsigned_integer_be(0, sizeof(uint32_t), 0, 0, | |
a82ffcff | 1986 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
0519cb86 MD |
1987 | ) |
1988 | ), | |
67337c4a MD |
1989 | side_field_gather_enum("6_le", &myenumgather, |
1990 | side_elem( | |
1991 | side_type_gather_unsigned_integer_le(0, sizeof(uint32_t), 0, 0, | |
a82ffcff | 1992 | SIDE_TYPE_GATHER_ACCESS_DIRECT) |
0519cb86 MD |
1993 | ) |
1994 | ), | |
a82ffcff | 1995 | ) |
0519cb86 MD |
1996 | ); |
1997 | ||
1998 | static | |
1999 | void test_gather_enum(void) | |
2000 | { | |
2001 | uint32_t v1 = 5; | |
2002 | uint64_t v2 = 400; | |
2003 | uint8_t v3 = 200; | |
2004 | int8_t v4 = -100; | |
67337c4a MD |
2005 | #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN |
2006 | uint32_t v5 = side_bswap_32(6); | |
0519cb86 MD |
2007 | uint32_t v6 = 6; |
2008 | #else | |
2009 | uint32_t v5 = 6; | |
67337c4a | 2010 | uint32_t v6 = side_bswap_32(6); |
0519cb86 MD |
2011 | #endif |
2012 | ||
67337c4a MD |
2013 | side_event(my_provider_event_enum_gather, |
2014 | side_arg_list( | |
2015 | side_arg_gather_integer(&v1), | |
2016 | side_arg_gather_integer(&v2), | |
2017 | side_arg_gather_integer(&v3), | |
2018 | side_arg_gather_integer(&v4), | |
2019 | side_arg_gather_integer(&v5), | |
2020 | side_arg_gather_integer(&v6), | |
0519cb86 MD |
2021 | ) |
2022 | ); | |
2023 | } | |
2024 | ||
67337c4a MD |
2025 | side_static_event(my_provider_event_gatherstring, |
2026 | "myprovider", "myeventgatherstring", SIDE_LOGLEVEL_DEBUG, | |
2027 | side_field_list( | |
a82ffcff | 2028 | side_field_gather_string("string", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT), |
67337c4a | 2029 | side_field_gather_array("arrayptr", |
a82ffcff MD |
2030 | side_elem(side_type_gather_string(0, SIDE_TYPE_GATHER_ACCESS_POINTER)), |
2031 | 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT | |
7d34edfc | 2032 | ), |
67337c4a | 2033 | side_field_gather_array("array", |
a82ffcff MD |
2034 | side_elem(side_type_gather_string(0, SIDE_TYPE_GATHER_ACCESS_DIRECT)), |
2035 | 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT | |
7d34edfc | 2036 | ), |
a82ffcff | 2037 | ) |
7d34edfc MD |
2038 | ); |
2039 | ||
2040 | static | |
2041 | void test_gather_string(void) | |
2042 | { | |
67337c4a | 2043 | side_event_cond(my_provider_event_gatherstring) { |
9365e936 MJ |
2044 | const char *str1 = "abcdef"; |
2045 | const char *ptrarray[3] = { | |
7d34edfc MD |
2046 | "abc", |
2047 | "def", | |
2048 | "ghi", | |
2049 | }; | |
2050 | char flatarray[] = { 'a', 'b', '\0', 'c', 'd', '\0', 'e', 'f', '\0' }; | |
2051 | ||
67337c4a MD |
2052 | side_event_call(my_provider_event_gatherstring, |
2053 | side_arg_list( | |
2054 | side_arg_gather_string(str1), | |
2055 | side_arg_gather_array(ptrarray), | |
2056 | side_arg_gather_array(flatarray), | |
7d34edfc MD |
2057 | ) |
2058 | ); | |
2059 | } | |
2060 | } | |
2061 | ||
67337c4a MD |
2062 | side_static_event(my_provider_event_str_utf, "myprovider", "myevent_str_utf", SIDE_LOGLEVEL_DEBUG, |
2063 | side_field_list( | |
a82ffcff MD |
2064 | side_field_string("utf8"), |
2065 | side_field_string32("utf32"), | |
2066 | side_field_string16("utf16"), | |
2067 | side_field_string32_le("utf32_le"), | |
2068 | side_field_string16_le("utf16_le"), | |
2069 | side_field_string32_be("utf32_be"), | |
2070 | side_field_string16_be("utf16_be"), | |
67337c4a | 2071 | side_field_dynamic("dynamic_utf32"), |
a82ffcff MD |
2072 | side_field_gather_string32("gather_utf32", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT), |
2073 | ) | |
52990f65 MD |
2074 | ); |
2075 | ||
2076 | static | |
2077 | void test_string_utf(void) | |
2078 | { | |
2079 | /* | |
2080 | * Character '®' is: | |
2081 | * UTF-8: \c2 \ae | |
2082 | * UTF-16: U+00ae | |
2083 | * UTF-32: U+000000ae | |
2084 | */ | |
2085 | uint8_t str8[] = { 0xc2, 0xae, 'a', 'b', 'c', 0 }; | |
2086 | uint32_t str32[] = { 0x000000ae, 'a', 'b', 'c', 0 }; | |
2087 | uint16_t str16[] = { 0x00ae, 'a', 'b', 'c', 0 }; | |
67337c4a | 2088 | #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN |
52990f65 MD |
2089 | uint32_t str32_le[] = { 0x000000ae, 'a', 'b', 'c', 0 }; |
2090 | uint16_t str16_le[] = { 0x00ae, 'a', 'b', 'c', 0 }; | |
67337c4a MD |
2091 | uint32_t str32_be[] = { side_bswap_32(0x000000ae), side_bswap_32('a'), side_bswap_32('b'), side_bswap_32('c'), 0 }; |
2092 | uint16_t str16_be[] = { side_bswap_16(0x00ae), side_bswap_16('a'), side_bswap_16('b'), side_bswap_16('c'), 0 }; | |
52990f65 | 2093 | #else |
67337c4a MD |
2094 | uint32_t str32_le[] = { side_bswap_32(0x000000ae), side_bswap_32('a'), side_bswap_32('b'), side_bswap_32('c'), 0 }; |
2095 | uint16_t str16_le[] = { side_bswap_16(0x00ae), side_bswap_16('a'), side_bswap_16('b'), side_bswap_16('c'), 0 }; | |
52990f65 MD |
2096 | uint32_t str32_be[] = { 0x000000ae, 'a', 'b', 'c', 0 }; |
2097 | uint16_t str16_be[] = { 0x00ae, 'a', 'b', 'c', 0 }; | |
2098 | #endif | |
2099 | ||
67337c4a MD |
2100 | side_event(my_provider_event_str_utf, |
2101 | side_arg_list( | |
2102 | side_arg_string(str8), | |
2103 | side_arg_string32(str32), | |
2104 | side_arg_string16(str16), | |
2105 | side_arg_string32(str32_le), | |
2106 | side_arg_string16(str16_le), | |
2107 | side_arg_string32(str32_be), | |
2108 | side_arg_string16(str16_be), | |
a82ffcff | 2109 | side_arg_dynamic_string32(str32), |
67337c4a | 2110 | side_arg_gather_string(str32), |
52990f65 MD |
2111 | ) |
2112 | ); | |
2113 | } | |
2114 | ||
5530345d | 2115 | static side_define_variant(myvariantdef, |
a82ffcff | 2116 | side_type_u32(), |
5530345d | 2117 | side_option_list( |
a82ffcff MD |
2118 | side_option_range(1, 3, side_type_u16()), |
2119 | side_option(5, side_type_string()), | |
2120 | ) | |
5530345d MD |
2121 | ); |
2122 | ||
2123 | side_static_event(my_provider_event_variant, "myprovider", "myeventvariant", SIDE_LOGLEVEL_DEBUG, | |
2124 | side_field_list( | |
2125 | side_field_variant("variant1", &myvariantdef), | |
2126 | side_field_variant("variant2", &myvariantdef), | |
a82ffcff MD |
2127 | side_field_u8("z"), |
2128 | ) | |
5530345d MD |
2129 | ); |
2130 | ||
2131 | static | |
2132 | void test_variant(void) | |
2133 | { | |
2134 | side_event_cond(my_provider_event_variant) { | |
2135 | side_arg_define_variant(myvariant1, side_arg_u32(2), side_arg_u16(4)); | |
2136 | side_arg_define_variant(myvariant2, side_arg_u32(5), side_arg_string("abc")); | |
2137 | ||
2138 | side_event_call(my_provider_event_variant, | |
2139 | side_arg_list( | |
2140 | side_arg_variant(&myvariant1), | |
2141 | side_arg_variant(&myvariant2), | |
2142 | side_arg_u8(55), | |
2143 | ) | |
2144 | ); | |
2145 | } | |
2146 | } | |
2147 | ||
f611d0c3 MD |
2148 | int main() |
2149 | { | |
2150 | test_fields(); | |
89747802 MD |
2151 | test_event_hidden(); |
2152 | test_event_export(); | |
c7a14585 | 2153 | test_struct_literal(); |
f611d0c3 MD |
2154 | test_struct(); |
2155 | test_array(); | |
2156 | test_vla(); | |
2157 | test_vla_visitor(); | |
cdd6e858 | 2158 | test_vla_visitor_2d(); |
a2e2357e MD |
2159 | test_dynamic_basic_type(); |
2160 | test_dynamic_vla(); | |
465e5e7e | 2161 | test_dynamic_null(); |
c208889e MD |
2162 | test_dynamic_struct(); |
2163 | test_dynamic_nested_struct(); | |
2164 | test_dynamic_vla_struct(); | |
2165 | test_dynamic_struct_vla(); | |
948e3e72 | 2166 | test_dynamic_nested_vla(); |
19fa6aa2 | 2167 | test_variadic(); |
41c4d119 | 2168 | test_static_variadic(); |
4f40d951 MD |
2169 | test_bool(); |
2170 | test_dynamic_bool(); | |
8ceca0cd | 2171 | test_dynamic_vla_with_visitor(); |
2b359235 | 2172 | test_dynamic_struct_with_visitor(); |
65010f43 | 2173 | test_event_user_attribute(); |
a848763d | 2174 | test_field_user_attribute(); |
808bd9bf MD |
2175 | test_variadic_attr(); |
2176 | test_variadic_vla_attr(); | |
2177 | test_variadic_struct_attr(); | |
fb25b355 MD |
2178 | test_float(); |
2179 | test_variadic_float(); | |
79f677ba | 2180 | test_enum(); |
ea32e5fc | 2181 | test_enum_bitmap(); |
7aec0d09 | 2182 | test_blob(); |
71aa8975 | 2183 | test_fmt_string(); |
8bdd5c12 | 2184 | test_endian(); |
1d9c515c | 2185 | test_base(); |
d41cb7ee MD |
2186 | test_struct_gather(); |
2187 | test_struct_gather_nest_ptr(); | |
2188 | test_struct_gather_float(); | |
2189 | test_array_gather(); | |
2190 | test_gather_structnest(); | |
2191 | test_gather_vla(); | |
2192 | test_gather_vla_flex(); | |
d69918cc | 2193 | test_gather_byte(); |
8ad2f385 | 2194 | test_gather_bool(); |
4e1b0e0e | 2195 | test_gather_pointer(); |
0519cb86 | 2196 | test_gather_enum(); |
7d34edfc | 2197 | test_gather_string(); |
52990f65 | 2198 | test_string_utf(); |
5530345d | 2199 | test_variant(); |
f611d0c3 MD |
2200 | return 0; |
2201 | } |