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("abc", SIDE_TYPE_U32
),
20 side_field("def", SIDE_TYPE_S64
),
21 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
26 void test_fields(void)
31 my_provider_event
.enabled
= 1;
32 side_event(&my_provider_event
, side_arg_list(side_arg_u32(uw
), side_arg_s64(sdw
),
33 side_arg_dynamic(side_arg_dynamic_string("zzz"))));
36 static side_define_event(my_provider_event2
, "myprovider", "myevent2", SIDE_LOGLEVEL_DEBUG
,
38 side_field_struct("structfield",
40 side_field("x", SIDE_TYPE_U32
),
41 side_field("y", SIDE_TYPE_S64
),
44 side_field("z", SIDE_TYPE_U8
),
49 void test_struct(void)
51 my_provider_event2
.enabled
= 1;
52 side_event_cond(&my_provider_event2
) {
53 side_arg_define_vec(mystruct
, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
54 side_event_call(&my_provider_event2
, side_arg_list(side_arg_struct(&mystruct
), side_arg_u8(55)));
58 static side_define_event(my_provider_event_array
, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG
,
60 side_field_array("arr", side_elem_type(SIDE_TYPE_U32
), 3),
61 side_field("v", SIDE_TYPE_S64
),
68 my_provider_event_array
.enabled
= 1;
69 side_event_cond(&my_provider_event_array
) {
70 side_arg_define_vec(myarray
, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
71 side_event_call(&my_provider_event_array
, side_arg_list(side_arg_array(&myarray
), side_arg_s64(42)));
75 static side_define_event(my_provider_event_vla
, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG
,
77 side_field_vla("vla", side_elem_type(SIDE_TYPE_U32
)),
78 side_field("v", SIDE_TYPE_S64
),
85 my_provider_event_vla
.enabled
= 1;
86 side_event_cond(&my_provider_event_vla
) {
87 side_arg_define_vec(myvla
, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
88 side_event_call(&my_provider_event_vla
, side_arg_list(side_arg_vla(&myvla
), side_arg_s64(42)));
92 /* 1D array visitor */
94 struct app_visitor_ctx
{
100 enum side_visitor_status
test_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
102 struct app_visitor_ctx
*ctx
= (struct app_visitor_ctx
*) _ctx
;
103 uint32_t length
= ctx
->length
, i
;
105 for (i
= 0; i
< length
; i
++) {
106 const struct side_arg_vec elem
= {
107 .type
= SIDE_TYPE_U32
,
109 .side_u32
= ctx
->ptr
[i
],
112 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
113 return SIDE_VISITOR_STATUS_ERROR
;
115 return SIDE_VISITOR_STATUS_OK
;
118 static uint32_t testarray
[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
120 static side_define_event(my_provider_event_vla_visitor
, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG
,
122 side_field_vla_visitor("vlavisit", side_elem_type(SIDE_TYPE_U32
), test_visitor
),
123 side_field("v", SIDE_TYPE_S64
),
128 void test_vla_visitor(void)
130 my_provider_event_vla_visitor
.enabled
= 1;
131 side_event_cond(&my_provider_event_vla_visitor
) {
132 struct app_visitor_ctx ctx
= {
134 .length
= SIDE_ARRAY_SIZE(testarray
),
136 side_event_call(&my_provider_event_vla_visitor
, side_arg_list(side_arg_vla_visitor(&ctx
), side_arg_s64(42)));
140 /* 2D array visitor */
142 struct app_visitor_2d_inner_ctx
{
148 enum side_visitor_status
test_inner_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
150 struct app_visitor_2d_inner_ctx
*ctx
= (struct app_visitor_2d_inner_ctx
*) _ctx
;
151 uint32_t length
= ctx
->length
, i
;
153 for (i
= 0; i
< length
; i
++) {
154 const struct side_arg_vec elem
= {
155 .type
= SIDE_TYPE_U32
,
157 .side_u32
= ctx
->ptr
[i
],
160 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
161 return SIDE_VISITOR_STATUS_ERROR
;
163 return SIDE_VISITOR_STATUS_OK
;
166 struct app_visitor_2d_outer_ctx
{
167 const uint32_t (*ptr
)[2];
172 enum side_visitor_status
test_outer_visitor(const struct side_tracer_visitor_ctx
*tracer_ctx
, void *_ctx
)
174 struct app_visitor_2d_outer_ctx
*ctx
= (struct app_visitor_2d_outer_ctx
*) _ctx
;
175 uint32_t length
= ctx
->length
, i
;
177 for (i
= 0; i
< length
; i
++) {
178 struct app_visitor_2d_inner_ctx inner_ctx
= {
182 const struct side_arg_vec elem
= side_arg_vla_visitor(&inner_ctx
);
183 if (tracer_ctx
->write_elem(tracer_ctx
, &elem
) != SIDE_VISITOR_STATUS_OK
)
184 return SIDE_VISITOR_STATUS_ERROR
;
186 return SIDE_VISITOR_STATUS_OK
;
189 static uint32_t testarray2d
[][2] = {
195 static side_define_event(my_provider_event_vla_visitor2d
, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG
,
197 side_field_vla_visitor("vlavisit2d",
198 side_elem(side_type_vla_visitor_decl(side_elem_type(SIDE_TYPE_U32
), test_inner_visitor
)), test_outer_visitor
),
199 side_field("v", SIDE_TYPE_S64
),
204 void test_vla_visitor_2d(void)
206 my_provider_event_vla_visitor2d
.enabled
= 1;
207 side_event_cond(&my_provider_event_vla_visitor2d
) {
208 struct app_visitor_2d_outer_ctx ctx
= {
210 .length
= SIDE_ARRAY_SIZE(testarray2d
),
212 side_event_call(&my_provider_event_vla_visitor2d
, side_arg_list(side_arg_vla_visitor(&ctx
), side_arg_s64(42)));
216 static int64_t array_fixint
[] = { -444, 555, 123, 2897432587 };
218 static side_define_event(my_provider_event_array_fixint
, "myprovider", "myarrayfixint", SIDE_LOGLEVEL_DEBUG
,
220 side_field_array("arrfixint", side_elem_type(SIDE_TYPE_S64
), SIDE_ARRAY_SIZE(array_fixint
)),
221 side_field("v", SIDE_TYPE_S64
),
226 void test_array_fixint(void)
228 my_provider_event_array_fixint
.enabled
= 1;
229 side_event(&my_provider_event_array_fixint
,
230 side_arg_list(side_arg_array_s64(array_fixint
), side_arg_s64(42)));
233 static int64_t vla_fixint
[] = { -444, 555, 123, 2897432587 };
235 static side_define_event(my_provider_event_vla_fixint
, "myprovider", "myvlafixint", SIDE_LOGLEVEL_DEBUG
,
237 side_field_vla("vlafixint", side_elem_type(SIDE_TYPE_S64
)),
238 side_field("v", SIDE_TYPE_S64
),
243 void test_vla_fixint(void)
245 my_provider_event_vla_fixint
.enabled
= 1;
246 side_event(&my_provider_event_vla_fixint
,
247 side_arg_list(side_arg_vla_s64(vla_fixint
, SIDE_ARRAY_SIZE(vla_fixint
)), side_arg_s64(42)));
250 static side_define_event(my_provider_event_dynamic_basic
,
251 "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG
,
253 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
258 void test_dynamic_basic_type(void)
260 my_provider_event_dynamic_basic
.enabled
= 1;
261 side_event(&my_provider_event_dynamic_basic
,
262 side_arg_list(side_arg_dynamic(side_arg_dynamic_s16(-33))));
265 static side_define_event(my_provider_event_dynamic_vla
,
266 "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG
,
268 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
273 void test_dynamic_vla(void)
275 side_arg_dynamic_define_vec(myvla
,
277 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
280 my_provider_event_dynamic_vla
.enabled
= 1;
281 side_event(&my_provider_event_dynamic_vla
,
282 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
285 static side_define_event(my_provider_event_dynamic_null
,
286 "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG
,
288 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
293 void test_dynamic_null(void)
295 my_provider_event_dynamic_null
.enabled
= 1;
296 side_event(&my_provider_event_dynamic_null
,
297 side_arg_list(side_arg_dynamic(side_arg_dynamic_null())));
300 static side_define_event(my_provider_event_dynamic_struct
,
301 "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG
,
303 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
308 void test_dynamic_struct(void)
310 side_arg_dynamic_define_struct(mystruct
,
312 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
313 side_arg_dynamic_field("b", side_arg_dynamic_string("zzz")),
314 side_arg_dynamic_field("c", side_arg_dynamic_null()),
318 my_provider_event_dynamic_struct
.enabled
= 1;
319 side_event(&my_provider_event_dynamic_struct
,
320 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
323 static side_define_event(my_provider_event_dynamic_nested_struct
,
324 "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG
,
326 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
331 void test_dynamic_nested_struct(void)
333 side_arg_dynamic_define_struct(nested
,
335 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
336 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
339 side_arg_dynamic_define_struct(nested2
,
341 side_arg_dynamic_field("aa", side_arg_dynamic_u64(128)),
342 side_arg_dynamic_field("bb", side_arg_dynamic_u16(1)),
345 side_arg_dynamic_define_struct(mystruct
,
347 side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested
)),
348 side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2
)),
351 my_provider_event_dynamic_nested_struct
.enabled
= 1;
352 side_event(&my_provider_event_dynamic_nested_struct
,
353 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
356 static side_define_event(my_provider_event_dynamic_vla_struct
,
357 "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG
,
359 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
364 void test_dynamic_vla_struct(void)
366 side_arg_dynamic_define_struct(nested
,
368 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
369 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
372 side_arg_dynamic_define_vec(myvla
,
374 side_arg_dynamic_struct(&nested
),
375 side_arg_dynamic_struct(&nested
),
376 side_arg_dynamic_struct(&nested
),
377 side_arg_dynamic_struct(&nested
),
380 my_provider_event_dynamic_vla_struct
.enabled
= 1;
381 side_event(&my_provider_event_dynamic_vla_struct
,
382 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
385 static side_define_event(my_provider_event_dynamic_struct_vla
,
386 "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG
,
388 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
393 void test_dynamic_struct_vla(void)
395 side_arg_dynamic_define_vec(myvla
,
397 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
400 side_arg_dynamic_define_vec(myvla2
,
402 side_arg_dynamic_u32(4), side_arg_dynamic_u64(5), side_arg_dynamic_u32(6),
405 side_arg_dynamic_define_struct(mystruct
,
407 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla
)),
408 side_arg_dynamic_field("b", side_arg_dynamic_vla(&myvla2
)),
411 my_provider_event_dynamic_struct_vla
.enabled
= 1;
412 side_event(&my_provider_event_dynamic_struct_vla
,
413 side_arg_list(side_arg_dynamic(side_arg_dynamic_struct(&mystruct
))));
416 static side_define_event(my_provider_event_dynamic_nested_vla
,
417 "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG
,
419 side_field("dynamic", SIDE_TYPE_DYNAMIC
),
424 void test_dynamic_nested_vla(void)
426 side_arg_dynamic_define_vec(nestedvla
,
428 side_arg_dynamic_u32(1), side_arg_dynamic_u16(2), side_arg_dynamic_u32(3),
431 side_arg_dynamic_define_vec(nestedvla2
,
433 side_arg_dynamic_u8(4), side_arg_dynamic_u32(5), side_arg_dynamic_u32(6),
436 side_arg_dynamic_define_vec(myvla
,
438 side_arg_dynamic_vla(&nestedvla
),
439 side_arg_dynamic_vla(&nestedvla2
),
442 my_provider_event_dynamic_nested_vla
.enabled
= 1;
443 side_event(&my_provider_event_dynamic_nested_vla
,
444 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla
))));
447 static side_define_event(my_provider_event_variadic
,
448 "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG
,
453 void test_variadic(void)
455 my_provider_event_variadic
.enabled
= 1;
456 side_event_variadic(&my_provider_event_variadic
,
459 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
460 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
465 static side_define_event(my_provider_event_static_variadic
,
466 "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG
,
468 side_field("abc", SIDE_TYPE_U32
),
469 side_field("def", SIDE_TYPE_U16
),
474 void test_static_variadic(void)
476 my_provider_event_static_variadic
.enabled
= 1;
477 side_event_variadic(&my_provider_event_static_variadic
,
483 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
484 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
489 static side_define_event(my_provider_event_bool
, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG
,
491 side_field("a_false", SIDE_TYPE_BOOL
),
492 side_field("b_true", SIDE_TYPE_BOOL
),
493 side_field("c_true", SIDE_TYPE_BOOL
),
494 side_field("d_true", SIDE_TYPE_BOOL
),
495 side_field("e_true", SIDE_TYPE_BOOL
),
496 side_field("f_false", SIDE_TYPE_BOOL
),
497 side_field("g_true", SIDE_TYPE_BOOL
),
506 uint64_t c
= 0x12345678;
512 my_provider_event_bool
.enabled
= 1;
513 side_event(&my_provider_event_bool
,
526 static side_define_event(my_provider_event_dynamic_bool
,
527 "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG
,
532 void test_dynamic_bool(void)
534 my_provider_event_dynamic_bool
.enabled
= 1;
535 side_event_variadic(&my_provider_event_dynamic_bool
,
538 side_arg_dynamic_field("a_true", side_arg_dynamic_bool(55)),
539 side_arg_dynamic_field("b_true", side_arg_dynamic_bool(-4)),
540 side_arg_dynamic_field("c_false", side_arg_dynamic_bool(0)),
541 side_arg_dynamic_field("d_true", side_arg_dynamic_bool(256)),
553 test_vla_visitor_2d();
556 test_dynamic_basic_type();
559 test_dynamic_struct();
560 test_dynamic_nested_struct();
561 test_dynamic_vla_struct();
562 test_dynamic_struct_vla();
563 test_dynamic_nested_vla();
565 test_static_variadic();