Implement dynamic struct visitor
[libside.git] / src / test.c
CommitLineData
f611d0c3
MD
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>
4f40d951 10#include <stdbool.h>
f611d0c3
MD
11
12#include <side/trace.h>
13#include "tracer.h"
14
15/* User code example */
16
17static side_define_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG,
18 side_field_list(
91d140a6
MD
19 side_field("abc", SIDE_TYPE_U32),
20 side_field("def", SIDE_TYPE_S64),
21 side_field("dynamic", SIDE_TYPE_DYNAMIC),
f611d0c3
MD
22 )
23);
24
25static
26void test_fields(void)
27{
28 uint32_t uw = 42;
29 int64_t sdw = -500;
30
31 my_provider_event.enabled = 1;
a2e2357e
MD
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"))));
f611d0c3
MD
34}
35
36static side_define_event(my_provider_event2, "myprovider", "myevent2", SIDE_LOGLEVEL_DEBUG,
37 side_field_list(
38 side_field_struct("structfield",
39 side_field_list(
91d140a6
MD
40 side_field("x", SIDE_TYPE_U32),
41 side_field("y", SIDE_TYPE_S64),
f611d0c3
MD
42 )
43 ),
91d140a6 44 side_field("z", SIDE_TYPE_U8),
f611d0c3
MD
45 )
46);
47
48static
49void test_struct(void)
50{
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)));
55 }
56}
57
58static side_define_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG,
59 side_field_list(
cdd6e858 60 side_field_array("arr", side_elem_type(SIDE_TYPE_U32), 3),
91d140a6 61 side_field("v", SIDE_TYPE_S64),
f611d0c3
MD
62 )
63);
64
65static
66void test_array(void)
67{
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)));
72 }
73}
74
75static side_define_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG,
76 side_field_list(
cdd6e858 77 side_field_vla("vla", side_elem_type(SIDE_TYPE_U32)),
91d140a6 78 side_field("v", SIDE_TYPE_S64),
f611d0c3
MD
79 )
80);
81
82static
83void test_vla(void)
84{
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)));
89 }
90}
91
cdd6e858
MD
92/* 1D array visitor */
93
f611d0c3
MD
94struct app_visitor_ctx {
95 const uint32_t *ptr;
352a4b77 96 uint32_t length;
f611d0c3
MD
97};
98
352a4b77
MD
99static
100enum side_visitor_status test_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
f611d0c3
MD
101{
102 struct app_visitor_ctx *ctx = (struct app_visitor_ctx *) _ctx;
352a4b77
MD
103 uint32_t length = ctx->length, i;
104
105 for (i = 0; i < length; i++) {
106 const struct side_arg_vec elem = {
107 .type = SIDE_TYPE_U32,
108 .u = {
109 .side_u32 = ctx->ptr[i],
110 },
111 };
db6ecef9
MD
112 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
113 return SIDE_VISITOR_STATUS_ERROR;
352a4b77 114 }
f611d0c3
MD
115 return SIDE_VISITOR_STATUS_OK;
116}
117
118static uint32_t testarray[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
119
120static side_define_event(my_provider_event_vla_visitor, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG,
121 side_field_list(
cdd6e858 122 side_field_vla_visitor("vlavisit", side_elem_type(SIDE_TYPE_U32), test_visitor),
91d140a6 123 side_field("v", SIDE_TYPE_S64),
f611d0c3
MD
124 )
125);
126
127static
128void test_vla_visitor(void)
129{
130 my_provider_event_vla_visitor.enabled = 1;
131 side_event_cond(&my_provider_event_vla_visitor) {
132 struct app_visitor_ctx ctx = {
133 .ptr = testarray,
352a4b77 134 .length = SIDE_ARRAY_SIZE(testarray),
f611d0c3
MD
135 };
136 side_event_call(&my_provider_event_vla_visitor, side_arg_list(side_arg_vla_visitor(&ctx), side_arg_s64(42)));
137 }
138}
139
cdd6e858
MD
140/* 2D array visitor */
141
142struct app_visitor_2d_inner_ctx {
143 const uint32_t *ptr;
144 uint32_t length;
145};
146
147static
148enum side_visitor_status test_inner_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
149{
150 struct app_visitor_2d_inner_ctx *ctx = (struct app_visitor_2d_inner_ctx *) _ctx;
151 uint32_t length = ctx->length, i;
152
153 for (i = 0; i < length; i++) {
154 const struct side_arg_vec elem = {
155 .type = SIDE_TYPE_U32,
156 .u = {
157 .side_u32 = ctx->ptr[i],
158 },
159 };
db6ecef9
MD
160 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
161 return SIDE_VISITOR_STATUS_ERROR;
cdd6e858
MD
162 }
163 return SIDE_VISITOR_STATUS_OK;
164}
165
166struct app_visitor_2d_outer_ctx {
167 const uint32_t (*ptr)[2];
168 uint32_t length;
169};
170
171static
172enum side_visitor_status test_outer_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
173{
174 struct app_visitor_2d_outer_ctx *ctx = (struct app_visitor_2d_outer_ctx *) _ctx;
175 uint32_t length = ctx->length, i;
176
177 for (i = 0; i < length; i++) {
178 struct app_visitor_2d_inner_ctx inner_ctx = {
179 .ptr = ctx->ptr[i],
180 .length = 2,
181 };
182 const struct side_arg_vec elem = side_arg_vla_visitor(&inner_ctx);
db6ecef9
MD
183 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
184 return SIDE_VISITOR_STATUS_ERROR;
cdd6e858
MD
185 }
186 return SIDE_VISITOR_STATUS_OK;
187}
188
189static uint32_t testarray2d[][2] = {
190 { 1, 2 },
191 { 33, 44 },
192 { 55, 66 },
193};
194
195static side_define_event(my_provider_event_vla_visitor2d, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG,
196 side_field_list(
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),
91d140a6 199 side_field("v", SIDE_TYPE_S64),
cdd6e858
MD
200 )
201);
202
203static
204void test_vla_visitor_2d(void)
205{
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 = {
209 .ptr = testarray2d,
210 .length = SIDE_ARRAY_SIZE(testarray2d),
211 };
212 side_event_call(&my_provider_event_vla_visitor2d, side_arg_list(side_arg_vla_visitor(&ctx), side_arg_s64(42)));
213 }
214}
215
ba845af5
MD
216static int64_t array_fixint[] = { -444, 555, 123, 2897432587 };
217
218static side_define_event(my_provider_event_array_fixint, "myprovider", "myarrayfixint", SIDE_LOGLEVEL_DEBUG,
219 side_field_list(
cdd6e858 220 side_field_array("arrfixint", side_elem_type(SIDE_TYPE_S64), SIDE_ARRAY_SIZE(array_fixint)),
91d140a6 221 side_field("v", SIDE_TYPE_S64),
ba845af5
MD
222 )
223);
224
225static
226void test_array_fixint(void)
227{
228 my_provider_event_array_fixint.enabled = 1;
1533629f
MD
229 side_event(&my_provider_event_array_fixint,
230 side_arg_list(side_arg_array_s64(array_fixint), side_arg_s64(42)));
231}
232
233static int64_t vla_fixint[] = { -444, 555, 123, 2897432587 };
234
235static side_define_event(my_provider_event_vla_fixint, "myprovider", "myvlafixint", SIDE_LOGLEVEL_DEBUG,
236 side_field_list(
cdd6e858 237 side_field_vla("vlafixint", side_elem_type(SIDE_TYPE_S64)),
91d140a6 238 side_field("v", SIDE_TYPE_S64),
1533629f
MD
239 )
240);
241
242static
243void test_vla_fixint(void)
244{
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)));
ba845af5
MD
248}
249
a2e2357e
MD
250static side_define_event(my_provider_event_dynamic_basic,
251 "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG,
252 side_field_list(
91d140a6 253 side_field("dynamic", SIDE_TYPE_DYNAMIC),
a2e2357e
MD
254 )
255);
256
257static
258void test_dynamic_basic_type(void)
259{
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))));
263}
264
265static side_define_event(my_provider_event_dynamic_vla,
266 "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG,
267 side_field_list(
91d140a6 268 side_field("dynamic", SIDE_TYPE_DYNAMIC),
a2e2357e
MD
269 )
270);
271
272static
273void test_dynamic_vla(void)
274{
948e3e72
MD
275 side_arg_dynamic_define_vec(myvla,
276 side_arg_list(
df075fa5
MD
277 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
278 )
279 );
a2e2357e
MD
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))));
283}
284
465e5e7e
MD
285static side_define_event(my_provider_event_dynamic_null,
286 "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG,
287 side_field_list(
91d140a6 288 side_field("dynamic", SIDE_TYPE_DYNAMIC),
465e5e7e
MD
289 )
290);
291
292static
293void test_dynamic_null(void)
294{
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())));
298}
299
c208889e
MD
300static side_define_event(my_provider_event_dynamic_struct,
301 "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG,
465e5e7e 302 side_field_list(
91d140a6 303 side_field("dynamic", SIDE_TYPE_DYNAMIC),
465e5e7e
MD
304 )
305);
306
307static
c208889e 308void test_dynamic_struct(void)
465e5e7e 309{
c208889e 310 side_arg_dynamic_define_struct(mystruct,
465e5e7e
MD
311 side_arg_list(
312 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
313 side_arg_dynamic_field("b", side_arg_dynamic_string("zzz")),
10c126ee 314 side_arg_dynamic_field("c", side_arg_dynamic_null()),
465e5e7e
MD
315 )
316 );
317
c208889e
MD
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))));
465e5e7e
MD
321}
322
c208889e
MD
323static side_define_event(my_provider_event_dynamic_nested_struct,
324 "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG,
3222d397 325 side_field_list(
91d140a6 326 side_field("dynamic", SIDE_TYPE_DYNAMIC),
3222d397
MD
327 )
328);
329
330static
c208889e 331void test_dynamic_nested_struct(void)
3222d397 332{
c208889e 333 side_arg_dynamic_define_struct(nested,
3222d397
MD
334 side_arg_list(
335 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
336 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
337 )
338 );
c208889e 339 side_arg_dynamic_define_struct(nested2,
3222d397
MD
340 side_arg_list(
341 side_arg_dynamic_field("aa", side_arg_dynamic_u64(128)),
342 side_arg_dynamic_field("bb", side_arg_dynamic_u16(1)),
343 )
344 );
c208889e 345 side_arg_dynamic_define_struct(mystruct,
3222d397 346 side_arg_list(
c208889e
MD
347 side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested)),
348 side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2)),
3222d397
MD
349 )
350 );
c208889e
MD
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))));
3222d397
MD
354}
355
c208889e
MD
356static side_define_event(my_provider_event_dynamic_vla_struct,
357 "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG,
7ce1b78f 358 side_field_list(
91d140a6 359 side_field("dynamic", SIDE_TYPE_DYNAMIC),
7ce1b78f
MD
360 )
361);
362
363static
c208889e 364void test_dynamic_vla_struct(void)
7ce1b78f 365{
c208889e 366 side_arg_dynamic_define_struct(nested,
7ce1b78f
MD
367 side_arg_list(
368 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
369 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
370 )
371 );
372 side_arg_dynamic_define_vec(myvla,
373 side_arg_list(
c208889e
MD
374 side_arg_dynamic_struct(&nested),
375 side_arg_dynamic_struct(&nested),
376 side_arg_dynamic_struct(&nested),
377 side_arg_dynamic_struct(&nested),
7ce1b78f
MD
378 )
379 );
c208889e
MD
380 my_provider_event_dynamic_vla_struct.enabled = 1;
381 side_event(&my_provider_event_dynamic_vla_struct,
7ce1b78f
MD
382 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla))));
383}
384
c208889e
MD
385static side_define_event(my_provider_event_dynamic_struct_vla,
386 "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG,
980bfdc4 387 side_field_list(
91d140a6 388 side_field("dynamic", SIDE_TYPE_DYNAMIC),
980bfdc4
MD
389 )
390);
391
392static
c208889e 393void test_dynamic_struct_vla(void)
980bfdc4
MD
394{
395 side_arg_dynamic_define_vec(myvla,
948e3e72 396 side_arg_list(
df075fa5
MD
397 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
398 )
399 );
980bfdc4 400 side_arg_dynamic_define_vec(myvla2,
948e3e72 401 side_arg_list(
df075fa5
MD
402 side_arg_dynamic_u32(4), side_arg_dynamic_u64(5), side_arg_dynamic_u32(6),
403 )
404 );
c208889e 405 side_arg_dynamic_define_struct(mystruct,
980bfdc4
MD
406 side_arg_list(
407 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla)),
408 side_arg_dynamic_field("b", side_arg_dynamic_vla(&myvla2)),
409 )
410 );
c208889e
MD
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))));
980bfdc4
MD
414}
415
948e3e72
MD
416static side_define_event(my_provider_event_dynamic_nested_vla,
417 "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG,
418 side_field_list(
91d140a6 419 side_field("dynamic", SIDE_TYPE_DYNAMIC),
948e3e72
MD
420 )
421);
422
423static
424void test_dynamic_nested_vla(void)
425{
426 side_arg_dynamic_define_vec(nestedvla,
427 side_arg_list(
428 side_arg_dynamic_u32(1), side_arg_dynamic_u16(2), side_arg_dynamic_u32(3),
429 )
430 );
431 side_arg_dynamic_define_vec(nestedvla2,
432 side_arg_list(
433 side_arg_dynamic_u8(4), side_arg_dynamic_u32(5), side_arg_dynamic_u32(6),
434 )
435 );
436 side_arg_dynamic_define_vec(myvla,
437 side_arg_list(
438 side_arg_dynamic_vla(&nestedvla),
439 side_arg_dynamic_vla(&nestedvla2),
440 )
441 );
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))));
445}
446
8a25ce77 447static side_define_event_variadic(my_provider_event_variadic,
19fa6aa2
MD
448 "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG,
449 side_field_list()
450);
451
452static
453void test_variadic(void)
454{
455 my_provider_event_variadic.enabled = 1;
456 side_event_variadic(&my_provider_event_variadic,
457 side_arg_list(),
458 side_arg_list(
459 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
460 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
461 )
462 );
463}
464
8a25ce77 465static side_define_event_variadic(my_provider_event_static_variadic,
41c4d119
MD
466 "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG,
467 side_field_list(
468 side_field("abc", SIDE_TYPE_U32),
469 side_field("def", SIDE_TYPE_U16),
470 )
471);
472
473static
474void test_static_variadic(void)
475{
476 my_provider_event_static_variadic.enabled = 1;
477 side_event_variadic(&my_provider_event_static_variadic,
478 side_arg_list(
479 side_arg_u32(1),
480 side_arg_u16(2),
481 ),
482 side_arg_list(
483 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
484 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
485 )
486 );
487}
488
4f40d951
MD
489static side_define_event(my_provider_event_bool, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG,
490 side_field_list(
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),
498 )
499);
500
501static
502void test_bool(void)
503{
504 uint32_t a = 0;
505 uint32_t b = 1;
506 uint64_t c = 0x12345678;
507 int16_t d = -32768;
508 bool e = true;
509 bool f = false;
510 uint32_t g = 256;
511
512 my_provider_event_bool.enabled = 1;
513 side_event(&my_provider_event_bool,
514 side_arg_list(
515 side_arg_bool(a),
516 side_arg_bool(b),
517 side_arg_bool(c),
518 side_arg_bool(d),
519 side_arg_bool(e),
520 side_arg_bool(f),
521 side_arg_bool(g),
522 )
523 );
524}
525
8a25ce77 526static side_define_event_variadic(my_provider_event_dynamic_bool,
4f40d951
MD
527 "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG,
528 side_field_list()
529);
530
531static
532void test_dynamic_bool(void)
533{
534 my_provider_event_dynamic_bool.enabled = 1;
535 side_event_variadic(&my_provider_event_dynamic_bool,
536 side_arg_list(),
537 side_arg_list(
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)),
542 )
543 );
544}
545
8ceca0cd
MD
546static side_define_event(my_provider_event_dynamic_vla_visitor,
547 "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG,
548 side_field_list(
549 side_field("dynamic", SIDE_TYPE_DYNAMIC),
550 )
551);
552
553struct app_dynamic_vla_visitor_ctx {
554 const uint32_t *ptr;
555 uint32_t length;
556};
557
558static
559enum side_visitor_status test_dynamic_vla_visitor(const struct side_tracer_dynamic_vla_visitor_ctx *tracer_ctx, void *_ctx)
560{
561 struct app_dynamic_vla_visitor_ctx *ctx = (struct app_dynamic_vla_visitor_ctx *) _ctx;
562 uint32_t length = ctx->length, i;
563
564 for (i = 0; i < length; i++) {
565 const struct side_arg_dynamic_vec elem = {
566 .dynamic_type = SIDE_DYNAMIC_TYPE_U32,
567 .u = {
568 .side_u32 = ctx->ptr[i],
569 },
570 };
571 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
572 return SIDE_VISITOR_STATUS_ERROR;
573 }
574 return SIDE_VISITOR_STATUS_OK;
575}
576
577static uint32_t testarray_dynamic_vla[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
578
579static
580void test_dynamic_vla_with_visitor(void)
581{
582 my_provider_event_dynamic_vla_visitor.enabled = 1;
583 side_event_cond(&my_provider_event_dynamic_vla_visitor) {
584 struct app_dynamic_vla_visitor_ctx ctx = {
585 .ptr = testarray_dynamic_vla,
586 .length = SIDE_ARRAY_SIZE(testarray_dynamic_vla),
587 };
588 side_event_call(&my_provider_event_dynamic_vla_visitor,
589 side_arg_list(
590 side_arg_dynamic(
591 side_arg_dynamic_vla_visitor(test_dynamic_vla_visitor, &ctx)
592 )
593 )
594 );
595 }
596}
597
2b359235
MD
598static side_define_event(my_provider_event_dynamic_struct_visitor,
599 "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG,
600 side_field_list(
601 side_field("dynamic", SIDE_TYPE_DYNAMIC),
602 )
603);
604
605struct struct_visitor_pair {
606 const char *name;
607 uint32_t value;
608};
609
610struct app_dynamic_struct_visitor_ctx {
611 const struct struct_visitor_pair *ptr;
612 uint32_t length;
613};
614
615static
616enum side_visitor_status test_dynamic_struct_visitor(const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, void *_ctx)
617{
618 struct app_dynamic_struct_visitor_ctx *ctx = (struct app_dynamic_struct_visitor_ctx *) _ctx;
619 uint32_t length = ctx->length, i;
620
621 for (i = 0; i < length; i++) {
622 struct side_arg_dynamic_event_field dynamic_field = {
623 .field_name = ctx->ptr[i].name,
624 .elem = {
625 .dynamic_type = SIDE_DYNAMIC_TYPE_U32,
626 .u = {
627 .side_u32 = ctx->ptr[i].value,
628 },
629 },
630 };
631 if (tracer_ctx->write_field(tracer_ctx, &dynamic_field) != SIDE_VISITOR_STATUS_OK)
632 return SIDE_VISITOR_STATUS_ERROR;
633 }
634 return SIDE_VISITOR_STATUS_OK;
635}
636
637static struct struct_visitor_pair testarray_dynamic_struct[] = {
638 { "a", 1, },
639 { "b", 2, },
640 { "c", 3, },
641 { "d", 4, },
642};
643
644static
645void test_dynamic_struct_with_visitor(void)
646{
647 my_provider_event_dynamic_struct_visitor.enabled = 1;
648 side_event_cond(&my_provider_event_dynamic_struct_visitor) {
649 struct app_dynamic_struct_visitor_ctx ctx = {
650 .ptr = testarray_dynamic_struct,
651 .length = SIDE_ARRAY_SIZE(testarray_dynamic_struct),
652 };
653 side_event_call(&my_provider_event_dynamic_struct_visitor,
654 side_arg_list(
655 side_arg_dynamic(
656 side_arg_dynamic_struct_visitor(test_dynamic_struct_visitor, &ctx)
657 )
658 )
659 );
660 }
661}
662
f611d0c3
MD
663int main()
664{
665 test_fields();
666 test_struct();
667 test_array();
668 test_vla();
669 test_vla_visitor();
cdd6e858 670 test_vla_visitor_2d();
ba845af5 671 test_array_fixint();
1533629f 672 test_vla_fixint();
a2e2357e
MD
673 test_dynamic_basic_type();
674 test_dynamic_vla();
465e5e7e 675 test_dynamic_null();
c208889e
MD
676 test_dynamic_struct();
677 test_dynamic_nested_struct();
678 test_dynamic_vla_struct();
679 test_dynamic_struct_vla();
948e3e72 680 test_dynamic_nested_vla();
19fa6aa2 681 test_variadic();
41c4d119 682 test_static_variadic();
4f40d951
MD
683 test_bool();
684 test_dynamic_bool();
8ceca0cd 685 test_dynamic_vla_with_visitor();
2b359235 686 test_dynamic_struct_with_visitor();
f611d0c3
MD
687 return 0;
688}
This page took 0.079215 seconds and 4 git commands to generate.