Add static type attributes
[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,
65010f43 18 side_attr_list(),
f611d0c3 19 side_field_list(
f37a556f
MD
20 side_field("abc", SIDE_TYPE_U32, side_attr_list()),
21 side_field("def", SIDE_TYPE_S64, side_attr_list()),
22 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
f611d0c3
MD
23 )
24);
25
26static
27void test_fields(void)
28{
29 uint32_t uw = 42;
30 int64_t sdw = -500;
31
32 my_provider_event.enabled = 1;
a2e2357e
MD
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"))));
f611d0c3
MD
35}
36
37static side_define_event(my_provider_event2, "myprovider", "myevent2", SIDE_LOGLEVEL_DEBUG,
65010f43 38 side_attr_list(),
f611d0c3
MD
39 side_field_list(
40 side_field_struct("structfield",
41 side_field_list(
f37a556f
MD
42 side_field("x", SIDE_TYPE_U32, side_attr_list()),
43 side_field("y", SIDE_TYPE_S64, side_attr_list()),
44 ),
45 side_attr_list()
f611d0c3 46 ),
f37a556f 47 side_field("z", SIDE_TYPE_U8, side_attr_list()),
f611d0c3
MD
48 )
49);
50
51static
52void 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
61static side_define_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG,
65010f43 62 side_attr_list(),
f611d0c3 63 side_field_list(
f37a556f
MD
64 side_field_array("arr", side_elem_type(SIDE_TYPE_U32, side_attr_list()), 3, side_attr_list()),
65 side_field("v", SIDE_TYPE_S64, side_attr_list()),
f611d0c3
MD
66 )
67);
68
69static
70void 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
79static side_define_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG,
65010f43 80 side_attr_list(),
f611d0c3 81 side_field_list(
f37a556f
MD
82 side_field_vla("vla", side_elem_type(SIDE_TYPE_U32, side_attr_list()), side_attr_list()),
83 side_field("v", SIDE_TYPE_S64, side_attr_list()),
f611d0c3
MD
84 )
85);
86
87static
88void 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
cdd6e858
MD
97/* 1D array visitor */
98
f611d0c3
MD
99struct app_visitor_ctx {
100 const uint32_t *ptr;
352a4b77 101 uint32_t length;
f611d0c3
MD
102};
103
352a4b77
MD
104static
105enum side_visitor_status test_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
f611d0c3
MD
106{
107 struct app_visitor_ctx *ctx = (struct app_visitor_ctx *) _ctx;
352a4b77
MD
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 };
db6ecef9
MD
117 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
118 return SIDE_VISITOR_STATUS_ERROR;
352a4b77 119 }
f611d0c3
MD
120 return SIDE_VISITOR_STATUS_OK;
121}
122
123static uint32_t testarray[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
124
125static side_define_event(my_provider_event_vla_visitor, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG,
65010f43 126 side_attr_list(),
f611d0c3 127 side_field_list(
f37a556f
MD
128 side_field_vla_visitor("vlavisit", side_elem_type(SIDE_TYPE_U32, side_attr_list()), test_visitor, side_attr_list()),
129 side_field("v", SIDE_TYPE_S64, side_attr_list()),
f611d0c3
MD
130 )
131);
132
133static
134void 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,
352a4b77 140 .length = SIDE_ARRAY_SIZE(testarray),
f611d0c3
MD
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
cdd6e858
MD
146/* 2D array visitor */
147
148struct app_visitor_2d_inner_ctx {
149 const uint32_t *ptr;
150 uint32_t length;
151};
152
153static
154enum 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 };
db6ecef9
MD
166 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
167 return SIDE_VISITOR_STATUS_ERROR;
cdd6e858
MD
168 }
169 return SIDE_VISITOR_STATUS_OK;
170}
171
172struct app_visitor_2d_outer_ctx {
173 const uint32_t (*ptr)[2];
174 uint32_t length;
175};
176
177static
178enum 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);
db6ecef9
MD
189 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
190 return SIDE_VISITOR_STATUS_ERROR;
cdd6e858
MD
191 }
192 return SIDE_VISITOR_STATUS_OK;
193}
194
195static uint32_t testarray2d[][2] = {
196 { 1, 2 },
197 { 33, 44 },
198 { 55, 66 },
199};
200
201static side_define_event(my_provider_event_vla_visitor2d, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG,
65010f43 202 side_attr_list(),
cdd6e858
MD
203 side_field_list(
204 side_field_vla_visitor("vlavisit2d",
f37a556f
MD
205 side_elem(
206 side_type_vla_visitor_decl(
207 side_elem_type(SIDE_TYPE_U32, side_attr_list()),
208 test_inner_visitor,
209 side_attr_list())
210 ), test_outer_visitor, side_attr_list()),
211 side_field("v", SIDE_TYPE_S64, side_attr_list()),
cdd6e858
MD
212 )
213);
214
215static
216void 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
ba845af5
MD
228static int64_t array_fixint[] = { -444, 555, 123, 2897432587 };
229
230static side_define_event(my_provider_event_array_fixint, "myprovider", "myarrayfixint", SIDE_LOGLEVEL_DEBUG,
65010f43 231 side_attr_list(),
ba845af5 232 side_field_list(
f37a556f
MD
233 side_field_array("arrfixint", side_elem_type(SIDE_TYPE_S64, side_attr_list()), SIDE_ARRAY_SIZE(array_fixint), side_attr_list()),
234 side_field("v", SIDE_TYPE_S64, side_attr_list()),
ba845af5
MD
235 )
236);
237
238static
239void test_array_fixint(void)
240{
241 my_provider_event_array_fixint.enabled = 1;
1533629f
MD
242 side_event(&my_provider_event_array_fixint,
243 side_arg_list(side_arg_array_s64(array_fixint), side_arg_s64(42)));
244}
245
246static int64_t vla_fixint[] = { -444, 555, 123, 2897432587 };
247
248static side_define_event(my_provider_event_vla_fixint, "myprovider", "myvlafixint", SIDE_LOGLEVEL_DEBUG,
65010f43 249 side_attr_list(),
1533629f 250 side_field_list(
f37a556f
MD
251 side_field_vla("vlafixint", side_elem_type(SIDE_TYPE_S64, side_attr_list()), side_attr_list()),
252 side_field("v", SIDE_TYPE_S64, side_attr_list()),
1533629f
MD
253 )
254);
255
256static
257void 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)));
ba845af5
MD
262}
263
a2e2357e
MD
264static side_define_event(my_provider_event_dynamic_basic,
265 "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG,
65010f43 266 side_attr_list(),
a2e2357e 267 side_field_list(
f37a556f 268 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
a2e2357e
MD
269 )
270);
271
272static
273void 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
280static side_define_event(my_provider_event_dynamic_vla,
281 "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG,
65010f43 282 side_attr_list(),
a2e2357e 283 side_field_list(
f37a556f 284 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
a2e2357e
MD
285 )
286);
287
288static
289void test_dynamic_vla(void)
290{
948e3e72
MD
291 side_arg_dynamic_define_vec(myvla,
292 side_arg_list(
df075fa5
MD
293 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
294 )
295 );
a2e2357e
MD
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
465e5e7e
MD
301static side_define_event(my_provider_event_dynamic_null,
302 "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG,
65010f43 303 side_attr_list(),
465e5e7e 304 side_field_list(
f37a556f 305 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
465e5e7e
MD
306 )
307);
308
309static
310void 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
c208889e
MD
317static side_define_event(my_provider_event_dynamic_struct,
318 "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG,
65010f43 319 side_attr_list(),
465e5e7e 320 side_field_list(
f37a556f 321 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
465e5e7e
MD
322 )
323);
324
325static
c208889e 326void test_dynamic_struct(void)
465e5e7e 327{
c208889e 328 side_arg_dynamic_define_struct(mystruct,
465e5e7e
MD
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")),
10c126ee 332 side_arg_dynamic_field("c", side_arg_dynamic_null()),
465e5e7e
MD
333 )
334 );
335
c208889e
MD
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))));
465e5e7e
MD
339}
340
c208889e
MD
341static side_define_event(my_provider_event_dynamic_nested_struct,
342 "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG,
65010f43 343 side_attr_list(),
3222d397 344 side_field_list(
f37a556f 345 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
3222d397
MD
346 )
347);
348
349static
c208889e 350void test_dynamic_nested_struct(void)
3222d397 351{
c208889e 352 side_arg_dynamic_define_struct(nested,
3222d397
MD
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 );
c208889e 358 side_arg_dynamic_define_struct(nested2,
3222d397
MD
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 );
c208889e 364 side_arg_dynamic_define_struct(mystruct,
3222d397 365 side_arg_list(
c208889e
MD
366 side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested)),
367 side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2)),
3222d397
MD
368 )
369 );
c208889e
MD
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))));
3222d397
MD
373}
374
c208889e
MD
375static side_define_event(my_provider_event_dynamic_vla_struct,
376 "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG,
65010f43 377 side_attr_list(),
7ce1b78f 378 side_field_list(
f37a556f 379 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
7ce1b78f
MD
380 )
381);
382
383static
c208889e 384void test_dynamic_vla_struct(void)
7ce1b78f 385{
c208889e 386 side_arg_dynamic_define_struct(nested,
7ce1b78f
MD
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(
c208889e
MD
394 side_arg_dynamic_struct(&nested),
395 side_arg_dynamic_struct(&nested),
396 side_arg_dynamic_struct(&nested),
397 side_arg_dynamic_struct(&nested),
7ce1b78f
MD
398 )
399 );
c208889e
MD
400 my_provider_event_dynamic_vla_struct.enabled = 1;
401 side_event(&my_provider_event_dynamic_vla_struct,
7ce1b78f
MD
402 side_arg_list(side_arg_dynamic(side_arg_dynamic_vla(&myvla))));
403}
404
c208889e
MD
405static side_define_event(my_provider_event_dynamic_struct_vla,
406 "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG,
65010f43 407 side_attr_list(),
980bfdc4 408 side_field_list(
f37a556f 409 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
980bfdc4
MD
410 )
411);
412
413static
c208889e 414void test_dynamic_struct_vla(void)
980bfdc4
MD
415{
416 side_arg_dynamic_define_vec(myvla,
948e3e72 417 side_arg_list(
df075fa5
MD
418 side_arg_dynamic_u32(1), side_arg_dynamic_u32(2), side_arg_dynamic_u32(3),
419 )
420 );
980bfdc4 421 side_arg_dynamic_define_vec(myvla2,
948e3e72 422 side_arg_list(
df075fa5
MD
423 side_arg_dynamic_u32(4), side_arg_dynamic_u64(5), side_arg_dynamic_u32(6),
424 )
425 );
c208889e 426 side_arg_dynamic_define_struct(mystruct,
980bfdc4
MD
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 );
c208889e
MD
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))));
980bfdc4
MD
435}
436
948e3e72
MD
437static side_define_event(my_provider_event_dynamic_nested_vla,
438 "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG,
65010f43 439 side_attr_list(),
948e3e72 440 side_field_list(
f37a556f 441 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
948e3e72
MD
442 )
443);
444
445static
446void 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
8a25ce77 469static side_define_event_variadic(my_provider_event_variadic,
19fa6aa2 470 "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG,
65010f43 471 side_attr_list(),
19fa6aa2
MD
472 side_field_list()
473);
474
475static
476void 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
8a25ce77 488static side_define_event_variadic(my_provider_event_static_variadic,
41c4d119 489 "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG,
65010f43 490 side_attr_list(),
41c4d119 491 side_field_list(
f37a556f
MD
492 side_field("abc", SIDE_TYPE_U32, side_attr_list()),
493 side_field("def", SIDE_TYPE_U16, side_attr_list()),
41c4d119
MD
494 )
495);
496
497static
498void 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
4f40d951 513static side_define_event(my_provider_event_bool, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG,
65010f43 514 side_attr_list(),
4f40d951 515 side_field_list(
f37a556f
MD
516 side_field("a_false", SIDE_TYPE_BOOL, side_attr_list()),
517 side_field("b_true", SIDE_TYPE_BOOL, side_attr_list()),
518 side_field("c_true", SIDE_TYPE_BOOL, side_attr_list()),
519 side_field("d_true", SIDE_TYPE_BOOL, side_attr_list()),
520 side_field("e_true", SIDE_TYPE_BOOL, side_attr_list()),
521 side_field("f_false", SIDE_TYPE_BOOL, side_attr_list()),
522 side_field("g_true", SIDE_TYPE_BOOL, side_attr_list()),
4f40d951
MD
523 )
524);
525
526static
527void 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
8a25ce77 551static side_define_event_variadic(my_provider_event_dynamic_bool,
4f40d951 552 "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG,
65010f43 553 side_attr_list(),
4f40d951
MD
554 side_field_list()
555);
556
557static
558void 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
8ceca0cd
MD
572static side_define_event(my_provider_event_dynamic_vla_visitor,
573 "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG,
65010f43 574 side_attr_list(),
8ceca0cd 575 side_field_list(
f37a556f 576 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
8ceca0cd
MD
577 )
578);
579
580struct app_dynamic_vla_visitor_ctx {
581 const uint32_t *ptr;
582 uint32_t length;
583};
584
585static
586enum 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
604static uint32_t testarray_dynamic_vla[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
605
606static
607void 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
2b359235
MD
625static side_define_event(my_provider_event_dynamic_struct_visitor,
626 "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG,
65010f43 627 side_attr_list(),
2b359235 628 side_field_list(
f37a556f 629 side_field("dynamic", SIDE_TYPE_DYNAMIC, side_attr_list()),
2b359235
MD
630 )
631);
632
633struct struct_visitor_pair {
634 const char *name;
635 uint32_t value;
636};
637
638struct app_dynamic_struct_visitor_ctx {
639 const struct struct_visitor_pair *ptr;
640 uint32_t length;
641};
642
643static
644enum 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
665static struct struct_visitor_pair testarray_dynamic_struct[] = {
666 { "a", 1, },
667 { "b", 2, },
668 { "c", 3, },
669 { "d", 4, },
670};
671
672static
673void 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
65010f43
MD
691static side_define_event(my_provider_event_user_attribute, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG,
692 side_attr_list(
693 side_attr("user_attribute_a", "val1"),
694 side_attr("user_attribute_b", "val2"),
695 ),
696 side_field_list(
f37a556f
MD
697 side_field("abc", SIDE_TYPE_U32, side_attr_list()),
698 side_field("def", SIDE_TYPE_S64, side_attr_list()),
65010f43
MD
699 )
700);
701
702static
703void 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
f611d0c3
MD
709int main()
710{
711 test_fields();
712 test_struct();
713 test_array();
714 test_vla();
715 test_vla_visitor();
cdd6e858 716 test_vla_visitor_2d();
ba845af5 717 test_array_fixint();
1533629f 718 test_vla_fixint();
a2e2357e
MD
719 test_dynamic_basic_type();
720 test_dynamic_vla();
465e5e7e 721 test_dynamic_null();
c208889e
MD
722 test_dynamic_struct();
723 test_dynamic_nested_struct();
724 test_dynamic_vla_struct();
725 test_dynamic_struct_vla();
948e3e72 726 test_dynamic_nested_vla();
19fa6aa2 727 test_variadic();
41c4d119 728 test_static_variadic();
4f40d951
MD
729 test_bool();
730 test_dynamic_bool();
8ceca0cd 731 test_dynamic_vla_with_visitor();
2b359235 732 test_dynamic_struct_with_visitor();
65010f43 733 test_event_user_attribute();
f611d0c3
MD
734 return 0;
735}
This page took 0.055444 seconds and 4 git commands to generate.