1 // SPDX-License-Identifier: MIT
3 * Copyright 2022 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
11 #include <side/trace.h>
14 /* User code example */
16 static side_define_event(my_provider_event
, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG
,
18 side_field("abc", SIDE_TYPE_U32
),
19 side_field("def", SIDE_TYPE_S64
),
20 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
25 void test_fields(void)
30 my_provider_event
.enabled
= 1;
31 side_event(&my_provider_event
, side_arg_list(side_arg_u32(uw
), side_arg_s64(sdw
),
32 side_arg_dynamic(side_arg_dynamic_string("zzz"))));
35 static side_define_event(my_provider_event2
, "myprovider", "myevent2", SIDE_LOGLEVEL_DEBUG
,
37 side_field_struct("structfield",
39 side_field("x", SIDE_TYPE_U32
),
40 side_field("y", SIDE_TYPE_S64
),
43 side_field("z", SIDE_TYPE_U8
),
48 void test_struct(void)
50 my_provider_event2
.enabled
= 1;
51 side_event_cond(&my_provider_event2
) {
52 side_arg_define_vec(mystruct
, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
53 side_event_call(&my_provider_event2
, side_arg_list(side_arg_struct(&mystruct
), side_arg_u8(55)));
57 static side_define_event(my_provider_event_array
, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG
,
59 side_field_array("arr", side_elem_type(SIDE_TYPE_U32
), 3),
60 side_field("v", SIDE_TYPE_S64
),
67 my_provider_event_array
.enabled
= 1;
68 side_event_cond(&my_provider_event_array
) {
69 side_arg_define_vec(myarray
, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
70 side_event_call(&my_provider_event_array
, side_arg_list(side_arg_array(&myarray
), side_arg_s64(42)));
74 static side_define_event(my_provider_event_vla
, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG
,
76 side_field_vla("vla", side_elem_type(SIDE_TYPE_U32
)),
77 side_field("v", SIDE_TYPE_S64
),
84 my_provider_event_vla
.enabled
= 1;
85 side_event_cond(&my_provider_event_vla
) {
86 side_arg_define_vec(myvla
, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
87 side_event_call(&my_provider_event_vla
, side_arg_list(side_arg_vla(&myvla
), side_arg_s64(42)));
91 /* 1D array visitor */
93 struct app_visitor_ctx
{
99 enum side_visitor_status
test_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
101 struct app_visitor_ctx
*ctx
= (struct app_visitor_ctx
*) _ctx
;
102 uint32_t length
= ctx
->length
, i
;
104 for (i
= 0; i
< length
; i
++) {
105 const struct side_arg_vec elem
= {
106 .type
= SIDE_TYPE_U32
,
108 .side_u32
= ctx
->ptr
[i
],
111 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
112 return SIDE_VISITOR_STATUS_ERROR
;
114 return SIDE_VISITOR_STATUS_OK
;
117 static uint32_t testarray
[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
119 static side_define_event(my_provider_event_vla_visitor
, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG
,
121 side_field_vla_visitor("vlavisit", side_elem_type(SIDE_TYPE_U32
), test_visitor
),
122 side_field("v", SIDE_TYPE_S64
),
127 void test_vla_visitor(void)
129 my_provider_event_vla_visitor
.enabled
= 1;
130 side_event_cond(&my_provider_event_vla_visitor
) {
131 struct app_visitor_ctx ctx
= {
133 .length
= SIDE_ARRAY_SIZE(testarray
),
135 side_event_call(&my_provider_event_vla_visitor
, side_arg_list(side_arg_vla_visitor(&ctx
), side_arg_s64(42)));
139 /* 2D array visitor */
141 struct app_visitor_2d_inner_ctx
{
147 enum side_visitor_status
test_inner_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
149 struct app_visitor_2d_inner_ctx
*ctx
= (struct app_visitor_2d_inner_ctx
*) _ctx
;
150 uint32_t length
= ctx
->length
, i
;
152 for (i
= 0; i
< length
; i
++) {
153 const struct side_arg_vec elem
= {
154 .type
= SIDE_TYPE_U32
,
156 .side_u32
= ctx
->ptr
[i
],
159 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
160 return SIDE_VISITOR_STATUS_ERROR
;
162 return SIDE_VISITOR_STATUS_OK
;
165 struct app_visitor_2d_outer_ctx
{
166 const uint32_t (*ptr
)[2];
171 enum side_visitor_status
test_outer_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
173 struct app_visitor_2d_outer_ctx
*ctx
= (struct app_visitor_2d_outer_ctx
*) _ctx
;
174 uint32_t length
= ctx
->length
, i
;
176 for (i
= 0; i
< length
; i
++) {
177 struct app_visitor_2d_inner_ctx inner_ctx
= {
181 const struct side_arg_vec elem
= side_arg_vla_visitor(&inner_ctx
);
182 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
183 return SIDE_VISITOR_STATUS_ERROR
;
185 return SIDE_VISITOR_STATUS_OK
;
188 static uint32_t testarray2d
[][2] = {
194 static side_define_event(my_provider_event_vla_visitor2d
, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG
,
196 side_field_vla_visitor("vlavisit2d",
197 side_elem(side_type_vla_visitor_decl(side_elem_type(SIDE_TYPE_U32
), test_inner_visitor
)), test_outer_visitor
),
198 side_field("v", SIDE_TYPE_S64
),
203 void test_vla_visitor_2d(void)
205 my_provider_event_vla_visitor2d
.enabled
= 1;
206 side_event_cond(&my_provider_event_vla_visitor2d
) {
207 struct app_visitor_2d_outer_ctx ctx
= {
209 .length
= SIDE_ARRAY_SIZE(testarray2d
),
211 side_event_call(&my_provider_event_vla_visitor2d
, side_arg_list(side_arg_vla_visitor(&ctx
), side_arg_s64(42)));
215 static int64_t array_fixint
[] = { -444, 555, 123, 2897432587 };
217 static side_define_event(my_provider_event_array_fixint
, "myprovider", "myarrayfixint", SIDE_LOGLEVEL_DEBUG
,
219 side_field_array("arrfixint", side_elem_type(SIDE_TYPE_S64
), SIDE_ARRAY_SIZE(array_fixint
)),
220 side_field("v", SIDE_TYPE_S64
),
225 void test_array_fixint(void)
227 my_provider_event_array_fixint
.enabled
= 1;
228 side_event(&my_provider_event_array_fixint
,
229 side_arg_list(side_arg_array_s64(array_fixint
), side_arg_s64(42)));
232 static int64_t vla_fixint
[] = { -444, 555, 123, 2897432587 };
234 static side_define_event(my_provider_event_vla_fixint
, "myprovider", "myvlafixint", SIDE_LOGLEVEL_DEBUG
,
236 side_field_vla("vlafixint", side_elem_type(SIDE_TYPE_S64
)),
237 side_field("v", SIDE_TYPE_S64
),
242 void test_vla_fixint(void)
244 my_provider_event_vla_fixint
.enabled
= 1;
245 side_event(&my_provider_event_vla_fixint
,
246 side_arg_list(side_arg_vla_s64(vla_fixint
, SIDE_ARRAY_SIZE(vla_fixint
)), side_arg_s64(42)));
249 static side_define_event(my_provider_event_dynamic_basic
,
250 "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG
,
252 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
257 void test_dynamic_basic_type(void)
259 my_provider_event_dynamic_basic
.enabled
= 1;
260 side_event(&my_provider_event_dynamic_basic
,
261 side_arg_list(side_arg_dynamic(side_arg_dynamic_s16(-33))));
264 static side_define_event(my_provider_event_dynamic_vla
,
265 "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG
,
267 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
272 void test_dynamic_vla(void)
274 side_arg_dynamic_define_vec(myvla
,
276 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
279 my_provider_event_dynamic_vla
.enabled
= 1;
280 side_event(&my_provider_event_dynamic_vla
,
281 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
284 static side_define_event(my_provider_event_dynamic_null
,
285 "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG
,
287 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
292 void test_dynamic_null(void)
294 my_provider_event_dynamic_null
.enabled
= 1;
295 side_event(&my_provider_event_dynamic_null
,
296 side_arg_list(side_arg_dynamic(side_arg_dynamic_null())));
299 static side_define_event(my_provider_event_dynamic_struct
,
300 "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG
,
302 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
307 void test_dynamic_struct(void)
309 side_arg_dynamic_define_struct(mystruct
,
311 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
312 side_arg_dynamic_field("b", side_arg_dynamic_string("zzz")),
313 side_arg_dynamic_field("c", side_arg_dynamic_null()),
317 my_provider_event_dynamic_struct
.enabled
= 1;
318 side_event(&my_provider_event_dynamic_struct
,
319 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
322 static side_define_event(my_provider_event_dynamic_nested_struct
,
323 "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG
,
325 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
330 void test_dynamic_nested_struct(void)
332 side_arg_dynamic_define_struct(nested
,
334 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
335 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
338 side_arg_dynamic_define_struct(nested2
,
340 side_arg_dynamic_field("aa", side_arg_dynamic_u64(128)),
341 side_arg_dynamic_field("bb", side_arg_dynamic_u16(1)),
344 side_arg_dynamic_define_struct(mystruct
,
346 side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested
)),
347 side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2
)),
350 my_provider_event_dynamic_nested_struct
.enabled
= 1;
351 side_event(&my_provider_event_dynamic_nested_struct
,
352 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
355 static side_define_event(my_provider_event_dynamic_vla_struct
,
356 "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG
,
358 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
363 void test_dynamic_vla_struct(void)
365 side_arg_dynamic_define_struct(nested
,
367 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
368 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
371 side_arg_dynamic_define_vec(myvla
,
373 side_arg_dynamic_struct(&nested
),
374 side_arg_dynamic_struct(&nested
),
375 side_arg_dynamic_struct(&nested
),
376 side_arg_dynamic_struct(&nested
),
379 my_provider_event_dynamic_vla_struct
.enabled
= 1;
380 side_event(&my_provider_event_dynamic_vla_struct
,
381 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
384 static side_define_event(my_provider_event_dynamic_struct_vla
,
385 "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG
,
387 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
392 void test_dynamic_struct_vla(void)
394 side_arg_dynamic_define_vec(myvla
,
396 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
399 side_arg_dynamic_define_vec(myvla2
,
401 side_arg_dynamic_u32(4), side_arg_dynamic_u64(5), side_arg_dynamic_u32(6),
404 side_arg_dynamic_define_struct(mystruct
,
406 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla
)),
407 side_arg_dynamic_field("b", side_arg_dynamic_vla(&myvla2
)),
410 my_provider_event_dynamic_struct_vla
.enabled
= 1;
411 side_event(&my_provider_event_dynamic_struct_vla
,
412 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
415 static side_define_event(my_provider_event_dynamic_nested_vla
,
416 "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG
,
418 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
423 void test_dynamic_nested_vla(void)
425 side_arg_dynamic_define_vec(nestedvla
,
427 side_arg_dynamic_u32(1), side_arg_dynamic_u16(2), side_arg_dynamic_u32(3),
430 side_arg_dynamic_define_vec(nestedvla2
,
432 side_arg_dynamic_u8(4), side_arg_dynamic_u32(5), side_arg_dynamic_u32(6),
435 side_arg_dynamic_define_vec(myvla
,
437 side_arg_dynamic_vla(&nestedvla
),
438 side_arg_dynamic_vla(&nestedvla2
),
441 my_provider_event_dynamic_nested_vla
.enabled
= 1;
442 side_event(&my_provider_event_dynamic_nested_vla
,
443 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
446 static side_define_event(my_provider_event_variadic
,
447 "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG
,
452 void test_variadic(void)
454 my_provider_event_variadic
.enabled
= 1;
455 side_event_variadic(&my_provider_event_variadic
,
458 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
459 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
464 static side_define_event(my_provider_event_static_variadic
,
465 "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG
,
467 side_field("abc", SIDE_TYPE_U32
),
468 side_field("def", SIDE_TYPE_U16
),
473 void test_static_variadic(void)
475 my_provider_event_static_variadic
.enabled
= 1;
476 side_event_variadic(&my_provider_event_static_variadic
,
482 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
483 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
495 test_vla_visitor_2d();
498 test_dynamic_basic_type();
501 test_dynamic_struct();
502 test_dynamic_nested_struct();
503 test_dynamic_vla_struct();
504 test_dynamic_struct_vla();
505 test_dynamic_nested_vla();
507 test_static_variadic();