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