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