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