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