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