Implement nested scatter-gather struct
[libside.git] / src / 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 #include "tracer.h"
15
16 /* User code example */
17
18 side_static_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG,
19 side_field_list(
20 side_field_u32("abc", side_attr_list()),
21 side_field_s64("def", side_attr_list()),
22 side_field_pointer("ptr", side_attr_list()),
23 side_field_dynamic("dynamic"),
24 side_field_dynamic("dynamic_pointer"),
25 side_field_null("null", side_attr_list()),
26 ),
27 side_attr_list()
28 );
29
30 static
31 void test_fields(void)
32 {
33 uint32_t uw = 42;
34 int64_t sdw = -500;
35
36 side_event(my_provider_event,
37 side_arg_list(
38 side_arg_u32(uw),
39 side_arg_s64(sdw),
40 side_arg_pointer((void *) 0x1),
41 side_arg_dynamic_string("zzz", side_attr_list()),
42 side_arg_dynamic_pointer((void *) 0x1, side_attr_list()),
43 side_arg_null(),
44 )
45 );
46 }
47
48 side_hidden_event(my_provider_event_hidden, "myprovider", "myeventhidden", SIDE_LOGLEVEL_DEBUG,
49 side_field_list(
50 side_field_u32("abc", side_attr_list()),
51 ),
52 side_attr_list()
53 );
54
55 static
56 void test_event_hidden(void)
57 {
58 side_event(my_provider_event_hidden, side_arg_list(side_arg_u32(2)));
59 }
60
61 side_declare_event(my_provider_event_export);
62
63 side_export_event(my_provider_event_export, "myprovider", "myeventexport", SIDE_LOGLEVEL_DEBUG,
64 side_field_list(
65 side_field_u32("abc", side_attr_list()),
66 ),
67 side_attr_list()
68 );
69
70 static
71 void test_event_export(void)
72 {
73 side_event(my_provider_event_export, side_arg_list(side_arg_u32(2)));
74 }
75
76 side_static_event(my_provider_event_struct_literal, "myprovider", "myeventstructliteral", SIDE_LOGLEVEL_DEBUG,
77 side_field_list(
78 side_field_struct("structliteral",
79 side_struct_literal(
80 side_field_list(
81 side_field_u32("x", side_attr_list()),
82 side_field_s64("y", side_attr_list()),
83 ),
84 side_attr_list()
85 )
86 ),
87 side_field_u8("z", side_attr_list()),
88 ),
89 side_attr_list()
90 );
91
92 static
93 void test_struct_literal(void)
94 {
95 side_event_cond(my_provider_event_struct_literal) {
96 side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
97 side_event_call(my_provider_event_struct_literal, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55)));
98 }
99 }
100
101 static side_define_struct(mystructdef,
102 side_field_list(
103 side_field_u32("x", side_attr_list()),
104 side_field_s64("y", side_attr_list()),
105 ),
106 side_attr_list()
107 );
108
109 side_static_event(my_provider_event_struct, "myprovider", "myeventstruct", SIDE_LOGLEVEL_DEBUG,
110 side_field_list(
111 side_field_struct("struct", &mystructdef),
112 side_field_u8("z", side_attr_list()),
113 ),
114 side_attr_list()
115 );
116
117 static
118 void test_struct(void)
119 {
120 side_event_cond(my_provider_event_struct) {
121 side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
122 side_event_call(my_provider_event_struct, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55)));
123 }
124 }
125
126 side_static_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG,
127 side_field_list(
128 side_field_array("arr", side_elem(side_type_u32(side_attr_list())), 3, side_attr_list()),
129 side_field_s64("v", side_attr_list()),
130 ),
131 side_attr_list()
132 );
133
134 static
135 void test_array(void)
136 {
137 side_event_cond(my_provider_event_array) {
138 side_arg_define_vec(myarray, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
139 side_event_call(my_provider_event_array, side_arg_list(side_arg_array(&myarray), side_arg_s64(42)));
140 }
141 }
142
143 side_static_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG,
144 side_field_list(
145 side_field_vla("vla", side_elem(side_type_u32(side_attr_list())), side_attr_list()),
146 side_field_s64("v", side_attr_list()),
147 ),
148 side_attr_list()
149 );
150
151 static
152 void test_vla(void)
153 {
154 side_event_cond(my_provider_event_vla) {
155 side_arg_define_vec(myvla, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
156 side_event_call(my_provider_event_vla, side_arg_list(side_arg_vla(&myvla), side_arg_s64(42)));
157 }
158 }
159
160 /* 1D array visitor */
161
162 struct app_visitor_ctx {
163 const uint32_t *ptr;
164 uint32_t length;
165 };
166
167 static
168 enum side_visitor_status test_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
169 {
170 struct app_visitor_ctx *ctx = (struct app_visitor_ctx *) _ctx;
171 uint32_t length = ctx->length, i;
172
173 for (i = 0; i < length; i++) {
174 const struct side_arg elem = side_arg_u32(ctx->ptr[i]);
175
176 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
177 return SIDE_VISITOR_STATUS_ERROR;
178 }
179 return SIDE_VISITOR_STATUS_OK;
180 }
181
182 static uint32_t testarray[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
183
184 side_static_event(my_provider_event_vla_visitor, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG,
185 side_field_list(
186 side_field_vla_visitor("vlavisit", side_elem(side_type_u32(side_attr_list())), test_visitor, side_attr_list()),
187 side_field_s64("v", side_attr_list()),
188 ),
189 side_attr_list()
190 );
191
192 static
193 void test_vla_visitor(void)
194 {
195 side_event_cond(my_provider_event_vla_visitor) {
196 struct app_visitor_ctx ctx = {
197 .ptr = testarray,
198 .length = SIDE_ARRAY_SIZE(testarray),
199 };
200 side_event_call(my_provider_event_vla_visitor, side_arg_list(side_arg_vla_visitor(&ctx), side_arg_s64(42)));
201 }
202 }
203
204 /* 2D array visitor */
205
206 struct app_visitor_2d_inner_ctx {
207 const uint32_t *ptr;
208 uint32_t length;
209 };
210
211 static
212 enum side_visitor_status test_inner_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
213 {
214 struct app_visitor_2d_inner_ctx *ctx = (struct app_visitor_2d_inner_ctx *) _ctx;
215 uint32_t length = ctx->length, i;
216
217 for (i = 0; i < length; i++) {
218 const struct side_arg elem = side_arg_u32(ctx->ptr[i]);
219
220 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
221 return SIDE_VISITOR_STATUS_ERROR;
222 }
223 return SIDE_VISITOR_STATUS_OK;
224 }
225
226 struct app_visitor_2d_outer_ctx {
227 const uint32_t (*ptr)[2];
228 uint32_t length;
229 };
230
231 static
232 enum side_visitor_status test_outer_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
233 {
234 struct app_visitor_2d_outer_ctx *ctx = (struct app_visitor_2d_outer_ctx *) _ctx;
235 uint32_t length = ctx->length, i;
236
237 for (i = 0; i < length; i++) {
238 struct app_visitor_2d_inner_ctx inner_ctx = {
239 .ptr = ctx->ptr[i],
240 .length = 2,
241 };
242 const struct side_arg elem = side_arg_vla_visitor(&inner_ctx);
243 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
244 return SIDE_VISITOR_STATUS_ERROR;
245 }
246 return SIDE_VISITOR_STATUS_OK;
247 }
248
249 static uint32_t testarray2d[][2] = {
250 { 1, 2 },
251 { 33, 44 },
252 { 55, 66 },
253 };
254
255 side_static_event(my_provider_event_vla_visitor2d, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG,
256 side_field_list(
257 side_field_vla_visitor("vlavisit2d",
258 side_elem(
259 side_type_vla_visitor(
260 side_elem(side_type_u32(side_attr_list())),
261 test_inner_visitor,
262 side_attr_list())
263 ), test_outer_visitor, side_attr_list()),
264 side_field_s64("v", side_attr_list()),
265 ),
266 side_attr_list()
267 );
268
269 static
270 void test_vla_visitor_2d(void)
271 {
272 side_event_cond(my_provider_event_vla_visitor2d) {
273 struct app_visitor_2d_outer_ctx ctx = {
274 .ptr = testarray2d,
275 .length = SIDE_ARRAY_SIZE(testarray2d),
276 };
277 side_event_call(my_provider_event_vla_visitor2d, side_arg_list(side_arg_vla_visitor(&ctx), side_arg_s64(42)));
278 }
279 }
280
281 static int64_t array_fixint[] = { -444, 555, 123, 2897432587 };
282
283 side_static_event(my_provider_event_array_fixint, "myprovider", "myarrayfixint", SIDE_LOGLEVEL_DEBUG,
284 side_field_list(
285 side_field_array("arrfixint", side_elem(side_type_s64(side_attr_list())), SIDE_ARRAY_SIZE(array_fixint), side_attr_list()),
286 side_field_s64("v", side_attr_list()),
287 ),
288 side_attr_list()
289 );
290
291 static
292 void test_array_fixint(void)
293 {
294 side_event(my_provider_event_array_fixint,
295 side_arg_list(side_arg_array_s64(array_fixint), side_arg_s64(42)));
296 }
297
298 static int64_t vla_fixint[] = { -444, 555, 123, 2897432587 };
299
300 side_static_event(my_provider_event_vla_fixint, "myprovider", "myvlafixint", SIDE_LOGLEVEL_DEBUG,
301 side_field_list(
302 side_field_vla("vlafixint", side_elem(side_type_s64(side_attr_list())), side_attr_list()),
303 side_field_s64("v", side_attr_list()),
304 ),
305 side_attr_list()
306 );
307
308 static
309 void test_vla_fixint(void)
310 {
311 side_event(my_provider_event_vla_fixint,
312 side_arg_list(side_arg_vla_s64(vla_fixint, SIDE_ARRAY_SIZE(vla_fixint)), side_arg_s64(42)));
313 }
314
315 side_static_event(my_provider_event_dynamic_basic,
316 "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG,
317 side_field_list(
318 side_field_dynamic("dynamic"),
319 ),
320 side_attr_list()
321 );
322
323 static
324 void test_dynamic_basic_type(void)
325 {
326 side_event(my_provider_event_dynamic_basic,
327 side_arg_list(side_arg_dynamic_s16(-33, side_attr_list())));
328 }
329
330 side_static_event(my_provider_event_dynamic_vla,
331 "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG,
332 side_field_list(
333 side_field_dynamic("dynamic"),
334 ),
335 side_attr_list()
336 );
337
338 static
339 void test_dynamic_vla(void)
340 {
341 side_arg_dynamic_define_vec(myvla,
342 side_arg_list(
343 side_arg_dynamic_u32(1, side_attr_list()),
344 side_arg_dynamic_u32(2, side_attr_list()),
345 side_arg_dynamic_u32(3, side_attr_list()),
346 ),
347 side_attr_list()
348 );
349 side_event(my_provider_event_dynamic_vla,
350 side_arg_list(side_arg_dynamic_vla(&myvla)));
351 }
352
353 side_static_event(my_provider_event_dynamic_null,
354 "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG,
355 side_field_list(
356 side_field_dynamic("dynamic"),
357 ),
358 side_attr_list()
359 );
360
361 static
362 void test_dynamic_null(void)
363 {
364 side_event(my_provider_event_dynamic_null,
365 side_arg_list(side_arg_dynamic_null(side_attr_list())));
366 }
367
368 side_static_event(my_provider_event_dynamic_struct,
369 "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG,
370 side_field_list(
371 side_field_dynamic("dynamic"),
372 ),
373 side_attr_list()
374 );
375
376 static
377 void test_dynamic_struct(void)
378 {
379 side_arg_dynamic_define_struct(mystruct,
380 side_arg_list(
381 side_arg_dynamic_field("a", side_arg_dynamic_u32(43, side_attr_list())),
382 side_arg_dynamic_field("b", side_arg_dynamic_string("zzz", side_attr_list())),
383 side_arg_dynamic_field("c", side_arg_dynamic_null(side_attr_list())),
384 ),
385 side_attr_list()
386 );
387
388 side_event(my_provider_event_dynamic_struct,
389 side_arg_list(side_arg_dynamic_struct(&mystruct)));
390 }
391
392 side_static_event(my_provider_event_dynamic_nested_struct,
393 "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG,
394 side_field_list(
395 side_field_dynamic("dynamic"),
396 ),
397 side_attr_list()
398 );
399
400 static
401 void test_dynamic_nested_struct(void)
402 {
403 side_arg_dynamic_define_struct(nested,
404 side_arg_list(
405 side_arg_dynamic_field("a", side_arg_dynamic_u32(43, side_attr_list())),
406 side_arg_dynamic_field("b", side_arg_dynamic_u8(55, side_attr_list())),
407 ),
408 side_attr_list()
409 );
410 side_arg_dynamic_define_struct(nested2,
411 side_arg_list(
412 side_arg_dynamic_field("aa", side_arg_dynamic_u64(128, side_attr_list())),
413 side_arg_dynamic_field("bb", side_arg_dynamic_u16(1, side_attr_list())),
414 ),
415 side_attr_list()
416 );
417 side_arg_dynamic_define_struct(mystruct,
418 side_arg_list(
419 side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested)),
420 side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2)),
421 ),
422 side_attr_list()
423 );
424 side_event(my_provider_event_dynamic_nested_struct,
425 side_arg_list(side_arg_dynamic_struct(&mystruct)));
426 }
427
428 side_static_event(my_provider_event_dynamic_vla_struct,
429 "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG,
430 side_field_list(
431 side_field_dynamic("dynamic"),
432 ),
433 side_attr_list()
434 );
435
436 static
437 void test_dynamic_vla_struct(void)
438 {
439 side_arg_dynamic_define_struct(nested,
440 side_arg_list(
441 side_arg_dynamic_field("a", side_arg_dynamic_u32(43, side_attr_list())),
442 side_arg_dynamic_field("b", side_arg_dynamic_u8(55, side_attr_list())),
443 ),
444 side_attr_list()
445 );
446 side_arg_dynamic_define_vec(myvla,
447 side_arg_list(
448 side_arg_dynamic_struct(&nested),
449 side_arg_dynamic_struct(&nested),
450 side_arg_dynamic_struct(&nested),
451 side_arg_dynamic_struct(&nested),
452 ),
453 side_attr_list()
454 );
455 side_event(my_provider_event_dynamic_vla_struct,
456 side_arg_list(side_arg_dynamic_vla(&myvla)));
457 }
458
459 side_static_event(my_provider_event_dynamic_struct_vla,
460 "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG,
461 side_field_list(
462 side_field_dynamic("dynamic"),
463 ),
464 side_attr_list()
465 );
466
467 static
468 void test_dynamic_struct_vla(void)
469 {
470 side_arg_dynamic_define_vec(myvla,
471 side_arg_list(
472 side_arg_dynamic_u32(1, side_attr_list()),
473 side_arg_dynamic_u32(2, side_attr_list()),
474 side_arg_dynamic_u32(3, side_attr_list()),
475 ),
476 side_attr_list()
477 );
478 side_arg_dynamic_define_vec(myvla2,
479 side_arg_list(
480 side_arg_dynamic_u32(4, side_attr_list()),
481 side_arg_dynamic_u64(5, side_attr_list()),
482 side_arg_dynamic_u32(6, side_attr_list()),
483 ),
484 side_attr_list()
485 );
486 side_arg_dynamic_define_struct(mystruct,
487 side_arg_list(
488 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla)),
489 side_arg_dynamic_field("b", side_arg_dynamic_vla(&myvla2)),
490 ),
491 side_attr_list()
492 );
493 side_event(my_provider_event_dynamic_struct_vla,
494 side_arg_list(side_arg_dynamic_struct(&mystruct)));
495 }
496
497 side_static_event(my_provider_event_dynamic_nested_vla,
498 "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG,
499 side_field_list(
500 side_field_dynamic("dynamic"),
501 ),
502 side_attr_list()
503 );
504
505 static
506 void test_dynamic_nested_vla(void)
507 {
508 side_arg_dynamic_define_vec(nestedvla,
509 side_arg_list(
510 side_arg_dynamic_u32(1, side_attr_list()),
511 side_arg_dynamic_u16(2, side_attr_list()),
512 side_arg_dynamic_u32(3, side_attr_list()),
513 ),
514 side_attr_list()
515 );
516 side_arg_dynamic_define_vec(nestedvla2,
517 side_arg_list(
518 side_arg_dynamic_u8(4, side_attr_list()),
519 side_arg_dynamic_u32(5, side_attr_list()),
520 side_arg_dynamic_u32(6, side_attr_list()),
521 ),
522 side_attr_list()
523 );
524 side_arg_dynamic_define_vec(myvla,
525 side_arg_list(
526 side_arg_dynamic_vla(&nestedvla),
527 side_arg_dynamic_vla(&nestedvla2),
528 ),
529 side_attr_list()
530 );
531 side_event(my_provider_event_dynamic_nested_vla,
532 side_arg_list(side_arg_dynamic_vla(&myvla)));
533 }
534
535 side_static_event_variadic(my_provider_event_variadic,
536 "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG,
537 side_field_list(),
538 side_attr_list()
539 );
540
541 static
542 void test_variadic(void)
543 {
544 side_event_variadic(my_provider_event_variadic,
545 side_arg_list(),
546 side_arg_list(
547 side_arg_dynamic_field("a", side_arg_dynamic_u32(55, side_attr_list())),
548 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4, side_attr_list())),
549 ),
550 side_attr_list()
551 );
552 }
553
554 side_static_event_variadic(my_provider_event_static_variadic,
555 "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG,
556 side_field_list(
557 side_field_u32("abc", side_attr_list()),
558 side_field_u16("def", side_attr_list()),
559 ),
560 side_attr_list()
561 );
562
563 static
564 void test_static_variadic(void)
565 {
566 side_event_variadic(my_provider_event_static_variadic,
567 side_arg_list(
568 side_arg_u32(1),
569 side_arg_u16(2),
570 ),
571 side_arg_list(
572 side_arg_dynamic_field("a", side_arg_dynamic_u32(55, side_attr_list())),
573 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4, side_attr_list())),
574 ),
575 side_attr_list()
576 );
577 }
578
579 side_static_event(my_provider_event_bool, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG,
580 side_field_list(
581 side_field_bool("a_false", side_attr_list()),
582 side_field_bool("b_true", side_attr_list()),
583 side_field_bool("c_true", side_attr_list()),
584 side_field_bool("d_true", side_attr_list()),
585 side_field_bool("e_true", side_attr_list()),
586 side_field_bool("f_false", side_attr_list()),
587 side_field_bool("g_true", side_attr_list()),
588 ),
589 side_attr_list()
590 );
591
592 static
593 void test_bool(void)
594 {
595 uint32_t a = 0;
596 uint32_t b = 1;
597 uint64_t c = 0x12345678;
598 int16_t d = -32768;
599 bool e = true;
600 bool f = false;
601 uint32_t g = 256;
602
603 side_event(my_provider_event_bool,
604 side_arg_list(
605 side_arg_bool(a),
606 side_arg_bool(b),
607 side_arg_bool(c),
608 side_arg_bool(d),
609 side_arg_bool(e),
610 side_arg_bool(f),
611 side_arg_bool(g),
612 )
613 );
614 }
615
616 side_static_event_variadic(my_provider_event_dynamic_bool,
617 "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG,
618 side_field_list(),
619 side_attr_list()
620 );
621
622 static
623 void test_dynamic_bool(void)
624 {
625 side_event_variadic(my_provider_event_dynamic_bool,
626 side_arg_list(),
627 side_arg_list(
628 side_arg_dynamic_field("a_true", side_arg_dynamic_bool(55, side_attr_list())),
629 side_arg_dynamic_field("b_true", side_arg_dynamic_bool(-4, side_attr_list())),
630 side_arg_dynamic_field("c_false", side_arg_dynamic_bool(0, side_attr_list())),
631 side_arg_dynamic_field("d_true", side_arg_dynamic_bool(256, side_attr_list())),
632 ),
633 side_attr_list()
634 );
635 }
636
637 side_static_event(my_provider_event_dynamic_vla_visitor,
638 "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG,
639 side_field_list(
640 side_field_dynamic("dynamic"),
641 ),
642 side_attr_list()
643 );
644
645 struct app_dynamic_vla_visitor_ctx {
646 const uint32_t *ptr;
647 uint32_t length;
648 };
649
650 static
651 enum side_visitor_status test_dynamic_vla_visitor(const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, void *_ctx)
652 {
653 struct app_dynamic_vla_visitor_ctx *ctx = (struct app_dynamic_vla_visitor_ctx *) _ctx;
654 uint32_t length = ctx->length, i;
655
656 for (i = 0; i < length; i++) {
657 const struct side_arg elem = side_arg_dynamic_u32(ctx->ptr[i], side_attr_list());
658 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
659 return SIDE_VISITOR_STATUS_ERROR;
660 }
661 return SIDE_VISITOR_STATUS_OK;
662 }
663
664 static uint32_t testarray_dynamic_vla[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
665
666 static
667 void test_dynamic_vla_with_visitor(void)
668 {
669 side_event_cond(my_provider_event_dynamic_vla_visitor) {
670 struct app_dynamic_vla_visitor_ctx ctx = {
671 .ptr = testarray_dynamic_vla,
672 .length = SIDE_ARRAY_SIZE(testarray_dynamic_vla),
673 };
674 side_event_call(my_provider_event_dynamic_vla_visitor,
675 side_arg_list(
676 side_arg_dynamic_vla_visitor(test_dynamic_vla_visitor, &ctx, side_attr_list())
677 )
678 );
679 }
680 }
681
682 side_static_event(my_provider_event_dynamic_struct_visitor,
683 "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG,
684 side_field_list(
685 side_field_dynamic("dynamic"),
686 ),
687 side_attr_list()
688 );
689
690 struct struct_visitor_pair {
691 const char *name;
692 uint32_t value;
693 };
694
695 struct app_dynamic_struct_visitor_ctx {
696 const struct struct_visitor_pair *ptr;
697 uint32_t length;
698 };
699
700 static
701 enum side_visitor_status test_dynamic_struct_visitor(const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, void *_ctx)
702 {
703 struct app_dynamic_struct_visitor_ctx *ctx = (struct app_dynamic_struct_visitor_ctx *) _ctx;
704 uint32_t length = ctx->length, i;
705
706 for (i = 0; i < length; i++) {
707 struct side_arg_dynamic_event_field dynamic_field = {
708 .field_name = ctx->ptr[i].name,
709 .elem = side_arg_dynamic_u32(ctx->ptr[i].value, side_attr_list()),
710 };
711 if (tracer_ctx->write_field(tracer_ctx, &dynamic_field) != SIDE_VISITOR_STATUS_OK)
712 return SIDE_VISITOR_STATUS_ERROR;
713 }
714 return SIDE_VISITOR_STATUS_OK;
715 }
716
717 static struct struct_visitor_pair testarray_dynamic_struct[] = {
718 { "a", 1, },
719 { "b", 2, },
720 { "c", 3, },
721 { "d", 4, },
722 };
723
724 static
725 void test_dynamic_struct_with_visitor(void)
726 {
727 side_event_cond(my_provider_event_dynamic_struct_visitor) {
728 struct app_dynamic_struct_visitor_ctx ctx = {
729 .ptr = testarray_dynamic_struct,
730 .length = SIDE_ARRAY_SIZE(testarray_dynamic_struct),
731 };
732 side_event_call(my_provider_event_dynamic_struct_visitor,
733 side_arg_list(
734 side_arg_dynamic_struct_visitor(test_dynamic_struct_visitor, &ctx, side_attr_list())
735 )
736 );
737 }
738 }
739
740 side_static_event(my_provider_event_user_attribute, "myprovider", "myevent_user_attribute", SIDE_LOGLEVEL_DEBUG,
741 side_field_list(
742 side_field_u32("abc", side_attr_list()),
743 side_field_s64("def", side_attr_list()),
744 ),
745 side_attr_list(
746 side_attr("user_attribute_a", side_attr_string("val1")),
747 side_attr("user_attribute_b", side_attr_string("val2")),
748 )
749 );
750
751 static
752 void test_event_user_attribute(void)
753 {
754 side_event(my_provider_event_user_attribute, side_arg_list(side_arg_u32(1), side_arg_s64(2)));
755 }
756
757 side_static_event(my_provider_field_user_attribute, "myprovider", "myevent_field_attribute", SIDE_LOGLEVEL_DEBUG,
758 side_field_list(
759 side_field_u32("abc",
760 side_attr_list(
761 side_attr("user_attribute_a", side_attr_string("val1")),
762 side_attr("user_attribute_b", side_attr_u32(2)),
763 )
764 ),
765 side_field_s64("def",
766 side_attr_list(
767 side_attr("user_attribute_c", side_attr_string("val3")),
768 side_attr("user_attribute_d", side_attr_s64(-5)),
769 )
770 ),
771 ),
772 side_attr_list()
773 );
774
775 static
776 void test_field_user_attribute(void)
777 {
778 side_event(my_provider_field_user_attribute, side_arg_list(side_arg_u32(1), side_arg_s64(2)));
779 }
780
781 side_static_event_variadic(my_provider_event_variadic_attr,
782 "myprovider", "myvariadiceventattr", SIDE_LOGLEVEL_DEBUG,
783 side_field_list(),
784 side_attr_list()
785 );
786
787 static
788 void test_variadic_attr(void)
789 {
790 side_event_variadic(my_provider_event_variadic_attr,
791 side_arg_list(),
792 side_arg_list(
793 side_arg_dynamic_field("a",
794 side_arg_dynamic_u32(55,
795 side_attr_list(
796 side_attr("user_attribute_c", side_attr_string("valX")),
797 side_attr("user_attribute_d", side_attr_u8(55)),
798 )
799 )
800 ),
801 side_arg_dynamic_field("b",
802 side_arg_dynamic_s8(-4,
803 side_attr_list(
804 side_attr("X", side_attr_u8(1)),
805 side_attr("Y", side_attr_s8(2)),
806 )
807 )
808 ),
809 ),
810 side_attr_list()
811 );
812 }
813
814 side_static_event_variadic(my_provider_event_variadic_vla_attr,
815 "myprovider", "myvariadiceventvlaattr", SIDE_LOGLEVEL_DEBUG,
816 side_field_list(),
817 side_attr_list()
818 );
819
820 static
821 void test_variadic_vla_attr(void)
822 {
823 side_arg_dynamic_define_vec(myvla,
824 side_arg_list(
825 side_arg_dynamic_u32(1,
826 side_attr_list(
827 side_attr("Z", side_attr_u8(0)),
828 side_attr("A", side_attr_u8(123)),
829 )
830 ),
831 side_arg_dynamic_u32(2, side_attr_list()),
832 side_arg_dynamic_u32(3, 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_variadic(my_provider_event_variadic_vla_attr,
840 side_arg_list(),
841 side_arg_list(
842 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla)),
843 ),
844 side_attr_list()
845 );
846 }
847
848 side_static_event_variadic(my_provider_event_variadic_struct_attr,
849 "myprovider", "myvariadiceventstructattr", SIDE_LOGLEVEL_DEBUG,
850 side_field_list(),
851 side_attr_list()
852 );
853
854 static
855 void test_variadic_struct_attr(void)
856 {
857 side_event_cond(my_provider_event_variadic_struct_attr) {
858 side_arg_dynamic_define_struct(mystruct,
859 side_arg_list(
860 side_arg_dynamic_field("a",
861 side_arg_dynamic_u32(43,
862 side_attr_list(
863 side_attr("A", side_attr_bool(true)),
864 )
865 )
866 ),
867 side_arg_dynamic_field("b", side_arg_dynamic_u8(55, side_attr_list())),
868 ),
869 side_attr_list(
870 side_attr("X", side_attr_u8(1)),
871 side_attr("Y", side_attr_u8(2)),
872 )
873 );
874 side_event_call_variadic(my_provider_event_variadic_struct_attr,
875 side_arg_list(),
876 side_arg_list(
877 side_arg_dynamic_field("a", side_arg_dynamic_struct(&mystruct)),
878 ),
879 side_attr_list()
880 );
881 }
882 }
883
884 side_static_event(my_provider_event_float, "myprovider", "myeventfloat", SIDE_LOGLEVEL_DEBUG,
885 side_field_list(
886 #if __HAVE_FLOAT16
887 side_field_float_binary16("binary16", side_attr_list()),
888 side_field_float_binary16_le("binary16_le", side_attr_list()),
889 side_field_float_binary16_be("binary16_be", side_attr_list()),
890 #endif
891 #if __HAVE_FLOAT32
892 side_field_float_binary32("binary32", side_attr_list()),
893 side_field_float_binary32_le("binary32_le", side_attr_list()),
894 side_field_float_binary32_be("binary32_be", side_attr_list()),
895 #endif
896 #if __HAVE_FLOAT64
897 side_field_float_binary64("binary64", side_attr_list()),
898 side_field_float_binary64_le("binary64_le", side_attr_list()),
899 side_field_float_binary64_be("binary64_be", side_attr_list()),
900 #endif
901 #if __HAVE_FLOAT128
902 side_field_float_binary128("binary128", side_attr_list()),
903 side_field_float_binary128_le("binary128_le", side_attr_list()),
904 side_field_float_binary128_be("binary128_be", side_attr_list()),
905 #endif
906 ),
907 side_attr_list()
908 );
909
910 static
911 void test_float(void)
912 {
913 #if __HAVE_FLOAT16
914 union {
915 _Float16 f;
916 uint16_t u;
917 } float16 = {
918 .f = 1.1,
919 };
920 #endif
921 #if __HAVE_FLOAT32
922 union {
923 _Float32 f;
924 uint32_t u;
925 } float32 = {
926 .f = 2.2,
927 };
928 #endif
929 #if __HAVE_FLOAT64
930 union {
931 _Float64 f;
932 uint64_t u;
933 } float64 = {
934 .f = 3.3,
935 };
936 #endif
937 #if __HAVE_FLOAT128
938 union {
939 _Float128 f;
940 char arr[16];
941 } float128 = {
942 .f = 4.4,
943 };
944 #endif
945
946 #if __HAVE_FLOAT16
947 float16.u = side_bswap_16(float16.u);
948 #endif
949 #if __HAVE_FLOAT32
950 float32.u = side_bswap_32(float32.u);
951 #endif
952 #if __HAVE_FLOAT64
953 float64.u = side_bswap_64(float64.u);
954 #endif
955 #if __HAVE_FLOAT128
956 side_bswap_128p(float128.arr);
957 #endif
958
959 side_event(my_provider_event_float,
960 side_arg_list(
961 #if __HAVE_FLOAT16
962 side_arg_float_binary16(1.1),
963 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
964 side_arg_float_binary16(1.1),
965 side_arg_float_binary16(float16.f),
966 # else
967 side_arg_float_binary16(float16.f),
968 side_arg_float_binary16(1.1),
969 # endif
970 #endif
971 #if __HAVE_FLOAT32
972 side_arg_float_binary32(2.2),
973 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
974 side_arg_float_binary32(2.2),
975 side_arg_float_binary32(float32.f),
976 # else
977 side_arg_float_binary32(float32.f),
978 side_arg_float_binary32(2.2),
979 # endif
980 #endif
981 #if __HAVE_FLOAT64
982 side_arg_float_binary64(3.3),
983 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
984 side_arg_float_binary64(3.3),
985 side_arg_float_binary64(float64.f),
986 # else
987 side_arg_float_binary64(float64.f),
988 side_arg_float_binary64(3.3),
989 # endif
990 #endif
991 #if __HAVE_FLOAT128
992 side_arg_float_binary128(4.4),
993 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
994 side_arg_float_binary128(4.4),
995 side_arg_float_binary128(float128.f),
996 # else
997 side_arg_float_binary128(float128.f),
998 side_arg_float_binary128(4.4),
999 # endif
1000 #endif
1001 )
1002 );
1003 }
1004
1005 side_static_event_variadic(my_provider_event_variadic_float,
1006 "myprovider", "myvariadicfloat", SIDE_LOGLEVEL_DEBUG,
1007 side_field_list(),
1008 side_attr_list()
1009 );
1010
1011 static
1012 void test_variadic_float(void)
1013 {
1014 #if __HAVE_FLOAT16
1015 union {
1016 _Float16 f;
1017 uint16_t u;
1018 } float16 = {
1019 .f = 1.1,
1020 };
1021 #endif
1022 #if __HAVE_FLOAT32
1023 union {
1024 _Float32 f;
1025 uint32_t u;
1026 } float32 = {
1027 .f = 2.2,
1028 };
1029 #endif
1030 #if __HAVE_FLOAT64
1031 union {
1032 _Float64 f;
1033 uint64_t u;
1034 } float64 = {
1035 .f = 3.3,
1036 };
1037 #endif
1038 #if __HAVE_FLOAT128
1039 union {
1040 _Float128 f;
1041 char arr[16];
1042 } float128 = {
1043 .f = 4.4,
1044 };
1045 #endif
1046
1047 #if __HAVE_FLOAT16
1048 float16.u = side_bswap_16(float16.u);
1049 #endif
1050 #if __HAVE_FLOAT32
1051 float32.u = side_bswap_32(float32.u);
1052 #endif
1053 #if __HAVE_FLOAT64
1054 float64.u = side_bswap_64(float64.u);
1055 #endif
1056 #if __HAVE_FLOAT128
1057 side_bswap_128p(float128.arr);
1058 #endif
1059
1060 side_event_variadic(my_provider_event_variadic_float,
1061 side_arg_list(),
1062 side_arg_list(
1063 #if __HAVE_FLOAT16
1064 side_arg_dynamic_field("binary16", side_arg_dynamic_float_binary16(1.1, side_attr_list())),
1065 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
1066 side_arg_dynamic_field("binary16_le", side_arg_dynamic_float_binary16_le(1.1, side_attr_list())),
1067 side_arg_dynamic_field("binary16_be", side_arg_dynamic_float_binary16_be(float16.f, side_attr_list())),
1068 # else
1069 side_arg_dynamic_field("binary16_le", side_arg_dynamic_float_binary16_le(float16.f, side_attr_list())),
1070 side_arg_dynamic_field("binary16_be", side_arg_dynamic_float_binary16_be(1.1, side_attr_list())),
1071 # endif
1072 #endif
1073 #if __HAVE_FLOAT32
1074 side_arg_dynamic_field("binary32", side_arg_dynamic_float_binary32(2.2, side_attr_list())),
1075 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
1076 side_arg_dynamic_field("binary32_le", side_arg_dynamic_float_binary32_le(2.2, side_attr_list())),
1077 side_arg_dynamic_field("binary32_be", side_arg_dynamic_float_binary32_be(float32.f, side_attr_list())),
1078 # else
1079 side_arg_dynamic_field("binary32_le", side_arg_dynamic_float_binary32_le(float32.f, side_attr_list())),
1080 side_arg_dynamic_field("binary32_be", side_arg_dynamic_float_binary32_be(2.2, side_attr_list())),
1081 # endif
1082 #endif
1083 #if __HAVE_FLOAT64
1084 side_arg_dynamic_field("binary64", side_arg_dynamic_float_binary64(3.3, side_attr_list())),
1085 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
1086 side_arg_dynamic_field("binary64_le", side_arg_dynamic_float_binary64_le(3.3, side_attr_list())),
1087 side_arg_dynamic_field("binary64_be", side_arg_dynamic_float_binary64_be(float64.f, side_attr_list())),
1088 # else
1089 side_arg_dynamic_field("binary64_le", side_arg_dynamic_float_binary64_le(float64.f, side_attr_list())),
1090 side_arg_dynamic_field("binary64_be", side_arg_dynamic_float_binary64_be(3.3, side_attr_list())),
1091 # endif
1092 #endif
1093 #if __HAVE_FLOAT128
1094 side_arg_dynamic_field("binary128", side_arg_dynamic_float_binary128(4.4, side_attr_list())),
1095 # if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
1096 side_arg_dynamic_field("binary128_le", side_arg_dynamic_float_binary128_le(4.4, side_attr_list())),
1097 side_arg_dynamic_field("binary128_be", side_arg_dynamic_float_binary128_be(float128.f, side_attr_list())),
1098 # else
1099 side_arg_dynamic_field("binary128_le", side_arg_dynamic_float_binary128_le(float128.f, side_attr_list())),
1100 side_arg_dynamic_field("binary128_be", side_arg_dynamic_float_binary128_be(4.4, side_attr_list())),
1101 # endif
1102 #endif
1103 ),
1104 side_attr_list()
1105 );
1106 }
1107
1108 static side_define_enum(myenum,
1109 side_enum_mapping_list(
1110 side_enum_mapping_range("one-ten", 1, 10),
1111 side_enum_mapping_range("100-200", 100, 200),
1112 side_enum_mapping_value("200", 200),
1113 side_enum_mapping_value("300", 300),
1114 ),
1115 side_attr_list()
1116 );
1117
1118 side_static_event(my_provider_event_enum, "myprovider", "myeventenum", SIDE_LOGLEVEL_DEBUG,
1119 side_field_list(
1120 side_field_enum("5", &myenum, side_elem(side_type_u32(side_attr_list()))),
1121 side_field_enum("400", &myenum, side_elem(side_type_u64(side_attr_list()))),
1122 side_field_enum("200", &myenum, side_elem(side_type_u8(side_attr_list()))),
1123 side_field_enum("-100", &myenum, side_elem(side_type_s8(side_attr_list()))),
1124 side_field_enum("6_be", &myenum, side_elem(side_type_u32_be(side_attr_list()))),
1125 side_field_enum("6_le", &myenum, side_elem(side_type_u32_le(side_attr_list()))),
1126 ),
1127 side_attr_list()
1128 );
1129
1130 static
1131 void test_enum(void)
1132 {
1133 side_event(my_provider_event_enum,
1134 side_arg_list(
1135 side_arg_u32(5),
1136 side_arg_u64(400),
1137 side_arg_u8(200),
1138 side_arg_s8(-100),
1139 #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
1140 side_arg_u32(side_bswap_32(6)),
1141 side_arg_u32(6),
1142 #else
1143 side_arg_u32(side_bswap_32(6)),
1144 side_arg_u32(6),
1145 #endif
1146 )
1147 );
1148 }
1149
1150 /* A bitmap enum maps bits to labels. */
1151 static side_define_enum_bitmap(myenum_bitmap,
1152 side_enum_bitmap_mapping_list(
1153 side_enum_bitmap_mapping_value("0", 0),
1154 side_enum_bitmap_mapping_range("1-2", 1, 2),
1155 side_enum_bitmap_mapping_range("2-4", 2, 4),
1156 side_enum_bitmap_mapping_value("3", 3),
1157 side_enum_bitmap_mapping_value("30", 30),
1158 side_enum_bitmap_mapping_value("63", 63),
1159 side_enum_bitmap_mapping_range("158-160", 158, 160),
1160 side_enum_bitmap_mapping_value("159", 159),
1161 side_enum_bitmap_mapping_range("500-700", 500, 700),
1162 ),
1163 side_attr_list()
1164 );
1165
1166 side_static_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitmap", SIDE_LOGLEVEL_DEBUG,
1167 side_field_list(
1168 side_field_enum_bitmap("bit_0", &myenum_bitmap, side_elem(side_type_u32(side_attr_list()))),
1169 side_field_enum_bitmap("bit_1", &myenum_bitmap, side_elem(side_type_u32(side_attr_list()))),
1170 side_field_enum_bitmap("bit_2", &myenum_bitmap, side_elem(side_type_u8(side_attr_list()))),
1171 side_field_enum_bitmap("bit_3", &myenum_bitmap, side_elem(side_type_u8(side_attr_list()))),
1172 side_field_enum_bitmap("bit_30", &myenum_bitmap, side_elem(side_type_u32(side_attr_list()))),
1173 side_field_enum_bitmap("bit_31", &myenum_bitmap, side_elem(side_type_u32(side_attr_list()))),
1174 side_field_enum_bitmap("bit_63", &myenum_bitmap, side_elem(side_type_u64(side_attr_list()))),
1175 side_field_enum_bitmap("bits_1+63", &myenum_bitmap, side_elem(side_type_u64(side_attr_list()))),
1176 side_field_enum_bitmap("byte_bit_2", &myenum_bitmap, side_elem(side_type_byte(side_attr_list()))),
1177 side_field_enum_bitmap("bit_159", &myenum_bitmap,
1178 side_elem(side_type_array(side_elem(side_type_u32(side_attr_list())), 5, side_attr_list()))),
1179 side_field_enum_bitmap("bit_159", &myenum_bitmap,
1180 side_elem(side_type_vla(side_elem(side_type_u32(side_attr_list())), side_attr_list()))),
1181 side_field_enum_bitmap("bit_2_be", &myenum_bitmap, side_elem(side_type_u32_be(side_attr_list()))),
1182 side_field_enum_bitmap("bit_2_le", &myenum_bitmap, side_elem(side_type_u32_le(side_attr_list()))),
1183 ),
1184 side_attr_list()
1185 );
1186
1187 static
1188 void test_enum_bitmap(void)
1189 {
1190 side_event_cond(my_provider_event_enum_bitmap) {
1191 side_arg_define_vec(myarray,
1192 side_arg_list(
1193 side_arg_u32(0),
1194 side_arg_u32(0),
1195 side_arg_u32(0),
1196 side_arg_u32(0),
1197 side_arg_u32(0x80000000), /* bit 159 */
1198 )
1199 );
1200 side_event_call(my_provider_event_enum_bitmap,
1201 side_arg_list(
1202 side_arg_u32(1 << 0),
1203 side_arg_u32(1 << 1),
1204 side_arg_u8(1 << 2),
1205 side_arg_u8(1 << 3),
1206 side_arg_u32(1 << 30),
1207 side_arg_u32(1 << 31),
1208 side_arg_u64(1ULL << 63),
1209 side_arg_u64((1ULL << 1) | (1ULL << 63)),
1210 side_arg_byte(1 << 2),
1211 side_arg_array(&myarray),
1212 side_arg_vla(&myarray),
1213 #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
1214 side_arg_u32(side_bswap_32(1 << 2)),
1215 side_arg_u32(1 << 2),
1216 #else
1217 side_arg_u32(0x06000000),
1218 side_arg_u32(side_bswap_32(1 << 2)),
1219 #endif
1220 )
1221 );
1222 }
1223 }
1224
1225 static uint8_t blob_fixint[] = { 0x55, 0x44, 0x33, 0x22, 0x11 };
1226
1227 side_static_event_variadic(my_provider_event_blob, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG,
1228 side_field_list(
1229 side_field_byte("blobfield", side_attr_list()),
1230 side_field_array("arrayblob", side_elem(side_type_byte(side_attr_list())), 3, side_attr_list()),
1231 side_field_array("arrayblobfix", side_elem(side_type_byte(side_attr_list())), SIDE_ARRAY_SIZE(blob_fixint), side_attr_list()),
1232 side_field_vla("vlablobfix", side_elem(side_type_byte(side_attr_list())), side_attr_list()),
1233 ),
1234 side_attr_list()
1235 );
1236
1237 static
1238 void test_blob(void)
1239 {
1240 side_event_cond(my_provider_event_blob) {
1241 side_arg_define_vec(myarray, side_arg_list(side_arg_byte(1), side_arg_byte(2), side_arg_byte(3)));
1242 side_arg_dynamic_define_vec(myvla,
1243 side_arg_list(
1244 side_arg_dynamic_byte(0x22, side_attr_list()),
1245 side_arg_dynamic_byte(0x33, side_attr_list()),
1246 ),
1247 side_attr_list()
1248 );
1249 side_event_call_variadic(my_provider_event_blob,
1250 side_arg_list(
1251 side_arg_byte(0x55),
1252 side_arg_array(&myarray),
1253 side_arg_array_byte(blob_fixint),
1254 side_arg_vla_byte(blob_fixint, SIDE_ARRAY_SIZE(blob_fixint)),
1255 ),
1256 side_arg_list(
1257 side_arg_dynamic_field("varblobfield",
1258 side_arg_dynamic_byte(0x55, side_attr_list())
1259 ),
1260 side_arg_dynamic_field("varblobvla", side_arg_dynamic_vla(&myvla)),
1261 ),
1262 side_attr_list()
1263 );
1264 }
1265 }
1266
1267 side_static_event_variadic(my_provider_event_format_string,
1268 "myprovider", "myeventformatstring", SIDE_LOGLEVEL_DEBUG,
1269 side_field_list(
1270 side_field_string("fmt", side_attr_list()),
1271 ),
1272 side_attr_list(
1273 side_attr("lang.c.format_string", side_attr_bool(true)),
1274 )
1275 );
1276
1277 static
1278 void test_fmt_string(void)
1279 {
1280 side_event_cond(my_provider_event_format_string) {
1281 side_arg_dynamic_define_vec(args,
1282 side_arg_list(
1283 side_arg_dynamic_string("blah", side_attr_list()),
1284 side_arg_dynamic_s32(123, side_attr_list()),
1285 ),
1286 side_attr_list()
1287 );
1288 side_event_call_variadic(my_provider_event_format_string,
1289 side_arg_list(
1290 side_arg_string("This is a formatted string with str: %s int: %d"),
1291 ),
1292 side_arg_list(
1293 side_arg_dynamic_field("arguments", side_arg_dynamic_vla(&args)),
1294 ),
1295 side_attr_list()
1296 );
1297 }
1298 }
1299
1300 side_static_event_variadic(my_provider_event_endian, "myprovider", "myevent_endian", SIDE_LOGLEVEL_DEBUG,
1301 side_field_list(
1302 side_field_u16_le("u16_le", side_attr_list()),
1303 side_field_u32_le("u32_le", side_attr_list()),
1304 side_field_u64_le("u64_le", side_attr_list()),
1305 side_field_s16_le("s16_le", side_attr_list()),
1306 side_field_s32_le("s32_le", side_attr_list()),
1307 side_field_s64_le("s64_le", side_attr_list()),
1308 side_field_u16_be("u16_be", side_attr_list()),
1309 side_field_u32_be("u32_be", side_attr_list()),
1310 side_field_u64_be("u64_be", side_attr_list()),
1311 side_field_s16_be("s16_be", side_attr_list()),
1312 side_field_s32_be("s32_be", side_attr_list()),
1313 side_field_s64_be("s64_be", side_attr_list()),
1314 ),
1315 side_attr_list()
1316 );
1317
1318 static
1319 void test_endian(void)
1320 {
1321 side_event_variadic(my_provider_event_endian,
1322 side_arg_list(
1323 #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
1324 side_arg_u16(1),
1325 side_arg_u32(1),
1326 side_arg_u64(1),
1327 side_arg_s16(1),
1328 side_arg_s32(1),
1329 side_arg_s64(1),
1330 side_arg_u16(side_bswap_16(1)),
1331 side_arg_u32(side_bswap_32(1)),
1332 side_arg_u64(side_bswap_64(1)),
1333 side_arg_s16(side_bswap_16(1)),
1334 side_arg_s32(side_bswap_32(1)),
1335 side_arg_s64(side_bswap_64(1)),
1336 #else
1337 side_arg_u16(side_bswap_16(1)),
1338 side_arg_u32(side_bswap_32(1)),
1339 side_arg_u64(side_bswap_64(1)),
1340 side_arg_s16(side_bswap_16(1)),
1341 side_arg_s32(side_bswap_32(1)),
1342 side_arg_s64(side_bswap_64(1)),
1343 side_arg_u16(1),
1344 side_arg_u32(1),
1345 side_arg_u64(1),
1346 side_arg_s16(1),
1347 side_arg_s32(1),
1348 side_arg_s64(1),
1349 #endif
1350 ),
1351 side_arg_list(
1352 #if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
1353 side_arg_dynamic_field("u16_le", side_arg_dynamic_u16_le(1, side_attr_list())),
1354 side_arg_dynamic_field("u32_le", side_arg_dynamic_u32_le(1, side_attr_list())),
1355 side_arg_dynamic_field("u64_le", side_arg_dynamic_u64_le(1, side_attr_list())),
1356 side_arg_dynamic_field("s16_le", side_arg_dynamic_s16_le(1, side_attr_list())),
1357 side_arg_dynamic_field("s32_le", side_arg_dynamic_s32_le(1, side_attr_list())),
1358 side_arg_dynamic_field("s64_le", side_arg_dynamic_s64_le(1, side_attr_list())),
1359 side_arg_dynamic_field("u16_be", side_arg_dynamic_u16_be(side_bswap_16(1), side_attr_list())),
1360 side_arg_dynamic_field("u32_be", side_arg_dynamic_u32_be(side_bswap_32(1), side_attr_list())),
1361 side_arg_dynamic_field("u64_be", side_arg_dynamic_u64_be(side_bswap_64(1), side_attr_list())),
1362 side_arg_dynamic_field("s16_be", side_arg_dynamic_s16_be(side_bswap_16(1), side_attr_list())),
1363 side_arg_dynamic_field("s32_be", side_arg_dynamic_s32_be(side_bswap_32(1), side_attr_list())),
1364 side_arg_dynamic_field("s64_be", side_arg_dynamic_s64_be(side_bswap_64(1), side_attr_list())),
1365 #else
1366 side_arg_dynamic_field("u16_le", side_arg_dynamic_u16_le(side_bswap_16(1), side_attr_list())),
1367 side_arg_dynamic_field("u32_le", side_arg_dynamic_u32_le(side_bswap_32(1), side_attr_list())),
1368 side_arg_dynamic_field("u64_le", side_arg_dynamic_u64_le(side_bswap_64(1), side_attr_list())),
1369 side_arg_dynamic_field("s16_le", side_arg_dynamic_s16_le(side_bswap_16(1), side_attr_list())),
1370 side_arg_dynamic_field("s32_le", side_arg_dynamic_s32_le(side_bswap_32(1), side_attr_list())),
1371 side_arg_dynamic_field("s64_le", side_arg_dynamic_s64_le(side_bswap_64(1), side_attr_list())),
1372 side_arg_dynamic_field("u16_be", side_arg_dynamic_u16_be(1, side_attr_list())),
1373 side_arg_dynamic_field("u32_be", side_arg_dynamic_u32_be(1, side_attr_list())),
1374 side_arg_dynamic_field("u64_be", side_arg_dynamic_u64_be(1, side_attr_list())),
1375 side_arg_dynamic_field("s16_be", side_arg_dynamic_s16_be(1, side_attr_list())),
1376 side_arg_dynamic_field("s32_be", side_arg_dynamic_s32_be(1, side_attr_list())),
1377 side_arg_dynamic_field("s64_be", side_arg_dynamic_s64_be(1, side_attr_list())),
1378 #endif
1379 ),
1380 side_attr_list()
1381 );
1382 }
1383
1384 side_static_event(my_provider_event_base, "myprovider", "myevent_base", SIDE_LOGLEVEL_DEBUG,
1385 side_field_list(
1386 side_field_u8("u8base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1387 side_field_u8("u8base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1388 side_field_u8("u8base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1389 side_field_u8("u8base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1390 side_field_u16("u16base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1391 side_field_u16("u16base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1392 side_field_u16("u16base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1393 side_field_u16("u16base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1394 side_field_u32("u32base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1395 side_field_u32("u32base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1396 side_field_u32("u32base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1397 side_field_u32("u32base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1398 side_field_u64("u64base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1399 side_field_u64("u64base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1400 side_field_u64("u64base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1401 side_field_u64("u64base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1402 side_field_s8("s8base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1403 side_field_s8("s8base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1404 side_field_s8("s8base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1405 side_field_s8("s8base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1406 side_field_s16("s16base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1407 side_field_s16("s16base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1408 side_field_s16("s16base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1409 side_field_s16("s16base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1410 side_field_s32("s32base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1411 side_field_s32("s32base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1412 side_field_s32("s32base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1413 side_field_s32("s32base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1414 side_field_s64("s64base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1415 side_field_s64("s64base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1416 side_field_s64("s64base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1417 side_field_s64("s64base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1418 ),
1419 side_attr_list()
1420 );
1421
1422 static
1423 void test_base(void)
1424 {
1425 side_event(my_provider_event_base,
1426 side_arg_list(
1427 side_arg_u8(55),
1428 side_arg_u8(55),
1429 side_arg_u8(55),
1430 side_arg_u8(55),
1431 side_arg_u16(55),
1432 side_arg_u16(55),
1433 side_arg_u16(55),
1434 side_arg_u16(55),
1435 side_arg_u32(55),
1436 side_arg_u32(55),
1437 side_arg_u32(55),
1438 side_arg_u32(55),
1439 side_arg_u64(55),
1440 side_arg_u64(55),
1441 side_arg_u64(55),
1442 side_arg_u64(55),
1443 side_arg_s8(-55),
1444 side_arg_s8(-55),
1445 side_arg_s8(-55),
1446 side_arg_s8(-55),
1447 side_arg_s16(-55),
1448 side_arg_s16(-55),
1449 side_arg_s16(-55),
1450 side_arg_s16(-55),
1451 side_arg_s32(-55),
1452 side_arg_s32(-55),
1453 side_arg_s32(-55),
1454 side_arg_s32(-55),
1455 side_arg_s64(-55),
1456 side_arg_s64(-55),
1457 side_arg_s64(-55),
1458 side_arg_s64(-55),
1459 )
1460 );
1461 }
1462
1463 struct test {
1464 uint32_t a;
1465 uint64_t b;
1466 uint8_t c;
1467 int32_t d;
1468 uint16_t e;
1469 int8_t f;
1470 int16_t g;
1471 int32_t h;
1472 int64_t i;
1473 int64_t j;
1474 int64_t k;
1475 };
1476
1477 static side_define_struct(mystructsgdef,
1478 side_field_list(
1479 side_field_sg_unsigned_integer("a", offsetof(struct test, a),
1480 side_struct_field_sizeof_bit(struct test, a), 0,
1481 side_struct_field_sizeof_bit(struct test, a), side_attr_list()),
1482 side_field_sg_signed_integer("d", offsetof(struct test, d),
1483 side_struct_field_sizeof_bit(struct test, d), 0,
1484 side_struct_field_sizeof_bit(struct test, d), side_attr_list()),
1485 side_field_sg_unsigned_integer("e", offsetof(struct test, e),
1486 side_struct_field_sizeof_bit(struct test, e), 8, 4,
1487 side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1488 side_field_sg_signed_integer("f", offsetof(struct test, f),
1489 side_struct_field_sizeof_bit(struct test, f), 1, 4,
1490 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1491 side_field_sg_signed_integer("g", offsetof(struct test, g),
1492 side_struct_field_sizeof_bit(struct test, g), 11, 4,
1493 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1494 side_field_sg_signed_integer("h", offsetof(struct test, h),
1495 side_struct_field_sizeof_bit(struct test, h), 1, 31,
1496 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1497 side_field_sg_signed_integer("i", offsetof(struct test, i),
1498 side_struct_field_sizeof_bit(struct test, i), 33, 20,
1499 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1500 side_field_sg_signed_integer("j", offsetof(struct test, j),
1501 side_struct_field_sizeof_bit(struct test, j), 63, 1,
1502 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1503 side_field_sg_signed_integer("k", offsetof(struct test, k),
1504 side_struct_field_sizeof_bit(struct test, k), 1, 63,
1505 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1506 ),
1507 side_attr_list()
1508 );
1509
1510 side_static_event(my_provider_event_structsg, "myprovider", "myeventstructsg", SIDE_LOGLEVEL_DEBUG,
1511 side_field_list(
1512 side_field_struct_sg("structsg", &mystructsgdef, 0),
1513 side_field_sg_signed_integer("intsg", 0, 32, 0, 32,
1514 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1515 ),
1516 side_attr_list()
1517 );
1518
1519 static
1520 void test_struct_sg(void)
1521 {
1522 side_event_cond(my_provider_event_structsg) {
1523 struct test mystruct = {
1524 .a = 55,
1525 .b = 123,
1526 .c = 2,
1527 .d = -55,
1528 .e = 0xABCD,
1529 .f = -1,
1530 .g = -1,
1531 .h = -1,
1532 .i = -1,
1533 .j = -1,
1534 .k = -1,
1535 };
1536 int32_t val = -66;
1537 side_event_call(my_provider_event_structsg,
1538 side_arg_list(
1539 side_arg_struct_sg(&mystruct),
1540 side_arg_signed_integer_sg(&val),
1541 )
1542 );
1543 }
1544 }
1545
1546 struct testnest2 {
1547 uint8_t c;
1548 };
1549
1550 struct testnest1 {
1551 uint64_t b;
1552 struct testnest2 *nest;
1553 };
1554
1555 struct testnest0 {
1556 uint32_t a;
1557 struct testnest1 *nest;
1558 };
1559
1560 static side_define_struct(mystructsgnest2,
1561 side_field_list(
1562 side_field_sg_unsigned_integer("c", offsetof(struct testnest2, c),
1563 side_struct_field_sizeof_bit(struct testnest2, c), 0,
1564 side_struct_field_sizeof_bit(struct testnest2, c), side_attr_list()),
1565 ),
1566 side_attr_list()
1567 );
1568
1569 static side_define_struct(mystructsgnest1,
1570 side_field_list(
1571 side_field_sg_unsigned_integer("b", offsetof(struct testnest1, b),
1572 side_struct_field_sizeof_bit(struct testnest1, b), 0,
1573 side_struct_field_sizeof_bit(struct testnest1, b), side_attr_list()),
1574 side_field_struct_sg("nest2", &mystructsgnest2,
1575 offsetof(struct testnest1, nest)),
1576 ),
1577 side_attr_list()
1578 );
1579
1580 static side_define_struct(mystructsgnest0,
1581 side_field_list(
1582 side_field_sg_unsigned_integer("a", offsetof(struct testnest0, a),
1583 side_struct_field_sizeof_bit(struct testnest0, a), 0,
1584 side_struct_field_sizeof_bit(struct testnest0, a), side_attr_list()),
1585 side_field_struct_sg("nest1", &mystructsgnest1,
1586 offsetof(struct testnest0, nest)),
1587 ),
1588 side_attr_list()
1589 );
1590
1591 side_static_event(my_provider_event_structsg_nest,
1592 "myprovider", "myeventstructsgnest", SIDE_LOGLEVEL_DEBUG,
1593 side_field_list(
1594 side_field_struct_sg("nest0", &mystructsgnest0, 0),
1595 ),
1596 side_attr_list()
1597 );
1598
1599 static
1600 void test_struct_sg_nest(void)
1601 {
1602 side_event_cond(my_provider_event_structsg_nest) {
1603 struct testnest2 mystruct2 = {
1604 .c = 77,
1605 };
1606 struct testnest1 mystruct1 = {
1607 .b = 66,
1608 .nest = &mystruct2,
1609 };
1610 struct testnest0 mystruct = {
1611 .a = 55,
1612 .nest = &mystruct1,
1613 };
1614 side_event_call(my_provider_event_structsg_nest,
1615 side_arg_list(
1616 side_arg_struct_sg(&mystruct),
1617 )
1618 );
1619 }
1620 }
1621
1622 int main()
1623 {
1624 test_fields();
1625 test_event_hidden();
1626 test_event_export();
1627 test_struct_literal();
1628 test_struct();
1629 test_array();
1630 test_vla();
1631 test_vla_visitor();
1632 test_vla_visitor_2d();
1633 test_array_fixint();
1634 test_vla_fixint();
1635 test_dynamic_basic_type();
1636 test_dynamic_vla();
1637 test_dynamic_null();
1638 test_dynamic_struct();
1639 test_dynamic_nested_struct();
1640 test_dynamic_vla_struct();
1641 test_dynamic_struct_vla();
1642 test_dynamic_nested_vla();
1643 test_variadic();
1644 test_static_variadic();
1645 test_bool();
1646 test_dynamic_bool();
1647 test_dynamic_vla_with_visitor();
1648 test_dynamic_struct_with_visitor();
1649 test_event_user_attribute();
1650 test_field_user_attribute();
1651 test_variadic_attr();
1652 test_variadic_vla_attr();
1653 test_variadic_struct_attr();
1654 test_float();
1655 test_variadic_float();
1656 test_enum();
1657 test_enum_bitmap();
1658 test_blob();
1659 test_fmt_string();
1660 test_endian();
1661 test_base();
1662 test_struct_sg();
1663 test_struct_sg_nest();
1664 return 0;
1665 }
This page took 0.06222 seconds and 4 git commands to generate.