1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 #include <side/trace.h>
15 /* User code example */
17 static side_define_event(my_provider_event
, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG
,
19 side_field_u32("abc", side_attr_list()),
20 side_field_s64("def", side_attr_list()),
21 side_field_dynamic("dynamic", side_attr_list()),
27 void test_fields(void)
32 my_provider_event_enabled
= 1;
33 side_event(my_provider_event
, side_arg_list(side_arg_u32(uw
), side_arg_s64(sdw
),
34 side_arg_dynamic(side_arg_dynamic_string("zzz", side_attr_list()))));
37 static side_define_event(my_provider_event_struct_literal
, "myprovider", "myeventstructliteral", SIDE_LOGLEVEL_DEBUG
,
39 side_field_struct("structliteral",
42 side_field_u32("x", side_attr_list()),
43 side_field_s64("y", side_attr_list()),
48 side_field_u8("z", side_attr_list()),
54 void test_struct_literal(void)
56 my_provider_event_struct_literal_enabled
= 1;
57 side_event_cond(my_provider_event_struct_literal
) {
58 side_arg_define_vec(mystruct
, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
59 side_event_call(my_provider_event_struct_literal
, side_arg_list(side_arg_struct(&mystruct
), side_arg_u8(55)));
63 static side_define_struct(mystructdef
,
65 side_field_u32("x", side_attr_list()),
66 side_field_s64("y", side_attr_list()),
71 static side_define_event(my_provider_event_struct
, "myprovider", "myeventstruct", SIDE_LOGLEVEL_DEBUG
,
73 side_field_struct("struct", &mystructdef
),
74 side_field_u8("z", side_attr_list()),
80 void test_struct(void)
82 my_provider_event_struct_enabled
= 1;
83 side_event_cond(my_provider_event_struct
) {
84 side_arg_define_vec(mystruct
, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
85 side_event_call(my_provider_event_struct
, side_arg_list(side_arg_struct(&mystruct
), side_arg_u8(55)));
89 static side_define_event(my_provider_event_array
, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG
,
91 side_field_array("arr", side_elem(side_type_u32(side_attr_list())), 3, side_attr_list()),
92 side_field_s64("v", side_attr_list()),
100 my_provider_event_array_enabled
= 1;
101 side_event_cond(my_provider_event_array
) {
102 side_arg_define_vec(myarray
, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
103 side_event_call(my_provider_event_array
, side_arg_list(side_arg_array(&myarray
), side_arg_s64(42)));
107 static side_define_event(my_provider_event_vla
, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG
,
109 side_field_vla("vla", side_elem(side_type_u32(side_attr_list())), side_attr_list()),
110 side_field_s64("v", side_attr_list()),
118 my_provider_event_vla_enabled
= 1;
119 side_event_cond(my_provider_event_vla
) {
120 side_arg_define_vec(myvla
, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
121 side_event_call(my_provider_event_vla
, side_arg_list(side_arg_vla(&myvla
), side_arg_s64(42)));
125 /* 1D array visitor */
127 struct app_visitor_ctx
{
133 enum side_visitor_status
test_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
135 struct app_visitor_ctx
*ctx
= (struct app_visitor_ctx
*) _ctx
;
136 uint32_t length
= ctx
->length
, i
;
138 for (i
= 0; i
< length
; i
++) {
139 const struct side_arg_vec elem
= side_arg_u32(ctx
->ptr
[i
]);
141 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
142 return SIDE_VISITOR_STATUS_ERROR
;
144 return SIDE_VISITOR_STATUS_OK
;
147 static uint32_t testarray
[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
149 static side_define_event(my_provider_event_vla_visitor
, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG
,
151 side_field_vla_visitor("vlavisit", side_elem(side_type_u32(side_attr_list())), test_visitor
, side_attr_list()),
152 side_field_s64("v", side_attr_list()),
158 void test_vla_visitor(void)
160 my_provider_event_vla_visitor_enabled
= 1;
161 side_event_cond(my_provider_event_vla_visitor
) {
162 struct app_visitor_ctx ctx
= {
164 .length
= SIDE_ARRAY_SIZE(testarray
),
166 side_event_call(my_provider_event_vla_visitor
, side_arg_list(side_arg_vla_visitor(&ctx
), side_arg_s64(42)));
170 /* 2D array visitor */
172 struct app_visitor_2d_inner_ctx
{
178 enum side_visitor_status
test_inner_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
180 struct app_visitor_2d_inner_ctx
*ctx
= (struct app_visitor_2d_inner_ctx
*) _ctx
;
181 uint32_t length
= ctx
->length
, i
;
183 for (i
= 0; i
< length
; i
++) {
184 const struct side_arg_vec elem
= side_arg_u32(ctx
->ptr
[i
]);
186 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
187 return SIDE_VISITOR_STATUS_ERROR
;
189 return SIDE_VISITOR_STATUS_OK
;
192 struct app_visitor_2d_outer_ctx
{
193 const uint32_t (*ptr
)[2];
198 enum side_visitor_status
test_outer_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
200 struct app_visitor_2d_outer_ctx
*ctx
= (struct app_visitor_2d_outer_ctx
*) _ctx
;
201 uint32_t length
= ctx
->length
, i
;
203 for (i
= 0; i
< length
; i
++) {
204 struct app_visitor_2d_inner_ctx inner_ctx
= {
208 const struct side_arg_vec elem
= side_arg_vla_visitor(&inner_ctx
);
209 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
210 return SIDE_VISITOR_STATUS_ERROR
;
212 return SIDE_VISITOR_STATUS_OK
;
215 static uint32_t testarray2d
[][2] = {
221 static side_define_event(my_provider_event_vla_visitor2d
, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG
,
223 side_field_vla_visitor("vlavisit2d",
225 side_type_vla_visitor(
226 side_elem(side_type_u32(side_attr_list())),
229 ), test_outer_visitor
, side_attr_list()),
230 side_field_s64("v", side_attr_list()),
236 void test_vla_visitor_2d(void)
238 my_provider_event_vla_visitor2d_enabled
= 1;
239 side_event_cond(my_provider_event_vla_visitor2d
) {
240 struct app_visitor_2d_outer_ctx ctx
= {
242 .length
= SIDE_ARRAY_SIZE(testarray2d
),
244 side_event_call(my_provider_event_vla_visitor2d
, side_arg_list(side_arg_vla_visitor(&ctx
), side_arg_s64(42)));
248 static int64_t array_fixint
[] = { -444, 555, 123, 2897432587 };
250 static side_define_event(my_provider_event_array_fixint
, "myprovider", "myarrayfixint", SIDE_LOGLEVEL_DEBUG
,
252 side_field_array("arrfixint", side_elem(side_type_s64(side_attr_list())), SIDE_ARRAY_SIZE(array_fixint
), side_attr_list()),
253 side_field_s64("v", side_attr_list()),
259 void test_array_fixint(void)
261 my_provider_event_array_fixint_enabled
= 1;
262 side_event(my_provider_event_array_fixint
,
263 side_arg_list(side_arg_array_s64(array_fixint
), side_arg_s64(42)));
266 static int64_t vla_fixint
[] = { -444, 555, 123, 2897432587 };
268 static side_define_event(my_provider_event_vla_fixint
, "myprovider", "myvlafixint", SIDE_LOGLEVEL_DEBUG
,
270 side_field_vla("vlafixint", side_elem(side_type_s64(side_attr_list())), side_attr_list()),
271 side_field_s64("v", side_attr_list()),
277 void test_vla_fixint(void)
279 my_provider_event_vla_fixint_enabled
= 1;
280 side_event(my_provider_event_vla_fixint
,
281 side_arg_list(side_arg_vla_s64(vla_fixint
, SIDE_ARRAY_SIZE(vla_fixint
)), side_arg_s64(42)));
284 static side_define_event(my_provider_event_dynamic_basic
,
285 "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG
,
287 side_field_dynamic("dynamic", side_attr_list()),
293 void test_dynamic_basic_type(void)
295 my_provider_event_dynamic_basic_enabled
= 1;
296 side_event(my_provider_event_dynamic_basic
,
297 side_arg_list(side_arg_dynamic(side_arg_dynamic_s16(-33, side_attr_list()))));
300 static side_define_event(my_provider_event_dynamic_vla
,
301 "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG
,
303 side_field_dynamic("dynamic", side_attr_list()),
309 void test_dynamic_vla(void)
311 side_arg_dynamic_define_vec(myvla
,
313 side_arg_dynamic_u32(1, side_attr_list()),
314 side_arg_dynamic_u32(2, side_attr_list()),
315 side_arg_dynamic_u32(3, side_attr_list()),
319 my_provider_event_dynamic_vla_enabled
= 1;
320 side_event(my_provider_event_dynamic_vla
,
321 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
324 static side_define_event(my_provider_event_dynamic_null
,
325 "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG
,
327 side_field_dynamic("dynamic", side_attr_list()),
333 void test_dynamic_null(void)
335 my_provider_event_dynamic_null_enabled
= 1;
336 side_event(my_provider_event_dynamic_null
,
337 side_arg_list(side_arg_dynamic(side_arg_dynamic_null(side_attr_list()))));
340 static side_define_event(my_provider_event_dynamic_struct
,
341 "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG
,
343 side_field_dynamic("dynamic", side_attr_list()),
349 void test_dynamic_struct(void)
351 side_arg_dynamic_define_struct(mystruct
,
353 side_arg_dynamic_field("a", side_arg_dynamic_u32(43, side_attr_list())),
354 side_arg_dynamic_field("b", side_arg_dynamic_string("zzz", side_attr_list())),
355 side_arg_dynamic_field("c", side_arg_dynamic_null(side_attr_list())),
360 my_provider_event_dynamic_struct_enabled
= 1;
361 side_event(my_provider_event_dynamic_struct
,
362 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
365 static side_define_event(my_provider_event_dynamic_nested_struct
,
366 "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG
,
368 side_field_dynamic("dynamic", side_attr_list()),
374 void test_dynamic_nested_struct(void)
376 side_arg_dynamic_define_struct(nested
,
378 side_arg_dynamic_field("a", side_arg_dynamic_u32(43, side_attr_list())),
379 side_arg_dynamic_field("b", side_arg_dynamic_u8(55, side_attr_list())),
383 side_arg_dynamic_define_struct(nested2
,
385 side_arg_dynamic_field("aa", side_arg_dynamic_u64(128, side_attr_list())),
386 side_arg_dynamic_field("bb", side_arg_dynamic_u16(1, side_attr_list())),
390 side_arg_dynamic_define_struct(mystruct
,
392 side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested
)),
393 side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2
)),
397 my_provider_event_dynamic_nested_struct_enabled
= 1;
398 side_event(my_provider_event_dynamic_nested_struct
,
399 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
402 static side_define_event(my_provider_event_dynamic_vla_struct
,
403 "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG
,
405 side_field_dynamic("dynamic", side_attr_list()),
411 void test_dynamic_vla_struct(void)
413 side_arg_dynamic_define_struct(nested
,
415 side_arg_dynamic_field("a", side_arg_dynamic_u32(43, side_attr_list())),
416 side_arg_dynamic_field("b", side_arg_dynamic_u8(55, side_attr_list())),
420 side_arg_dynamic_define_vec(myvla
,
422 side_arg_dynamic_struct(&nested
),
423 side_arg_dynamic_struct(&nested
),
424 side_arg_dynamic_struct(&nested
),
425 side_arg_dynamic_struct(&nested
),
429 my_provider_event_dynamic_vla_struct_enabled
= 1;
430 side_event(my_provider_event_dynamic_vla_struct
,
431 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
434 static side_define_event(my_provider_event_dynamic_struct_vla
,
435 "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG
,
437 side_field_dynamic("dynamic", side_attr_list()),
443 void test_dynamic_struct_vla(void)
445 side_arg_dynamic_define_vec(myvla
,
447 side_arg_dynamic_u32(1, side_attr_list()),
448 side_arg_dynamic_u32(2, side_attr_list()),
449 side_arg_dynamic_u32(3, side_attr_list()),
453 side_arg_dynamic_define_vec(myvla2
,
455 side_arg_dynamic_u32(4, side_attr_list()),
456 side_arg_dynamic_u64(5, side_attr_list()),
457 side_arg_dynamic_u32(6, side_attr_list()),
461 side_arg_dynamic_define_struct(mystruct
,
463 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla
)),
464 side_arg_dynamic_field("b", side_arg_dynamic_vla(&myvla2
)),
468 my_provider_event_dynamic_struct_vla_enabled
= 1;
469 side_event(my_provider_event_dynamic_struct_vla
,
470 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
473 static side_define_event(my_provider_event_dynamic_nested_vla
,
474 "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG
,
476 side_field_dynamic("dynamic", side_attr_list()),
482 void test_dynamic_nested_vla(void)
484 side_arg_dynamic_define_vec(nestedvla
,
486 side_arg_dynamic_u32(1, side_attr_list()),
487 side_arg_dynamic_u16(2, side_attr_list()),
488 side_arg_dynamic_u32(3, side_attr_list()),
492 side_arg_dynamic_define_vec(nestedvla2
,
494 side_arg_dynamic_u8(4, side_attr_list()),
495 side_arg_dynamic_u32(5, side_attr_list()),
496 side_arg_dynamic_u32(6, side_attr_list()),
500 side_arg_dynamic_define_vec(myvla
,
502 side_arg_dynamic_vla(&nestedvla
),
503 side_arg_dynamic_vla(&nestedvla2
),
507 my_provider_event_dynamic_nested_vla_enabled
= 1;
508 side_event(my_provider_event_dynamic_nested_vla
,
509 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
512 static side_define_event_variadic(my_provider_event_variadic
,
513 "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG
,
519 void test_variadic(void)
521 my_provider_event_variadic_enabled
= 1;
522 side_event_variadic(my_provider_event_variadic
,
525 side_arg_dynamic_field("a", side_arg_dynamic_u32(55, side_attr_list())),
526 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4, side_attr_list())),
532 static side_define_event_variadic(my_provider_event_static_variadic
,
533 "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG
,
535 side_field_u32("abc", side_attr_list()),
536 side_field_u16("def", side_attr_list()),
542 void test_static_variadic(void)
544 my_provider_event_static_variadic_enabled
= 1;
545 side_event_variadic(my_provider_event_static_variadic
,
551 side_arg_dynamic_field("a", side_arg_dynamic_u32(55, side_attr_list())),
552 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4, side_attr_list())),
558 static side_define_event(my_provider_event_bool
, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG
,
560 side_field_bool("a_false", side_attr_list()),
561 side_field_bool("b_true", side_attr_list()),
562 side_field_bool("c_true", side_attr_list()),
563 side_field_bool("d_true", side_attr_list()),
564 side_field_bool("e_true", side_attr_list()),
565 side_field_bool("f_false", side_attr_list()),
566 side_field_bool("g_true", side_attr_list()),
576 uint64_t c
= 0x12345678;
582 my_provider_event_bool_enabled
= 1;
583 side_event(my_provider_event_bool
,
596 static side_define_event_variadic(my_provider_event_dynamic_bool
,
597 "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG
,
603 void test_dynamic_bool(void)
605 my_provider_event_dynamic_bool_enabled
= 1;
606 side_event_variadic(my_provider_event_dynamic_bool
,
609 side_arg_dynamic_field("a_true", side_arg_dynamic_bool(55, side_attr_list())),
610 side_arg_dynamic_field("b_true", side_arg_dynamic_bool(-4, side_attr_list())),
611 side_arg_dynamic_field("c_false", side_arg_dynamic_bool(0, side_attr_list())),
612 side_arg_dynamic_field("d_true", side_arg_dynamic_bool(256, side_attr_list())),
618 static side_define_event(my_provider_event_dynamic_vla_visitor
,
619 "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG
,
621 side_field_dynamic("dynamic", side_attr_list()),
626 struct app_dynamic_vla_visitor_ctx
{
632 enum side_visitor_status
test_dynamic_vla_visitor(const struct side_tracer_dynamic_vla_visitor_ctx
*tracer_ctx
, void *_ctx
)
634 struct app_dynamic_vla_visitor_ctx
*ctx
= (struct app_dynamic_vla_visitor_ctx
*) _ctx
;
635 uint32_t length
= ctx
->length
, i
;
637 for (i
= 0; i
< length
; i
++) {
638 const struct side_arg_dynamic_vec elem
= {
639 .dynamic_type
= SIDE_DYNAMIC_TYPE_U32
,
645 .side_u32
= ctx
->ptr
[i
],
650 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
651 return SIDE_VISITOR_STATUS_ERROR
;
653 return SIDE_VISITOR_STATUS_OK
;
656 static uint32_t testarray_dynamic_vla
[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
659 void test_dynamic_vla_with_visitor(void)
661 my_provider_event_dynamic_vla_visitor_enabled
= 1;
662 side_event_cond(my_provider_event_dynamic_vla_visitor
) {
663 struct app_dynamic_vla_visitor_ctx ctx
= {
664 .ptr
= testarray_dynamic_vla
,
665 .length
= SIDE_ARRAY_SIZE(testarray_dynamic_vla
),
667 side_event_call(my_provider_event_dynamic_vla_visitor
,
670 side_arg_dynamic_vla_visitor(test_dynamic_vla_visitor
, &ctx
, side_attr_list())
677 static side_define_event(my_provider_event_dynamic_struct_visitor
,
678 "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG
,
680 side_field_dynamic("dynamic", side_attr_list()),
685 struct struct_visitor_pair
{
690 struct app_dynamic_struct_visitor_ctx
{
691 const struct struct_visitor_pair
*ptr
;
696 enum side_visitor_status
test_dynamic_struct_visitor(const struct side_tracer_dynamic_struct_visitor_ctx
*tracer_ctx
, void *_ctx
)
698 struct app_dynamic_struct_visitor_ctx
*ctx
= (struct app_dynamic_struct_visitor_ctx
*) _ctx
;
699 uint32_t length
= ctx
->length
, i
;
701 for (i
= 0; i
< length
; i
++) {
702 struct side_arg_dynamic_event_field dynamic_field
= {
703 .field_name
= ctx
->ptr
[i
].name
,
705 .dynamic_type
= SIDE_DYNAMIC_TYPE_U32
,
711 .side_u32
= ctx
->ptr
[i
].value
,
717 if (tracer_ctx
->write_field(tracer_ctx
, &dynamic_field
) != SIDE_VISITOR_STATUS_OK
)
718 return SIDE_VISITOR_STATUS_ERROR
;
720 return SIDE_VISITOR_STATUS_OK
;
723 static struct struct_visitor_pair testarray_dynamic_struct
[] = {
731 void test_dynamic_struct_with_visitor(void)
733 my_provider_event_dynamic_struct_visitor_enabled
= 1;
734 side_event_cond(my_provider_event_dynamic_struct_visitor
) {
735 struct app_dynamic_struct_visitor_ctx ctx
= {
736 .ptr
= testarray_dynamic_struct
,
737 .length
= SIDE_ARRAY_SIZE(testarray_dynamic_struct
),
739 side_event_call(my_provider_event_dynamic_struct_visitor
,
742 side_arg_dynamic_struct_visitor(test_dynamic_struct_visitor
, &ctx
, side_attr_list())
749 static side_define_event(my_provider_event_user_attribute
, "myprovider", "myevent_user_attribute", SIDE_LOGLEVEL_DEBUG
,
751 side_field_u32("abc", side_attr_list()),
752 side_field_s64("def", side_attr_list()),
755 side_attr("user_attribute_a", side_attr_string("val1")),
756 side_attr("user_attribute_b", side_attr_string("val2")),
761 void test_event_user_attribute(void)
763 my_provider_event_user_attribute_enabled
= 1;
764 side_event(my_provider_event_user_attribute
, side_arg_list(side_arg_u32(1), side_arg_s64(2)));
767 static side_define_event(my_provider_field_user_attribute
, "myprovider", "myevent_field_attribute", SIDE_LOGLEVEL_DEBUG
,
769 side_field_u32("abc",
771 side_attr("user_attribute_a", side_attr_string("val1")),
772 side_attr("user_attribute_b", side_attr_u32(2)),
775 side_field_s64("def",
777 side_attr("user_attribute_c", side_attr_string("val3")),
778 side_attr("user_attribute_d", side_attr_s64(-5)),
786 void test_field_user_attribute(void)
788 my_provider_field_user_attribute_enabled
= 1;
789 side_event(my_provider_field_user_attribute
, side_arg_list(side_arg_u32(1), side_arg_s64(2)));
792 static side_define_event_variadic(my_provider_event_variadic_attr
,
793 "myprovider", "myvariadiceventattr", SIDE_LOGLEVEL_DEBUG
,
799 void test_variadic_attr(void)
801 my_provider_event_variadic_attr_enabled
= 1;
802 side_event_variadic(my_provider_event_variadic_attr
,
805 side_arg_dynamic_field("a",
806 side_arg_dynamic_u32(55,
808 side_attr("user_attribute_c", side_attr_string("valX")),
809 side_attr("user_attribute_d", side_attr_u8(55)),
813 side_arg_dynamic_field("b",
814 side_arg_dynamic_s8(-4,
816 side_attr("X", side_attr_u8(1)),
817 side_attr("Y", side_attr_s8(2)),
826 static side_define_event_variadic(my_provider_event_variadic_vla_attr
,
827 "myprovider", "myvariadiceventvlaattr", SIDE_LOGLEVEL_DEBUG
,
833 void test_variadic_vla_attr(void)
835 side_arg_dynamic_define_vec(myvla
,
837 side_arg_dynamic_u32(1,
839 side_attr("Z", side_attr_u8(0)),
840 side_attr("A", side_attr_u8(123)),
843 side_arg_dynamic_u32(2, side_attr_list()),
844 side_arg_dynamic_u32(3, side_attr_list()),
847 side_attr("X", side_attr_u8(1)),
848 side_attr("Y", side_attr_u8(2)),
851 my_provider_event_variadic_vla_attr_enabled
= 1;
852 side_event_variadic(my_provider_event_variadic_vla_attr
,
855 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla
)),
861 static side_define_event_variadic(my_provider_event_variadic_struct_attr
,
862 "myprovider", "myvariadiceventstructattr", SIDE_LOGLEVEL_DEBUG
,
868 void test_variadic_struct_attr(void)
870 my_provider_event_variadic_struct_attr_enabled
= 1;
871 side_event_cond(my_provider_event_variadic_struct_attr
) {
872 side_arg_dynamic_define_struct(mystruct
,
874 side_arg_dynamic_field("a",
875 side_arg_dynamic_u32(43,
877 side_attr("A", side_attr_bool(true)),
881 side_arg_dynamic_field("b", side_arg_dynamic_u8(55, side_attr_list())),
884 side_attr("X", side_attr_u8(1)),
885 side_attr("Y", side_attr_u8(2)),
888 side_event_call_variadic(my_provider_event_variadic_struct_attr
,
891 side_arg_dynamic_field("a", side_arg_dynamic_struct(&mystruct
)),
898 static side_define_event(my_provider_event_float
, "myprovider", "myeventfloat", SIDE_LOGLEVEL_DEBUG
,
901 side_field_float_binary16("binary16", side_attr_list()),
904 side_field_float_binary32("binary32", side_attr_list()),
907 side_field_float_binary64("binary64", side_attr_list()),
910 side_field_float_binary128("binary128", side_attr_list()),
917 void test_float(void)
919 my_provider_event_float_enabled
= 1;
920 side_event(my_provider_event_float
,
923 side_arg_float_binary16(1.1),
926 side_arg_float_binary32(2.2),
929 side_arg_float_binary64(3.3),
932 side_arg_float_binary128(4.4),
938 static side_define_event_variadic(my_provider_event_variadic_float
,
939 "myprovider", "myvariadicfloat", SIDE_LOGLEVEL_DEBUG
,
945 void test_variadic_float(void)
947 my_provider_event_variadic_float_enabled
= 1;
948 side_event_variadic(my_provider_event_variadic_float
,
952 side_arg_dynamic_field("binary16",
953 side_arg_dynamic_float_binary16(1.1, side_attr_list())
957 side_arg_dynamic_field("binary32",
958 side_arg_dynamic_float_binary32(2.2, side_attr_list())
962 side_arg_dynamic_field("binary64",
963 side_arg_dynamic_float_binary64(3.3, side_attr_list())
967 side_arg_dynamic_field("binary128",
968 side_arg_dynamic_float_binary128(4.4, side_attr_list())
976 static side_define_enum(myenum
,
977 side_enum_mapping_list(
978 side_enum_mapping_range("one-ten", 1, 10),
979 side_enum_mapping_range("100-200", 100, 200),
980 side_enum_mapping_value("200", 200),
981 side_enum_mapping_value("300", 300),
986 static side_define_event(my_provider_event_enum
, "myprovider", "myeventenum", SIDE_LOGLEVEL_DEBUG
,
988 side_field_enum("5", side_elem(side_type_u32(side_attr_list())), &myenum
),
989 side_field_enum("400", side_elem(side_type_u64(side_attr_list())), &myenum
),
990 side_field_enum("200", side_elem(side_type_u8(side_attr_list())), &myenum
),
991 side_field_enum("-100", side_elem(side_type_s8(side_attr_list())), &myenum
),
999 my_provider_event_enum_enabled
= 1;
1000 side_event(my_provider_event_enum
,
1010 /* A bitmap enum maps bits to labels. */
1011 static side_define_enum_bitmap(myenum_bitmap
,
1012 side_enum_bitmap_mapping_list(
1013 side_enum_bitmap_mapping_value("0", 0),
1014 side_enum_bitmap_mapping_range("1-2", 1, 2),
1015 side_enum_bitmap_mapping_range("2-4", 2, 4),
1016 side_enum_bitmap_mapping_value("3", 3),
1017 side_enum_bitmap_mapping_value("30", 30),
1018 side_enum_bitmap_mapping_value("63", 63),
1019 side_enum_bitmap_mapping_range("158-160", 158, 160),
1020 side_enum_bitmap_mapping_value("159", 159),
1021 side_enum_bitmap_mapping_range("500-700", 500, 700),
1026 static side_define_event(my_provider_event_enum_bitmap
, "myprovider", "myeventenumbitmap", SIDE_LOGLEVEL_DEBUG
,
1028 side_field_enum_bitmap32("bit_0", &myenum_bitmap
),
1029 side_field_enum_bitmap32("bit_1", &myenum_bitmap
),
1030 side_field_enum_bitmap8("bit_2", &myenum_bitmap
),
1031 side_field_enum_bitmap8("bit_3", &myenum_bitmap
),
1032 side_field_enum_bitmap32("bit_30", &myenum_bitmap
),
1033 side_field_enum_bitmap32("bit_31", &myenum_bitmap
),
1034 side_field_enum_bitmap64("bit_63", &myenum_bitmap
),
1035 side_field_enum_bitmap64("bits_1+63", &myenum_bitmap
),
1036 side_field_enum_bitmap_array("bit_159", &myenum_bitmap
,
1037 side_elem(side_type_u32(side_attr_list())), 5),
1038 side_field_enum_bitmap_vla("bit_159", &myenum_bitmap
,
1039 side_elem(side_type_u32(side_attr_list()))),
1045 void test_enum_bitmap(void)
1047 my_provider_event_enum_bitmap_enabled
= 1;
1048 side_event_cond(my_provider_event_enum_bitmap
) {
1049 side_arg_define_vec(myarray
,
1055 side_arg_u32(0x80000000), /* bit 159 */
1058 side_event_call(my_provider_event_enum_bitmap
,
1060 side_arg_enum_bitmap32(1 << 0),
1061 side_arg_enum_bitmap32(1 << 1),
1062 side_arg_enum_bitmap8(1 << 2),
1063 side_arg_enum_bitmap8(1 << 3),
1064 side_arg_enum_bitmap32(1 << 30),
1065 side_arg_enum_bitmap32(1 << 31),
1066 side_arg_enum_bitmap64(1ULL << 63),
1067 side_arg_enum_bitmap64((1ULL << 1) | (1ULL << 63)),
1068 side_arg_enum_bitmap_array(&myarray
),
1069 side_arg_enum_bitmap_vla(&myarray
),
1075 static uint8_t blob_fixint
[] = { 0x55, 0x44, 0x33, 0x22, 0x11 };
1077 static side_define_event_variadic(my_provider_event_blob
, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG
,
1079 side_field_blob("blobfield", side_attr_list()),
1080 side_field_array("arrayblob", side_elem(side_type_blob(side_attr_list())), 3, side_attr_list()),
1081 side_field_array("arrayblobfix", side_elem(side_type_blob(side_attr_list())), SIDE_ARRAY_SIZE(blob_fixint
), side_attr_list()),
1082 side_field_vla("vlablobfix", side_elem(side_type_blob(side_attr_list())), side_attr_list()),
1088 void test_blob(void)
1090 my_provider_event_blob_enabled
= 1;
1091 side_event_cond(my_provider_event_blob
) {
1092 side_arg_define_vec(myarray
, side_arg_list(side_arg_blob(1), side_arg_blob(2), side_arg_blob(3)));
1093 side_arg_dynamic_define_vec(myvla
,
1095 side_arg_dynamic_blob(0x22, side_attr_list()),
1096 side_arg_dynamic_blob(0x33, side_attr_list()),
1100 side_event_call_variadic(my_provider_event_blob
,
1102 side_arg_blob(0x55),
1103 side_arg_array(&myarray
),
1104 side_arg_array_blob(blob_fixint
),
1105 side_arg_vla_blob(blob_fixint
, SIDE_ARRAY_SIZE(blob_fixint
)),
1108 side_arg_dynamic_field("varblobfield",
1109 side_arg_dynamic_blob(0x55, side_attr_list())
1111 side_arg_dynamic_field("varblobvla", side_arg_dynamic_vla(&myvla
)),
1118 static side_define_event_variadic(my_provider_event_format_string
,
1119 "myprovider", "myeventformatstring", SIDE_LOGLEVEL_DEBUG
,
1121 side_field_string("fmt", side_attr_list()),
1124 side_attr("lang.c.format_string", side_attr_bool(true)),
1129 void test_fmt_string(void)
1131 my_provider_event_format_string_enabled
= 1;
1132 side_event_cond(my_provider_event_format_string
) {
1133 side_arg_dynamic_define_vec(args
,
1135 side_arg_dynamic_string("blah", side_attr_list()),
1136 side_arg_dynamic_s32(123, side_attr_list()),
1140 side_event_call_variadic(my_provider_event_format_string
,
1142 side_arg_string("This is a formatted string with str: %s int: %d"),
1145 side_arg_dynamic_field("arguments", side_arg_dynamic_vla(&args
)),
1155 test_struct_literal();
1160 test_vla_visitor_2d();
1161 test_array_fixint();
1163 test_dynamic_basic_type();
1165 test_dynamic_null();
1166 test_dynamic_struct();
1167 test_dynamic_nested_struct();
1168 test_dynamic_vla_struct();
1169 test_dynamic_struct_vla();
1170 test_dynamic_nested_vla();
1172 test_static_variadic();
1174 test_dynamic_bool();
1175 test_dynamic_vla_with_visitor();
1176 test_dynamic_struct_with_visitor();
1177 test_event_user_attribute();
1178 test_field_user_attribute();
1179 test_variadic_attr();
1180 test_variadic_vla_attr();
1181 test_variadic_struct_attr();
1183 test_variadic_float();