Add indirection for visitor arguments
[libside.git] / tests / unit / 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>
7a1cb105 11#include <stddef.h>
f611d0c3 12
67337c4a 13#include <side/trace.h>
f611d0c3
MD
14
15/* User code example */
16
67337c4a
MD
17side_static_event(my_provider_event, "myprovider", "myevent", SIDE_LOGLEVEL_DEBUG,
18 side_field_list(
a82ffcff
MD
19 side_field_u32("abc"),
20 side_field_s64("def"),
21 side_field_pointer("ptr"),
67337c4a
MD
22 side_field_dynamic("dynamic"),
23 side_field_dynamic("dynamic_pointer"),
a82ffcff
MD
24 side_field_null("null"),
25 )
f611d0c3
MD
26);
27
28static
29void test_fields(void)
30{
31 uint32_t uw = 42;
32 int64_t sdw = -500;
33
67337c4a
MD
34 side_event(my_provider_event,
35 side_arg_list(
36 side_arg_u32(uw),
37 side_arg_s64(sdw),
38 side_arg_pointer((void *) 0x1),
a82ffcff
MD
39 side_arg_dynamic_string("zzz"),
40 side_arg_dynamic_pointer((void *) 0x1),
67337c4a 41 side_arg_null(),
f5e650d7
MD
42 )
43 );
f611d0c3
MD
44}
45
67337c4a
MD
46side_hidden_event(my_provider_event_hidden, "myprovider", "myeventhidden", SIDE_LOGLEVEL_DEBUG,
47 side_field_list(
a82ffcff
MD
48 side_field_u32("abc"),
49 )
89747802
MD
50);
51
52static
53void test_event_hidden(void)
54{
67337c4a 55 side_event(my_provider_event_hidden, side_arg_list(side_arg_u32(2)));
89747802
MD
56}
57
67337c4a 58side_declare_event(my_provider_event_export);
89747802 59
67337c4a
MD
60side_export_event(my_provider_event_export, "myprovider", "myeventexport", SIDE_LOGLEVEL_DEBUG,
61 side_field_list(
a82ffcff
MD
62 side_field_u32("abc"),
63 )
89747802
MD
64);
65
66static
67void test_event_export(void)
68{
67337c4a 69 side_event(my_provider_event_export, side_arg_list(side_arg_u32(2)));
89747802
MD
70}
71
67337c4a
MD
72side_static_event(my_provider_event_struct_literal, "myprovider", "myeventstructliteral", SIDE_LOGLEVEL_DEBUG,
73 side_field_list(
74 side_field_struct("structliteral",
75 side_struct_literal(
76 side_field_list(
a82ffcff
MD
77 side_field_u32("x"),
78 side_field_s64("y"),
79 )
c7a14585 80 )
f611d0c3 81 ),
a82ffcff
MD
82 side_field_u8("z"),
83 )
f611d0c3
MD
84);
85
c7a14585
MD
86static
87void test_struct_literal(void)
88{
67337c4a
MD
89 side_event_cond(my_provider_event_struct_literal) {
90 side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
91 side_event_call(my_provider_event_struct_literal, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55)));
c7a14585
MD
92 }
93}
94
67337c4a
MD
95static side_define_struct(mystructdef,
96 side_field_list(
a82ffcff
MD
97 side_field_u32("x"),
98 side_field_s64("y"),
99 )
c7a14585
MD
100);
101
67337c4a
MD
102side_static_event(my_provider_event_struct, "myprovider", "myeventstruct", SIDE_LOGLEVEL_DEBUG,
103 side_field_list(
104 side_field_struct("struct", &mystructdef),
a82ffcff
MD
105 side_field_u8("z"),
106 )
c7a14585
MD
107);
108
f611d0c3
MD
109static
110void test_struct(void)
111{
67337c4a
MD
112 side_event_cond(my_provider_event_struct) {
113 side_arg_define_vec(mystruct, side_arg_list(side_arg_u32(21), side_arg_s64(22)));
114 side_event_call(my_provider_event_struct, side_arg_list(side_arg_struct(&mystruct), side_arg_u8(55)));
f611d0c3
MD
115 }
116}
117
67337c4a
MD
118side_static_event(my_provider_event_array, "myprovider", "myarray", SIDE_LOGLEVEL_DEBUG,
119 side_field_list(
a82ffcff
MD
120 side_field_array("arr", side_elem(side_type_u32()), 3),
121 side_field_s64("v"),
122 )
f611d0c3
MD
123);
124
125static
126void test_array(void)
127{
67337c4a
MD
128 side_event_cond(my_provider_event_array) {
129 side_arg_define_vec(myarray, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
130 side_event_call(my_provider_event_array, side_arg_list(side_arg_array(&myarray), side_arg_s64(42)));
f611d0c3
MD
131 }
132}
133
67337c4a
MD
134side_static_event(my_provider_event_vla, "myprovider", "myvla", SIDE_LOGLEVEL_DEBUG,
135 side_field_list(
a82ffcff
MD
136 side_field_vla("vla", side_elem(side_type_u32())),
137 side_field_s64("v"),
138 )
f611d0c3
MD
139);
140
141static
142void test_vla(void)
143{
67337c4a
MD
144 side_event_cond(my_provider_event_vla) {
145 side_arg_define_vec(myvla, side_arg_list(side_arg_u32(1), side_arg_u32(2), side_arg_u32(3)));
146 side_event_call(my_provider_event_vla, side_arg_list(side_arg_vla(&myvla), side_arg_s64(42)));
f611d0c3
MD
147 }
148}
149
cdd6e858
MD
150/* 1D array visitor */
151
f611d0c3
MD
152struct app_visitor_ctx {
153 const uint32_t *ptr;
352a4b77 154 uint32_t length;
f611d0c3
MD
155};
156
352a4b77 157static
67337c4a 158enum side_visitor_status test_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
f611d0c3
MD
159{
160 struct app_visitor_ctx *ctx = (struct app_visitor_ctx *) _ctx;
352a4b77
MD
161 uint32_t length = ctx->length, i;
162
163 for (i = 0; i < length; i++) {
67337c4a 164 const struct side_arg elem = side_arg_u32(ctx->ptr[i]);
ffb5c809 165
67337c4a
MD
166 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
167 return SIDE_VISITOR_STATUS_ERROR;
352a4b77 168 }
67337c4a 169 return SIDE_VISITOR_STATUS_OK;
f611d0c3
MD
170}
171
172static uint32_t testarray[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
173
67337c4a
MD
174side_static_event(my_provider_event_vla_visitor, "myprovider", "myvlavisit", SIDE_LOGLEVEL_DEBUG,
175 side_field_list(
a82ffcff
MD
176 side_field_vla_visitor("vlavisit", side_elem(side_type_u32()), test_visitor),
177 side_field_s64("v"),
178 )
f611d0c3
MD
179);
180
181static
182void test_vla_visitor(void)
183{
67337c4a 184 side_event_cond(my_provider_event_vla_visitor) {
f611d0c3
MD
185 struct app_visitor_ctx ctx = {
186 .ptr = testarray,
67337c4a 187 .length = SIDE_ARRAY_SIZE(testarray),
f611d0c3 188 };
c6af61dc
MD
189 side_arg_define_vla_visitor(side_visitor, &ctx);
190 side_event_call(my_provider_event_vla_visitor,
191 side_arg_list(side_arg_vla_visitor(&side_visitor), side_arg_s64(42)));
f611d0c3
MD
192 }
193}
194
cdd6e858
MD
195/* 2D array visitor */
196
197struct app_visitor_2d_inner_ctx {
198 const uint32_t *ptr;
199 uint32_t length;
200};
201
202static
67337c4a 203enum side_visitor_status test_inner_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
cdd6e858
MD
204{
205 struct app_visitor_2d_inner_ctx *ctx = (struct app_visitor_2d_inner_ctx *) _ctx;
206 uint32_t length = ctx->length, i;
207
208 for (i = 0; i < length; i++) {
67337c4a 209 const struct side_arg elem = side_arg_u32(ctx->ptr[i]);
ffb5c809 210
67337c4a
MD
211 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
212 return SIDE_VISITOR_STATUS_ERROR;
cdd6e858 213 }
67337c4a 214 return SIDE_VISITOR_STATUS_OK;
cdd6e858
MD
215}
216
217struct app_visitor_2d_outer_ctx {
218 const uint32_t (*ptr)[2];
219 uint32_t length;
220};
221
222static
67337c4a 223enum side_visitor_status test_outer_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
cdd6e858
MD
224{
225 struct app_visitor_2d_outer_ctx *ctx = (struct app_visitor_2d_outer_ctx *) _ctx;
226 uint32_t length = ctx->length, i;
227
228 for (i = 0; i < length; i++) {
229 struct app_visitor_2d_inner_ctx inner_ctx = {
230 .ptr = ctx->ptr[i],
231 .length = 2,
232 };
c6af61dc
MD
233 side_arg_define_vla_visitor(side_inner_visitor, &inner_ctx);
234 const struct side_arg elem = side_arg_vla_visitor(&side_inner_visitor);
67337c4a
MD
235 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
236 return SIDE_VISITOR_STATUS_ERROR;
cdd6e858 237 }
67337c4a 238 return SIDE_VISITOR_STATUS_OK;
cdd6e858
MD
239}
240
241static uint32_t testarray2d[][2] = {
242 { 1, 2 },
243 { 33, 44 },
244 { 55, 66 },
245};
246
67337c4a
MD
247side_static_event(my_provider_event_vla_visitor2d, "myprovider", "myvlavisit2d", SIDE_LOGLEVEL_DEBUG,
248 side_field_list(
249 side_field_vla_visitor("vlavisit2d",
250 side_elem(
251 side_type_vla_visitor(
a82ffcff
MD
252 side_elem(side_type_u32()),
253 test_inner_visitor
254 )
255 ), test_outer_visitor),
256 side_field_s64("v"),
257 )
cdd6e858
MD
258);
259
260static
261void test_vla_visitor_2d(void)
262{
67337c4a 263 side_event_cond(my_provider_event_vla_visitor2d) {
cdd6e858
MD
264 struct app_visitor_2d_outer_ctx ctx = {
265 .ptr = testarray2d,
67337c4a 266 .length = SIDE_ARRAY_SIZE(testarray2d),
cdd6e858 267 };
c6af61dc
MD
268 side_arg_define_vla_visitor(side_outer_visitor, &ctx);
269 side_event_call(my_provider_event_vla_visitor2d,
270 side_arg_list(side_arg_vla_visitor(&side_outer_visitor), side_arg_s64(42)));
cdd6e858
MD
271 }
272}
273
67337c4a
MD
274side_static_event(my_provider_event_dynamic_basic,
275 "myprovider", "mydynamicbasic", SIDE_LOGLEVEL_DEBUG,
276 side_field_list(
277 side_field_dynamic("dynamic"),
a82ffcff 278 )
a2e2357e
MD
279);
280
281static
282void test_dynamic_basic_type(void)
283{
67337c4a 284 side_event(my_provider_event_dynamic_basic,
a82ffcff 285 side_arg_list(side_arg_dynamic_s16(-33)));
a2e2357e
MD
286}
287
67337c4a
MD
288side_static_event(my_provider_event_dynamic_vla,
289 "myprovider", "mydynamicvla", SIDE_LOGLEVEL_DEBUG,
290 side_field_list(
291 side_field_dynamic("dynamic"),
a82ffcff 292 )
a2e2357e
MD
293);
294
295static
296void test_dynamic_vla(void)
297{
67337c4a
MD
298 side_arg_dynamic_define_vec(myvla,
299 side_arg_list(
a82ffcff
MD
300 side_arg_dynamic_u32(1),
301 side_arg_dynamic_u32(2),
302 side_arg_dynamic_u32(3),
303 )
df075fa5 304 );
67337c4a
MD
305 side_event(my_provider_event_dynamic_vla,
306 side_arg_list(side_arg_dynamic_vla(&myvla)));
a2e2357e
MD
307}
308
67337c4a
MD
309side_static_event(my_provider_event_dynamic_null,
310 "myprovider", "mydynamicnull", SIDE_LOGLEVEL_DEBUG,
311 side_field_list(
312 side_field_dynamic("dynamic"),
a82ffcff 313 )
465e5e7e
MD
314);
315
316static
317void test_dynamic_null(void)
318{
67337c4a 319 side_event(my_provider_event_dynamic_null,
a82ffcff 320 side_arg_list(side_arg_dynamic_null()));
465e5e7e
MD
321}
322
67337c4a
MD
323side_static_event(my_provider_event_dynamic_struct,
324 "myprovider", "mydynamicstruct", SIDE_LOGLEVEL_DEBUG,
325 side_field_list(
326 side_field_dynamic("dynamic"),
a82ffcff 327 )
465e5e7e
MD
328);
329
330static
c208889e 331void test_dynamic_struct(void)
465e5e7e 332{
67337c4a
MD
333 side_arg_dynamic_define_struct(mystruct,
334 side_arg_list(
a82ffcff
MD
335 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
336 side_arg_dynamic_field("b", side_arg_dynamic_string("zzz")),
337 side_arg_dynamic_field("c", side_arg_dynamic_null()),
338 )
465e5e7e
MD
339 );
340
67337c4a
MD
341 side_event(my_provider_event_dynamic_struct,
342 side_arg_list(side_arg_dynamic_struct(&mystruct)));
465e5e7e
MD
343}
344
67337c4a
MD
345side_static_event(my_provider_event_dynamic_nested_struct,
346 "myprovider", "mydynamicnestedstruct", SIDE_LOGLEVEL_DEBUG,
347 side_field_list(
348 side_field_dynamic("dynamic"),
a82ffcff 349 )
3222d397
MD
350);
351
352static
c208889e 353void test_dynamic_nested_struct(void)
3222d397 354{
67337c4a
MD
355 side_arg_dynamic_define_struct(nested,
356 side_arg_list(
a82ffcff
MD
357 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
358 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
359 )
3222d397 360 );
67337c4a
MD
361 side_arg_dynamic_define_struct(nested2,
362 side_arg_list(
a82ffcff
MD
363 side_arg_dynamic_field("aa", side_arg_dynamic_u64(128)),
364 side_arg_dynamic_field("bb", side_arg_dynamic_u16(1)),
365 )
3222d397 366 );
67337c4a
MD
367 side_arg_dynamic_define_struct(mystruct,
368 side_arg_list(
369 side_arg_dynamic_field("nested", side_arg_dynamic_struct(&nested)),
370 side_arg_dynamic_field("nested2", side_arg_dynamic_struct(&nested2)),
a82ffcff 371 )
3222d397 372 );
67337c4a
MD
373 side_event(my_provider_event_dynamic_nested_struct,
374 side_arg_list(side_arg_dynamic_struct(&mystruct)));
3222d397
MD
375}
376
67337c4a
MD
377side_static_event(my_provider_event_dynamic_vla_struct,
378 "myprovider", "mydynamicvlastruct", SIDE_LOGLEVEL_DEBUG,
379 side_field_list(
380 side_field_dynamic("dynamic"),
a82ffcff 381 )
7ce1b78f
MD
382);
383
384static
c208889e 385void test_dynamic_vla_struct(void)
7ce1b78f 386{
67337c4a
MD
387 side_arg_dynamic_define_struct(nested,
388 side_arg_list(
a82ffcff
MD
389 side_arg_dynamic_field("a", side_arg_dynamic_u32(43)),
390 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
391 )
7ce1b78f 392 );
67337c4a
MD
393 side_arg_dynamic_define_vec(myvla,
394 side_arg_list(
395 side_arg_dynamic_struct(&nested),
396 side_arg_dynamic_struct(&nested),
397 side_arg_dynamic_struct(&nested),
398 side_arg_dynamic_struct(&nested),
a82ffcff 399 )
7ce1b78f 400 );
67337c4a
MD
401 side_event(my_provider_event_dynamic_vla_struct,
402 side_arg_list(side_arg_dynamic_vla(&myvla)));
7ce1b78f
MD
403}
404
67337c4a
MD
405side_static_event(my_provider_event_dynamic_struct_vla,
406 "myprovider", "mydynamicstructvla", SIDE_LOGLEVEL_DEBUG,
407 side_field_list(
408 side_field_dynamic("dynamic"),
a82ffcff 409 )
980bfdc4
MD
410);
411
412static
c208889e 413void test_dynamic_struct_vla(void)
980bfdc4 414{
67337c4a
MD
415 side_arg_dynamic_define_vec(myvla,
416 side_arg_list(
a82ffcff
MD
417 side_arg_dynamic_u32(1),
418 side_arg_dynamic_u32(2),
419 side_arg_dynamic_u32(3),
420 )
df075fa5 421 );
67337c4a
MD
422 side_arg_dynamic_define_vec(myvla2,
423 side_arg_list(
a82ffcff
MD
424 side_arg_dynamic_u32(4),
425 side_arg_dynamic_u64(5),
426 side_arg_dynamic_u32(6),
427 )
df075fa5 428 );
67337c4a
MD
429 side_arg_dynamic_define_struct(mystruct,
430 side_arg_list(
431 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla)),
432 side_arg_dynamic_field("b", side_arg_dynamic_vla(&myvla2)),
a82ffcff 433 )
980bfdc4 434 );
67337c4a
MD
435 side_event(my_provider_event_dynamic_struct_vla,
436 side_arg_list(side_arg_dynamic_struct(&mystruct)));
980bfdc4
MD
437}
438
67337c4a
MD
439side_static_event(my_provider_event_dynamic_nested_vla,
440 "myprovider", "mydynamicnestedvla", SIDE_LOGLEVEL_DEBUG,
441 side_field_list(
442 side_field_dynamic("dynamic"),
a82ffcff 443 )
948e3e72
MD
444);
445
446static
447void test_dynamic_nested_vla(void)
448{
67337c4a
MD
449 side_arg_dynamic_define_vec(nestedvla,
450 side_arg_list(
a82ffcff
MD
451 side_arg_dynamic_u32(1),
452 side_arg_dynamic_u16(2),
453 side_arg_dynamic_u32(3),
454 )
948e3e72 455 );
67337c4a
MD
456 side_arg_dynamic_define_vec(nestedvla2,
457 side_arg_list(
a82ffcff
MD
458 side_arg_dynamic_u8(4),
459 side_arg_dynamic_u32(5),
460 side_arg_dynamic_u32(6),
461 )
948e3e72 462 );
67337c4a
MD
463 side_arg_dynamic_define_vec(myvla,
464 side_arg_list(
465 side_arg_dynamic_vla(&nestedvla),
466 side_arg_dynamic_vla(&nestedvla2),
a82ffcff 467 )
948e3e72 468 );
67337c4a
MD
469 side_event(my_provider_event_dynamic_nested_vla,
470 side_arg_list(side_arg_dynamic_vla(&myvla)));
948e3e72
MD
471}
472
67337c4a
MD
473side_static_event_variadic(my_provider_event_variadic,
474 "myprovider", "myvariadicevent", SIDE_LOGLEVEL_DEBUG,
a82ffcff 475 side_field_list()
19fa6aa2
MD
476);
477
478static
479void test_variadic(void)
480{
67337c4a
MD
481 side_event_variadic(my_provider_event_variadic,
482 side_arg_list(),
483 side_arg_list(
a82ffcff
MD
484 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
485 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
486 )
19fa6aa2
MD
487 );
488}
489
67337c4a
MD
490side_static_event_variadic(my_provider_event_static_variadic,
491 "myprovider", "mystaticvariadicevent", SIDE_LOGLEVEL_DEBUG,
492 side_field_list(
a82ffcff
MD
493 side_field_u32("abc"),
494 side_field_u16("def"),
495 )
41c4d119
MD
496);
497
498static
499void test_static_variadic(void)
500{
67337c4a
MD
501 side_event_variadic(my_provider_event_static_variadic,
502 side_arg_list(
503 side_arg_u32(1),
504 side_arg_u16(2),
41c4d119 505 ),
67337c4a 506 side_arg_list(
a82ffcff
MD
507 side_arg_dynamic_field("a", side_arg_dynamic_u32(55)),
508 side_arg_dynamic_field("b", side_arg_dynamic_s8(-4)),
509 )
41c4d119
MD
510 );
511}
512
67337c4a
MD
513side_static_event(my_provider_event_bool, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG,
514 side_field_list(
a82ffcff
MD
515 side_field_bool("a_false"),
516 side_field_bool("b_true"),
517 side_field_bool("c_true"),
518 side_field_bool("d_true"),
519 side_field_bool("e_true"),
520 side_field_bool("f_false"),
521 side_field_bool("g_true"),
522 )
4f40d951
MD
523);
524
525static
526void test_bool(void)
527{
528 uint32_t a = 0;
529 uint32_t b = 1;
530 uint64_t c = 0x12345678;
531 int16_t d = -32768;
532 bool e = true;
533 bool f = false;
534 uint32_t g = 256;
535
67337c4a
MD
536 side_event(my_provider_event_bool,
537 side_arg_list(
538 side_arg_bool(a),
539 side_arg_bool(b),
540 side_arg_bool(c),
541 side_arg_bool(d),
542 side_arg_bool(e),
543 side_arg_bool(f),
544 side_arg_bool(g),
4f40d951
MD
545 )
546 );
547}
548
67337c4a
MD
549side_static_event_variadic(my_provider_event_dynamic_bool,
550 "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG,
a82ffcff 551 side_field_list()
4f40d951
MD
552);
553
554static
555void test_dynamic_bool(void)
556{
67337c4a
MD
557 side_event_variadic(my_provider_event_dynamic_bool,
558 side_arg_list(),
559 side_arg_list(
a82ffcff
MD
560 side_arg_dynamic_field("a_true", side_arg_dynamic_bool(55)),
561 side_arg_dynamic_field("b_true", side_arg_dynamic_bool(-4)),
562 side_arg_dynamic_field("c_false", side_arg_dynamic_bool(0)),
563 side_arg_dynamic_field("d_true", side_arg_dynamic_bool(256)),
564 )
4f40d951
MD
565 );
566}
567
67337c4a
MD
568side_static_event(my_provider_event_dynamic_vla_visitor,
569 "myprovider", "mydynamicvlavisitor", SIDE_LOGLEVEL_DEBUG,
570 side_field_list(
571 side_field_dynamic("dynamic"),
a82ffcff 572 )
8ceca0cd
MD
573);
574
575struct app_dynamic_vla_visitor_ctx {
576 const uint32_t *ptr;
577 uint32_t length;
578};
579
580static
67337c4a 581enum side_visitor_status test_dynamic_vla_visitor(const struct side_tracer_visitor_ctx *tracer_ctx, void *_ctx)
8ceca0cd
MD
582{
583 struct app_dynamic_vla_visitor_ctx *ctx = (struct app_dynamic_vla_visitor_ctx *) _ctx;
584 uint32_t length = ctx->length, i;
585
586 for (i = 0; i < length; i++) {
a82ffcff 587 const struct side_arg elem = side_arg_dynamic_u32(ctx->ptr[i]);
67337c4a
MD
588 if (tracer_ctx->write_elem(tracer_ctx, &elem) != SIDE_VISITOR_STATUS_OK)
589 return SIDE_VISITOR_STATUS_ERROR;
8ceca0cd 590 }
67337c4a 591 return SIDE_VISITOR_STATUS_OK;
8ceca0cd
MD
592}
593
594static uint32_t testarray_dynamic_vla[] = { 1, 2, 3, 4, 5, 6, 7, 8 };
595
596static
597void test_dynamic_vla_with_visitor(void)
598{
67337c4a 599 side_event_cond(my_provider_event_dynamic_vla_visitor) {
8ceca0cd
MD
600 struct app_dynamic_vla_visitor_ctx ctx = {
601 .ptr = testarray_dynamic_vla,
67337c4a 602 .length = SIDE_ARRAY_SIZE(testarray_dynamic_vla),
8ceca0cd 603 };
c6af61dc 604 side_arg_dynamic_define_vla_visitor(myvlavisitor, test_dynamic_vla_visitor, &ctx);
67337c4a
MD
605 side_event_call(my_provider_event_dynamic_vla_visitor,
606 side_arg_list(
c6af61dc 607 side_arg_dynamic_vla_visitor(&myvlavisitor)
8ceca0cd
MD
608 )
609 );
610 }
611}
612
67337c4a
MD
613side_static_event(my_provider_event_dynamic_struct_visitor,
614 "myprovider", "mydynamicstructvisitor", SIDE_LOGLEVEL_DEBUG,
615 side_field_list(
616 side_field_dynamic("dynamic"),
a82ffcff 617 )
2b359235
MD
618);
619
620struct struct_visitor_pair {
621 const char *name;
622 uint32_t value;
623};
624
625struct app_dynamic_struct_visitor_ctx {
626 const struct struct_visitor_pair *ptr;
627 uint32_t length;
628};
629
630static
67337c4a 631enum side_visitor_status test_dynamic_struct_visitor(const struct side_tracer_dynamic_struct_visitor_ctx *tracer_ctx, void *_ctx)
2b359235
MD
632{
633 struct app_dynamic_struct_visitor_ctx *ctx = (struct app_dynamic_struct_visitor_ctx *) _ctx;
634 uint32_t length = ctx->length, i;
635
636 for (i = 0; i < length; i++) {
f13253cb
MD
637 struct side_arg_dynamic_field dynamic_field =
638 side_arg_dynamic_field(ctx->ptr[i].name,
639 side_arg_dynamic_u32(ctx->ptr[i].value));
67337c4a
MD
640 if (tracer_ctx->write_field(tracer_ctx, &dynamic_field) != SIDE_VISITOR_STATUS_OK)
641 return SIDE_VISITOR_STATUS_ERROR;
2b359235 642 }
67337c4a 643 return SIDE_VISITOR_STATUS_OK;
2b359235
MD
644}
645
646static struct struct_visitor_pair testarray_dynamic_struct[] = {
647 { "a", 1, },
648 { "b", 2, },
649 { "c", 3, },
650 { "d", 4, },
651};
652
653static
654void test_dynamic_struct_with_visitor(void)
655{
67337c4a 656 side_event_cond(my_provider_event_dynamic_struct_visitor) {
2b359235
MD
657 struct app_dynamic_struct_visitor_ctx ctx = {
658 .ptr = testarray_dynamic_struct,
67337c4a 659 .length = SIDE_ARRAY_SIZE(testarray_dynamic_struct),
2b359235 660 };
c6af61dc 661 side_arg_dynamic_define_struct_visitor(mystructvisitor, test_dynamic_struct_visitor, &ctx);
67337c4a
MD
662 side_event_call(my_provider_event_dynamic_struct_visitor,
663 side_arg_list(
c6af61dc 664 side_arg_dynamic_struct_visitor(&mystructvisitor)
2b359235
MD
665 )
666 );
667 }
668}
669
67337c4a
MD
670side_static_event(my_provider_event_user_attribute, "myprovider", "myevent_user_attribute", SIDE_LOGLEVEL_DEBUG,
671 side_field_list(
a82ffcff
MD
672 side_field_u32("abc"),
673 side_field_s64("def"),
399c836b 674 ),
67337c4a
MD
675 side_attr_list(
676 side_attr("user_attribute_a", side_attr_string("val1")),
677 side_attr("user_attribute_b", side_attr_string("val2")),
65010f43
MD
678 )
679);
680
681static
682void test_event_user_attribute(void)
683{
67337c4a 684 side_event(my_provider_event_user_attribute, side_arg_list(side_arg_u32(1), side_arg_s64(2)));
65010f43
MD
685}
686
67337c4a
MD
687side_static_event(my_provider_field_user_attribute, "myprovider", "myevent_field_attribute", SIDE_LOGLEVEL_DEBUG,
688 side_field_list(
689 side_field_u32("abc",
690 side_attr_list(
691 side_attr("user_attribute_a", side_attr_string("val1")),
692 side_attr("user_attribute_b", side_attr_u32(2)),
a848763d
MD
693 )
694 ),
67337c4a
MD
695 side_field_s64("def",
696 side_attr_list(
697 side_attr("user_attribute_c", side_attr_string("val3")),
698 side_attr("user_attribute_d", side_attr_s64(-5)),
a848763d
MD
699 )
700 ),
a82ffcff 701 )
a848763d
MD
702);
703
704static
705void test_field_user_attribute(void)
706{
67337c4a 707 side_event(my_provider_field_user_attribute, side_arg_list(side_arg_u32(1), side_arg_s64(2)));
a848763d
MD
708}
709
67337c4a
MD
710side_static_event_variadic(my_provider_event_variadic_attr,
711 "myprovider", "myvariadiceventattr", SIDE_LOGLEVEL_DEBUG,
a82ffcff 712 side_field_list()
808bd9bf
MD
713);
714
715static
716void test_variadic_attr(void)
717{
67337c4a
MD
718 side_event_variadic(my_provider_event_variadic_attr,
719 side_arg_list(),
720 side_arg_list(
721 side_arg_dynamic_field("a",
722 side_arg_dynamic_u32(55,
723 side_attr_list(
724 side_attr("user_attribute_c", side_attr_string("valX")),
725 side_attr("user_attribute_d", side_attr_u8(55)),
808bd9bf
MD
726 )
727 )
728 ),
67337c4a
MD
729 side_arg_dynamic_field("b",
730 side_arg_dynamic_s8(-4,
731 side_attr_list(
732 side_attr("X", side_attr_u8(1)),
733 side_attr("Y", side_attr_s8(2)),
808bd9bf
MD
734 )
735 )
736 ),
a82ffcff 737 )
808bd9bf
MD
738 );
739}
740
67337c4a
MD
741side_static_event_variadic(my_provider_event_variadic_vla_attr,
742 "myprovider", "myvariadiceventvlaattr", SIDE_LOGLEVEL_DEBUG,
a82ffcff 743 side_field_list()
808bd9bf
MD
744);
745
746static
747void test_variadic_vla_attr(void)
748{
67337c4a
MD
749 side_arg_dynamic_define_vec(myvla,
750 side_arg_list(
751 side_arg_dynamic_u32(1,
752 side_attr_list(
753 side_attr("Z", side_attr_u8(0)),
754 side_attr("A", side_attr_u8(123)),
808bd9bf
MD
755 )
756 ),
a82ffcff
MD
757 side_arg_dynamic_u32(2),
758 side_arg_dynamic_u32(3),
8d20e708 759 ),
67337c4a
MD
760 side_attr_list(
761 side_attr("X", side_attr_u8(1)),
762 side_attr("Y", side_attr_u8(2)),
808bd9bf
MD
763 )
764 );
67337c4a
MD
765 side_event_variadic(my_provider_event_variadic_vla_attr,
766 side_arg_list(),
767 side_arg_list(
768 side_arg_dynamic_field("a", side_arg_dynamic_vla(&myvla)),
a82ffcff 769 )
808bd9bf
MD
770 );
771}
772
67337c4a
MD
773side_static_event_variadic(my_provider_event_variadic_struct_attr,
774 "myprovider", "myvariadiceventstructattr", SIDE_LOGLEVEL_DEBUG,
a82ffcff 775 side_field_list()
808bd9bf
MD
776);
777
778static
779void test_variadic_struct_attr(void)
780{
67337c4a
MD
781 side_event_cond(my_provider_event_variadic_struct_attr) {
782 side_arg_dynamic_define_struct(mystruct,
783 side_arg_list(
784 side_arg_dynamic_field("a",
785 side_arg_dynamic_u32(43,
786 side_attr_list(
787 side_attr("A", side_attr_bool(true)),
808bd9bf
MD
788 )
789 )
790 ),
a82ffcff 791 side_arg_dynamic_field("b", side_arg_dynamic_u8(55)),
8d20e708 792 ),
67337c4a
MD
793 side_attr_list(
794 side_attr("X", side_attr_u8(1)),
795 side_attr("Y", side_attr_u8(2)),
808bd9bf
MD
796 )
797 );
67337c4a
MD
798 side_event_call_variadic(my_provider_event_variadic_struct_attr,
799 side_arg_list(),
800 side_arg_list(
801 side_arg_dynamic_field("a", side_arg_dynamic_struct(&mystruct)),
a82ffcff 802 )
808bd9bf
MD
803 );
804 }
805}
806
67337c4a
MD
807side_static_event(my_provider_event_float, "myprovider", "myeventfloat", SIDE_LOGLEVEL_DEBUG,
808 side_field_list(
fb25b355 809#if __HAVE_FLOAT16
a82ffcff
MD
810 side_field_float_binary16("binary16"),
811 side_field_float_binary16_le("binary16_le"),
812 side_field_float_binary16_be("binary16_be"),
fb25b355
MD
813#endif
814#if __HAVE_FLOAT32
a82ffcff
MD
815 side_field_float_binary32("binary32"),
816 side_field_float_binary32_le("binary32_le"),
817 side_field_float_binary32_be("binary32_be"),
fb25b355
MD
818#endif
819#if __HAVE_FLOAT64
a82ffcff
MD
820 side_field_float_binary64("binary64"),
821 side_field_float_binary64_le("binary64_le"),
822 side_field_float_binary64_be("binary64_be"),
fb25b355
MD
823#endif
824#if __HAVE_FLOAT128
a82ffcff
MD
825 side_field_float_binary128("binary128"),
826 side_field_float_binary128_le("binary128_le"),
827 side_field_float_binary128_be("binary128_be"),
fb25b355 828#endif
a82ffcff 829 )
fb25b355
MD
830);
831
832static
833void test_float(void)
834{
8bdd5c12
MD
835#if __HAVE_FLOAT16
836 union {
837 _Float16 f;
838 uint16_t u;
839 } float16 = {
840 .f = 1.1,
841 };
842#endif
843#if __HAVE_FLOAT32
844 union {
845 _Float32 f;
846 uint32_t u;
847 } float32 = {
848 .f = 2.2,
849 };
850#endif
851#if __HAVE_FLOAT64
852 union {
853 _Float64 f;
854 uint64_t u;
855 } float64 = {
856 .f = 3.3,
857 };
858#endif
859#if __HAVE_FLOAT128
860 union {
861 _Float128 f;
862 char arr[16];
863 } float128 = {
864 .f = 4.4,
865 };
866#endif
867
868#if __HAVE_FLOAT16
67337c4a 869 float16.u = side_bswap_16(float16.u);
8bdd5c12
MD
870#endif
871#if __HAVE_FLOAT32
67337c4a 872 float32.u = side_bswap_32(float32.u);
8bdd5c12
MD
873#endif
874#if __HAVE_FLOAT64
67337c4a 875 float64.u = side_bswap_64(float64.u);
8bdd5c12
MD
876#endif
877#if __HAVE_FLOAT128
67337c4a 878 side_bswap_128p(float128.arr);
8bdd5c12
MD
879#endif
880
67337c4a
MD
881 side_event(my_provider_event_float,
882 side_arg_list(
fb25b355 883#if __HAVE_FLOAT16
67337c4a
MD
884 side_arg_float_binary16(1.1),
885# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
886 side_arg_float_binary16(1.1),
887 side_arg_float_binary16(float16.f),
8bdd5c12 888# else
67337c4a
MD
889 side_arg_float_binary16(float16.f),
890 side_arg_float_binary16(1.1),
8bdd5c12 891# endif
fb25b355
MD
892#endif
893#if __HAVE_FLOAT32
67337c4a
MD
894 side_arg_float_binary32(2.2),
895# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
896 side_arg_float_binary32(2.2),
897 side_arg_float_binary32(float32.f),
8bdd5c12 898# else
67337c4a
MD
899 side_arg_float_binary32(float32.f),
900 side_arg_float_binary32(2.2),
8bdd5c12 901# endif
fb25b355
MD
902#endif
903#if __HAVE_FLOAT64
67337c4a
MD
904 side_arg_float_binary64(3.3),
905# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
906 side_arg_float_binary64(3.3),
907 side_arg_float_binary64(float64.f),
8bdd5c12 908# else
67337c4a
MD
909 side_arg_float_binary64(float64.f),
910 side_arg_float_binary64(3.3),
8bdd5c12 911# endif
fb25b355
MD
912#endif
913#if __HAVE_FLOAT128
67337c4a
MD
914 side_arg_float_binary128(4.4),
915# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
916 side_arg_float_binary128(4.4),
917 side_arg_float_binary128(float128.f),
8bdd5c12 918# else
67337c4a
MD
919 side_arg_float_binary128(float128.f),
920 side_arg_float_binary128(4.4),
8bdd5c12 921# endif
fb25b355
MD
922#endif
923 )
924 );
925}
926
67337c4a
MD
927side_static_event_variadic(my_provider_event_variadic_float,
928 "myprovider", "myvariadicfloat", SIDE_LOGLEVEL_DEBUG,
a82ffcff 929 side_field_list()
fb25b355
MD
930);
931
932static
933void test_variadic_float(void)
934{
8bdd5c12
MD
935#if __HAVE_FLOAT16
936 union {
937 _Float16 f;
938 uint16_t u;
939 } float16 = {
940 .f = 1.1,
941 };
942#endif
943#if __HAVE_FLOAT32
944 union {
945 _Float32 f;
946 uint32_t u;
947 } float32 = {
948 .f = 2.2,
949 };
950#endif
951#if __HAVE_FLOAT64
952 union {
953 _Float64 f;
954 uint64_t u;
955 } float64 = {
956 .f = 3.3,
957 };
958#endif
959#if __HAVE_FLOAT128
960 union {
961 _Float128 f;
962 char arr[16];
963 } float128 = {
964 .f = 4.4,
965 };
966#endif
967
968#if __HAVE_FLOAT16
67337c4a 969 float16.u = side_bswap_16(float16.u);
8bdd5c12
MD
970#endif
971#if __HAVE_FLOAT32
67337c4a 972 float32.u = side_bswap_32(float32.u);
8bdd5c12
MD
973#endif
974#if __HAVE_FLOAT64
67337c4a 975 float64.u = side_bswap_64(float64.u);
8bdd5c12
MD
976#endif
977#if __HAVE_FLOAT128
67337c4a 978 side_bswap_128p(float128.arr);
8bdd5c12
MD
979#endif
980
67337c4a
MD
981 side_event_variadic(my_provider_event_variadic_float,
982 side_arg_list(),
983 side_arg_list(
fb25b355 984#if __HAVE_FLOAT16
a82ffcff 985 side_arg_dynamic_field("binary16", side_arg_dynamic_float_binary16(1.1)),
67337c4a 986# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
a82ffcff
MD
987 side_arg_dynamic_field("binary16_le", side_arg_dynamic_float_binary16_le(1.1)),
988 side_arg_dynamic_field("binary16_be", side_arg_dynamic_float_binary16_be(float16.f)),
8bdd5c12 989# else
a82ffcff
MD
990 side_arg_dynamic_field("binary16_le", side_arg_dynamic_float_binary16_le(float16.f)),
991 side_arg_dynamic_field("binary16_be", side_arg_dynamic_float_binary16_be(1.1)),
8bdd5c12 992# endif
fb25b355
MD
993#endif
994#if __HAVE_FLOAT32
a82ffcff 995 side_arg_dynamic_field("binary32", side_arg_dynamic_float_binary32(2.2)),
67337c4a 996# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
a82ffcff
MD
997 side_arg_dynamic_field("binary32_le", side_arg_dynamic_float_binary32_le(2.2)),
998 side_arg_dynamic_field("binary32_be", side_arg_dynamic_float_binary32_be(float32.f)),
8bdd5c12 999# else
a82ffcff
MD
1000 side_arg_dynamic_field("binary32_le", side_arg_dynamic_float_binary32_le(float32.f)),
1001 side_arg_dynamic_field("binary32_be", side_arg_dynamic_float_binary32_be(2.2)),
8bdd5c12 1002# endif
fb25b355
MD
1003#endif
1004#if __HAVE_FLOAT64
a82ffcff 1005 side_arg_dynamic_field("binary64", side_arg_dynamic_float_binary64(3.3)),
67337c4a 1006# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
a82ffcff
MD
1007 side_arg_dynamic_field("binary64_le", side_arg_dynamic_float_binary64_le(3.3)),
1008 side_arg_dynamic_field("binary64_be", side_arg_dynamic_float_binary64_be(float64.f)),
8bdd5c12 1009# else
a82ffcff
MD
1010 side_arg_dynamic_field("binary64_le", side_arg_dynamic_float_binary64_le(float64.f)),
1011 side_arg_dynamic_field("binary64_be", side_arg_dynamic_float_binary64_be(3.3)),
8bdd5c12 1012# endif
fb25b355
MD
1013#endif
1014#if __HAVE_FLOAT128
a82ffcff 1015 side_arg_dynamic_field("binary128", side_arg_dynamic_float_binary128(4.4)),
67337c4a 1016# if SIDE_FLOAT_WORD_ORDER == SIDE_LITTLE_ENDIAN
a82ffcff
MD
1017 side_arg_dynamic_field("binary128_le", side_arg_dynamic_float_binary128_le(4.4)),
1018 side_arg_dynamic_field("binary128_be", side_arg_dynamic_float_binary128_be(float128.f)),
8bdd5c12 1019# else
a82ffcff
MD
1020 side_arg_dynamic_field("binary128_le", side_arg_dynamic_float_binary128_le(float128.f)),
1021 side_arg_dynamic_field("binary128_be", side_arg_dynamic_float_binary128_be(4.4)),
8bdd5c12 1022# endif
fb25b355 1023#endif
a82ffcff 1024 )
fb25b355
MD
1025 );
1026}
1027
67337c4a
MD
1028static side_define_enum(myenum,
1029 side_enum_mapping_list(
1030 side_enum_mapping_range("one-ten", 1, 10),
1031 side_enum_mapping_range("100-200", 100, 200),
1032 side_enum_mapping_value("200", 200),
1033 side_enum_mapping_value("300", 300),
a82ffcff 1034 )
79f677ba
MD
1035);
1036
67337c4a
MD
1037side_static_event(my_provider_event_enum, "myprovider", "myeventenum", SIDE_LOGLEVEL_DEBUG,
1038 side_field_list(
a82ffcff
MD
1039 side_field_enum("5", &myenum, side_elem(side_type_u32())),
1040 side_field_enum("400", &myenum, side_elem(side_type_u64())),
1041 side_field_enum("200", &myenum, side_elem(side_type_u8())),
1042 side_field_enum("-100", &myenum, side_elem(side_type_s8())),
1043 side_field_enum("6_be", &myenum, side_elem(side_type_u32_be())),
1044 side_field_enum("6_le", &myenum, side_elem(side_type_u32_le())),
1045 )
79f677ba
MD
1046);
1047
1048static
1049void test_enum(void)
1050{
67337c4a
MD
1051 side_event(my_provider_event_enum,
1052 side_arg_list(
1053 side_arg_u32(5),
1054 side_arg_u64(400),
1055 side_arg_u8(200),
1056 side_arg_s8(-100),
1057#if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
1058 side_arg_u32(side_bswap_32(6)),
1059 side_arg_u32(6),
8bdd5c12 1060#else
67337c4a
MD
1061 side_arg_u32(6),
1062 side_arg_u32(side_bswap_32(6)),
8bdd5c12 1063#endif
79f677ba
MD
1064 )
1065 );
1066}
1067
ea32e5fc 1068/* A bitmap enum maps bits to labels. */
67337c4a
MD
1069static side_define_enum_bitmap(myenum_bitmap,
1070 side_enum_bitmap_mapping_list(
1071 side_enum_bitmap_mapping_value("0", 0),
1072 side_enum_bitmap_mapping_range("1-2", 1, 2),
1073 side_enum_bitmap_mapping_range("2-4", 2, 4),
1074 side_enum_bitmap_mapping_value("3", 3),
1075 side_enum_bitmap_mapping_value("30", 30),
1076 side_enum_bitmap_mapping_value("63", 63),
1077 side_enum_bitmap_mapping_range("158-160", 158, 160),
1078 side_enum_bitmap_mapping_value("159", 159),
1079 side_enum_bitmap_mapping_range("500-700", 500, 700),
a82ffcff 1080 )
ea32e5fc
MD
1081);
1082
67337c4a
MD
1083side_static_event(my_provider_event_enum_bitmap, "myprovider", "myeventenumbitmap", SIDE_LOGLEVEL_DEBUG,
1084 side_field_list(
a82ffcff
MD
1085 side_field_enum_bitmap("bit_0", &myenum_bitmap, side_elem(side_type_u32())),
1086 side_field_enum_bitmap("bit_1", &myenum_bitmap, side_elem(side_type_u32())),
1087 side_field_enum_bitmap("bit_2", &myenum_bitmap, side_elem(side_type_u8())),
1088 side_field_enum_bitmap("bit_3", &myenum_bitmap, side_elem(side_type_u8())),
1089 side_field_enum_bitmap("bit_30", &myenum_bitmap, side_elem(side_type_u32())),
1090 side_field_enum_bitmap("bit_31", &myenum_bitmap, side_elem(side_type_u32())),
1091 side_field_enum_bitmap("bit_63", &myenum_bitmap, side_elem(side_type_u64())),
1092 side_field_enum_bitmap("bits_1+63", &myenum_bitmap, side_elem(side_type_u64())),
1093 side_field_enum_bitmap("byte_bit_2", &myenum_bitmap, side_elem(side_type_byte())),
67337c4a 1094 side_field_enum_bitmap("bit_159", &myenum_bitmap,
a82ffcff 1095 side_elem(side_type_array(side_elem(side_type_u32()), 5))),
67337c4a 1096 side_field_enum_bitmap("bit_159", &myenum_bitmap,
a82ffcff
MD
1097 side_elem(side_type_vla(side_elem(side_type_u32())))),
1098 side_field_enum_bitmap("bit_2_be", &myenum_bitmap, side_elem(side_type_u32_be())),
1099 side_field_enum_bitmap("bit_2_le", &myenum_bitmap, side_elem(side_type_u32_le())),
1100 )
ea32e5fc
MD
1101);
1102
1103static
1104void test_enum_bitmap(void)
1105{
67337c4a
MD
1106 side_event_cond(my_provider_event_enum_bitmap) {
1107 side_arg_define_vec(myarray,
1108 side_arg_list(
1109 side_arg_u32(0),
1110 side_arg_u32(0),
1111 side_arg_u32(0),
1112 side_arg_u32(0),
1113 side_arg_u32(0x80000000), /* bit 159 */
af6aa6e1
MD
1114 )
1115 );
67337c4a
MD
1116 side_event_call(my_provider_event_enum_bitmap,
1117 side_arg_list(
1118 side_arg_u32(1U << 0),
1119 side_arg_u32(1U << 1),
1120 side_arg_u8(1U << 2),
1121 side_arg_u8(1U << 3),
1122 side_arg_u32(1U << 30),
1123 side_arg_u32(1U << 31),
1124 side_arg_u64(1ULL << 63),
1125 side_arg_u64((1ULL << 1) | (1ULL << 63)),
1126 side_arg_byte(1U << 2),
1127 side_arg_array(&myarray),
1128 side_arg_vla(&myarray),
1129#if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
1130 side_arg_u32(side_bswap_32(1U << 2)),
1131 side_arg_u32(1U << 2),
8bdd5c12 1132#else
67337c4a
MD
1133 side_arg_u32(1U << 2),
1134 side_arg_u32(side_bswap_32(1U << 2)),
8bdd5c12 1135#endif
af6aa6e1
MD
1136 )
1137 );
1138 }
ea32e5fc
MD
1139}
1140
67337c4a
MD
1141side_static_event_variadic(my_provider_event_blob, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG,
1142 side_field_list(
a82ffcff
MD
1143 side_field_byte("blobfield"),
1144 side_field_array("arrayblob", side_elem(side_type_byte()), 3),
1145 )
7aec0d09
MD
1146);
1147
1148static
1149void test_blob(void)
1150{
67337c4a
MD
1151 side_event_cond(my_provider_event_blob) {
1152 side_arg_define_vec(myarray, side_arg_list(side_arg_byte(1), side_arg_byte(2), side_arg_byte(3)));
1153 side_arg_dynamic_define_vec(myvla,
1154 side_arg_list(
a82ffcff
MD
1155 side_arg_dynamic_byte(0x22),
1156 side_arg_dynamic_byte(0x33),
1157 )
199e7aa9 1158 );
67337c4a
MD
1159 side_event_call_variadic(my_provider_event_blob,
1160 side_arg_list(
1161 side_arg_byte(0x55),
1162 side_arg_array(&myarray),
199e7aa9 1163 ),
67337c4a
MD
1164 side_arg_list(
1165 side_arg_dynamic_field("varblobfield",
a82ffcff 1166 side_arg_dynamic_byte(0x55)
199e7aa9 1167 ),
67337c4a 1168 side_arg_dynamic_field("varblobvla", side_arg_dynamic_vla(&myvla)),
a82ffcff 1169 )
7aec0d09
MD
1170 );
1171 }
1172}
ea32e5fc 1173
67337c4a
MD
1174side_static_event_variadic(my_provider_event_format_string,
1175 "myprovider", "myeventformatstring", SIDE_LOGLEVEL_DEBUG,
1176 side_field_list(
a82ffcff 1177 side_field_string("fmt"),
71aa8975 1178 ),
67337c4a
MD
1179 side_attr_list(
1180 side_attr("lang.c.format_string", side_attr_bool(true)),
71aa8975
MD
1181 )
1182);
1183
1184static
1185void test_fmt_string(void)
1186{
67337c4a
MD
1187 side_event_cond(my_provider_event_format_string) {
1188 side_arg_dynamic_define_vec(args,
1189 side_arg_list(
a82ffcff
MD
1190 side_arg_dynamic_string("blah"),
1191 side_arg_dynamic_s32(123),
1192 )
71aa8975 1193 );
67337c4a
MD
1194 side_event_call_variadic(my_provider_event_format_string,
1195 side_arg_list(
1196 side_arg_string("This is a formatted string with str: %s int: %d"),
71aa8975 1197 ),
67337c4a
MD
1198 side_arg_list(
1199 side_arg_dynamic_field("arguments", side_arg_dynamic_vla(&args)),
a82ffcff 1200 )
71aa8975
MD
1201 );
1202 }
1203}
1204
67337c4a
MD
1205side_static_event_variadic(my_provider_event_endian, "myprovider", "myevent_endian", SIDE_LOGLEVEL_DEBUG,
1206 side_field_list(
a82ffcff
MD
1207 side_field_u16_le("u16_le"),
1208 side_field_u32_le("u32_le"),
1209 side_field_u64_le("u64_le"),
1210 side_field_s16_le("s16_le"),
1211 side_field_s32_le("s32_le"),
1212 side_field_s64_le("s64_le"),
1213 side_field_u16_be("u16_be"),
1214 side_field_u32_be("u32_be"),
1215 side_field_u64_be("u64_be"),
1216 side_field_s16_be("s16_be"),
1217 side_field_s32_be("s32_be"),
1218 side_field_s64_be("s64_be"),
1219 )
8bdd5c12
MD
1220);
1221
1222static
1223void test_endian(void)
1224{
67337c4a
MD
1225 side_event_variadic(my_provider_event_endian,
1226 side_arg_list(
1227#if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
1228 side_arg_u16(1),
1229 side_arg_u32(1),
1230 side_arg_u64(1),
1231 side_arg_s16(1),
1232 side_arg_s32(1),
1233 side_arg_s64(1),
1234 side_arg_u16(side_bswap_16(1)),
1235 side_arg_u32(side_bswap_32(1)),
1236 side_arg_u64(side_bswap_64(1)),
1237 side_arg_s16(side_bswap_16(1)),
1238 side_arg_s32(side_bswap_32(1)),
1239 side_arg_s64(side_bswap_64(1)),
8bdd5c12 1240#else
67337c4a
MD
1241 side_arg_u16(side_bswap_16(1)),
1242 side_arg_u32(side_bswap_32(1)),
1243 side_arg_u64(side_bswap_64(1)),
1244 side_arg_s16(side_bswap_16(1)),
1245 side_arg_s32(side_bswap_32(1)),
1246 side_arg_s64(side_bswap_64(1)),
1247 side_arg_u16(1),
1248 side_arg_u32(1),
1249 side_arg_u64(1),
1250 side_arg_s16(1),
1251 side_arg_s32(1),
1252 side_arg_s64(1),
8bdd5c12
MD
1253#endif
1254 ),
67337c4a
MD
1255 side_arg_list(
1256#if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
a82ffcff
MD
1257 side_arg_dynamic_field("u16_le", side_arg_dynamic_u16_le(1)),
1258 side_arg_dynamic_field("u32_le", side_arg_dynamic_u32_le(1)),
1259 side_arg_dynamic_field("u64_le", side_arg_dynamic_u64_le(1)),
1260 side_arg_dynamic_field("s16_le", side_arg_dynamic_s16_le(1)),
1261 side_arg_dynamic_field("s32_le", side_arg_dynamic_s32_le(1)),
1262 side_arg_dynamic_field("s64_le", side_arg_dynamic_s64_le(1)),
1263 side_arg_dynamic_field("u16_be", side_arg_dynamic_u16_be(side_bswap_16(1))),
1264 side_arg_dynamic_field("u32_be", side_arg_dynamic_u32_be(side_bswap_32(1))),
1265 side_arg_dynamic_field("u64_be", side_arg_dynamic_u64_be(side_bswap_64(1))),
1266 side_arg_dynamic_field("s16_be", side_arg_dynamic_s16_be(side_bswap_16(1))),
1267 side_arg_dynamic_field("s32_be", side_arg_dynamic_s32_be(side_bswap_32(1))),
1268 side_arg_dynamic_field("s64_be", side_arg_dynamic_s64_be(side_bswap_64(1))),
8bdd5c12 1269#else
a82ffcff
MD
1270 side_arg_dynamic_field("u16_le", side_arg_dynamic_u16_le(side_bswap_16(1))),
1271 side_arg_dynamic_field("u32_le", side_arg_dynamic_u32_le(side_bswap_32(1))),
1272 side_arg_dynamic_field("u64_le", side_arg_dynamic_u64_le(side_bswap_64(1))),
1273 side_arg_dynamic_field("s16_le", side_arg_dynamic_s16_le(side_bswap_16(1))),
1274 side_arg_dynamic_field("s32_le", side_arg_dynamic_s32_le(side_bswap_32(1))),
1275 side_arg_dynamic_field("s64_le", side_arg_dynamic_s64_le(side_bswap_64(1))),
1276 side_arg_dynamic_field("u16_be", side_arg_dynamic_u16_be(1)),
1277 side_arg_dynamic_field("u32_be", side_arg_dynamic_u32_be(1)),
1278 side_arg_dynamic_field("u64_be", side_arg_dynamic_u64_be(1)),
1279 side_arg_dynamic_field("s16_be", side_arg_dynamic_s16_be(1)),
1280 side_arg_dynamic_field("s32_be", side_arg_dynamic_s32_be(1)),
1281 side_arg_dynamic_field("s64_be", side_arg_dynamic_s64_be(1)),
8bdd5c12 1282#endif
a82ffcff 1283 )
8bdd5c12
MD
1284 );
1285}
1286
67337c4a
MD
1287side_static_event(my_provider_event_base, "myprovider", "myevent_base", SIDE_LOGLEVEL_DEBUG,
1288 side_field_list(
1289 side_field_u8("u8base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1290 side_field_u8("u8base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1291 side_field_u8("u8base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1292 side_field_u8("u8base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1293 side_field_u16("u16base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1294 side_field_u16("u16base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1295 side_field_u16("u16base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1296 side_field_u16("u16base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1297 side_field_u32("u32base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1298 side_field_u32("u32base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1299 side_field_u32("u32base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1300 side_field_u32("u32base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1301 side_field_u64("u64base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1302 side_field_u64("u64base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1303 side_field_u64("u64base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1304 side_field_u64("u64base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1305 side_field_s8("s8base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1306 side_field_s8("s8base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1307 side_field_s8("s8base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1308 side_field_s8("s8base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1309 side_field_s16("s16base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1310 side_field_s16("s16base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1311 side_field_s16("s16base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1312 side_field_s16("s16base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1313 side_field_s32("s32base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1314 side_field_s32("s32base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1315 side_field_s32("s32base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1316 side_field_s32("s32base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1317 side_field_s64("s64base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
1318 side_field_s64("s64base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
1319 side_field_s64("s64base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1320 side_field_s64("s64base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
a82ffcff 1321 )
1d9c515c
MD
1322);
1323
1324static
1325void test_base(void)
1326{
67337c4a
MD
1327 side_event(my_provider_event_base,
1328 side_arg_list(
1329 side_arg_u8(55),
1330 side_arg_u8(55),
1331 side_arg_u8(55),
1332 side_arg_u8(55),
1333 side_arg_u16(55),
1334 side_arg_u16(55),
1335 side_arg_u16(55),
1336 side_arg_u16(55),
1337 side_arg_u32(55),
1338 side_arg_u32(55),
1339 side_arg_u32(55),
1340 side_arg_u32(55),
1341 side_arg_u64(55),
1342 side_arg_u64(55),
1343 side_arg_u64(55),
1344 side_arg_u64(55),
1345 side_arg_s8(-55),
1346 side_arg_s8(-55),
1347 side_arg_s8(-55),
1348 side_arg_s8(-55),
1349 side_arg_s16(-55),
1350 side_arg_s16(-55),
1351 side_arg_s16(-55),
1352 side_arg_s16(-55),
1353 side_arg_s32(-55),
1354 side_arg_s32(-55),
1355 side_arg_s32(-55),
1356 side_arg_s32(-55),
1357 side_arg_s64(-55),
1358 side_arg_s64(-55),
1359 side_arg_s64(-55),
1360 side_arg_s64(-55),
1d9c515c
MD
1361 )
1362 );
1363}
1364
7a1cb105
MD
1365struct test {
1366 uint32_t a;
1367 uint64_t b;
1368 uint8_t c;
1369 int32_t d;
1370 uint16_t e;
bc0b21eb
MD
1371 int8_t f;
1372 int16_t g;
1373 int32_t h;
1374 int64_t i;
1375 int64_t j;
1376 int64_t k;
c1723f3c 1377 uint64_t test;
7a1cb105
MD
1378};
1379
67337c4a
MD
1380static side_define_struct(mystructgatherdef,
1381 side_field_list(
1382 side_field_gather_unsigned_integer("a", offsetof(struct test, a),
1383 side_struct_field_sizeof(struct test, a), 0, 0,
a82ffcff 1384 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a
MD
1385 side_field_gather_signed_integer("d", offsetof(struct test, d),
1386 side_struct_field_sizeof(struct test, d), 0, 0,
a82ffcff 1387 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a
MD
1388 side_field_gather_unsigned_integer("e", offsetof(struct test, e),
1389 side_struct_field_sizeof(struct test, e), 8, 4,
1390 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1391 side_field_gather_signed_integer("f", offsetof(struct test, f),
1392 side_struct_field_sizeof(struct test, f), 1, 4,
1393 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1394 side_field_gather_signed_integer("g", offsetof(struct test, g),
1395 side_struct_field_sizeof(struct test, g), 11, 4,
1396 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1397 side_field_gather_signed_integer("h", offsetof(struct test, h),
1398 side_struct_field_sizeof(struct test, h), 1, 31,
1399 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1400 side_field_gather_signed_integer("i", offsetof(struct test, i),
1401 side_struct_field_sizeof(struct test, i), 33, 20,
1402 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1403 side_field_gather_signed_integer("j", offsetof(struct test, j),
1404 side_struct_field_sizeof(struct test, j), 63, 1,
1405 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1406 side_field_gather_signed_integer("k", offsetof(struct test, k),
1407 side_struct_field_sizeof(struct test, k), 1, 63,
1408 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
1409 side_field_gather_unsigned_integer_le("test", offsetof(struct test, test),
1410 side_struct_field_sizeof(struct test, test), 0, 64,
1411 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1412 side_field_gather_unsigned_integer_le("test_le", offsetof(struct test, test),
1413 side_struct_field_sizeof(struct test, test), 0, 64,
1414 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
1415 side_field_gather_unsigned_integer_be("test_be", offsetof(struct test, test),
1416 side_struct_field_sizeof(struct test, test), 0, 64,
1417 SIDE_TYPE_GATHER_ACCESS_DIRECT, side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
a82ffcff 1418 )
7a1cb105
MD
1419);
1420
67337c4a
MD
1421side_static_event(my_provider_event_structgather, "myprovider", "myeventstructgather", SIDE_LOGLEVEL_DEBUG,
1422 side_field_list(
1423 side_field_gather_struct("structgather", &mystructgatherdef, 0, sizeof(struct test),
1424 SIDE_TYPE_GATHER_ACCESS_DIRECT),
1425 side_field_gather_signed_integer("intgather", 0, sizeof(int32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT,
1426 side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
13d97eca 1427#if __HAVE_FLOAT32
a82ffcff 1428 side_field_gather_float("f32", 0, sizeof(_Float32), SIDE_TYPE_GATHER_ACCESS_DIRECT),
13d97eca 1429#endif
a82ffcff 1430 )
7a1cb105
MD
1431);
1432
1433static
d41cb7ee 1434void test_struct_gather(void)
7a1cb105 1435{
67337c4a 1436 side_event_cond(my_provider_event_structgather) {
7a1cb105
MD
1437 struct test mystruct = {
1438 .a = 55,
1439 .b = 123,
1440 .c = 2,
1441 .d = -55,
1442 .e = 0xABCD,
bc0b21eb
MD
1443 .f = -1,
1444 .g = -1,
1445 .h = -1,
1446 .i = -1,
1447 .j = -1,
1448 .k = -1,
c1723f3c 1449 .test = 0xFF,
7a1cb105 1450 };
33956c71 1451 int32_t val = -66;
13d97eca
MD
1452#if __HAVE_FLOAT32
1453 _Float32 f32 = 1.1;
1454#endif
67337c4a
MD
1455 side_event_call(my_provider_event_structgather,
1456 side_arg_list(
1457 side_arg_gather_struct(&mystruct),
1458 side_arg_gather_integer(&val),
13d97eca 1459#if __HAVE_FLOAT32
67337c4a 1460 side_arg_gather_float(&f32),
13d97eca 1461#endif
33956c71
MD
1462 )
1463 );
7a1cb105
MD
1464 }
1465}
1466
7394a8b8
MD
1467struct testnest2 {
1468 uint8_t c;
1469};
1470
1471struct testnest1 {
1472 uint64_t b;
1473 struct testnest2 *nest;
1474};
1475
1476struct testnest0 {
1477 uint32_t a;
1478 struct testnest1 *nest;
1479};
1480
67337c4a
MD
1481static side_define_struct(mystructgathernest2,
1482 side_field_list(
1483 side_field_gather_unsigned_integer("c", offsetof(struct testnest2, c),
1484 side_struct_field_sizeof(struct testnest2, c), 0, 0,
a82ffcff
MD
1485 SIDE_TYPE_GATHER_ACCESS_DIRECT),
1486 )
7394a8b8
MD
1487);
1488
67337c4a
MD
1489static side_define_struct(mystructgathernest1,
1490 side_field_list(
1491 side_field_gather_unsigned_integer("b", offsetof(struct testnest1, b),
1492 side_struct_field_sizeof(struct testnest1, b), 0, 0,
a82ffcff 1493 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1494 side_field_gather_struct("nest2", &mystructgathernest2,
dd7947bf 1495 offsetof(struct testnest1, nest), sizeof(struct testnest2),
67337c4a 1496 SIDE_TYPE_GATHER_ACCESS_POINTER),
a82ffcff 1497 )
7394a8b8
MD
1498);
1499
67337c4a
MD
1500static side_define_struct(mystructgathernest0,
1501 side_field_list(
1502 side_field_gather_unsigned_integer("a", offsetof(struct testnest0, a),
1503 side_struct_field_sizeof(struct testnest0, a), 0, 0,
a82ffcff 1504 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1505 side_field_gather_struct("nest1", &mystructgathernest1,
dd7947bf 1506 offsetof(struct testnest0, nest), sizeof(struct testnest1),
67337c4a 1507 SIDE_TYPE_GATHER_ACCESS_POINTER),
a82ffcff 1508 )
7394a8b8
MD
1509);
1510
67337c4a
MD
1511side_static_event(my_provider_event_structgather_nest,
1512 "myprovider", "myeventstructgathernest", SIDE_LOGLEVEL_DEBUG,
1513 side_field_list(
1514 side_field_gather_struct("nest0", &mystructgathernest0, 0,
1515 sizeof(struct testnest0), SIDE_TYPE_GATHER_ACCESS_DIRECT),
a82ffcff 1516 )
7394a8b8
MD
1517);
1518
1519static
d41cb7ee 1520void test_struct_gather_nest_ptr(void)
7394a8b8 1521{
67337c4a 1522 side_event_cond(my_provider_event_structgather_nest) {
7394a8b8
MD
1523 struct testnest2 mystruct2 = {
1524 .c = 77,
1525 };
1526 struct testnest1 mystruct1 = {
1527 .b = 66,
1528 .nest = &mystruct2,
1529 };
1530 struct testnest0 mystruct = {
1531 .a = 55,
1532 .nest = &mystruct1,
1533 };
67337c4a
MD
1534 side_event_call(my_provider_event_structgather_nest,
1535 side_arg_list(
1536 side_arg_gather_struct(&mystruct),
7394a8b8
MD
1537 )
1538 );
1539 }
1540}
1541
905f68e3
MD
1542struct testfloat {
1543#if __HAVE_FLOAT16
1544 _Float16 f16;
1545#endif
1546#if __HAVE_FLOAT32
1547 _Float32 f32;
1548#endif
1549#if __HAVE_FLOAT64
1550 _Float64 f64;
1551#endif
1552#if __HAVE_FLOAT128
1553 _Float128 f128;
1554#endif
1555};
1556
67337c4a
MD
1557static side_define_struct(mystructgatherfloat,
1558 side_field_list(
905f68e3 1559#if __HAVE_FLOAT16
67337c4a 1560 side_field_gather_float("f16", offsetof(struct testfloat, f16), side_struct_field_sizeof(struct testfloat, f16),
a82ffcff 1561 SIDE_TYPE_GATHER_ACCESS_DIRECT),
905f68e3
MD
1562#endif
1563#if __HAVE_FLOAT32
67337c4a 1564 side_field_gather_float("f32", offsetof(struct testfloat, f32), side_struct_field_sizeof(struct testfloat, f32),
a82ffcff 1565 SIDE_TYPE_GATHER_ACCESS_DIRECT),
905f68e3
MD
1566#endif
1567#if __HAVE_FLOAT64
67337c4a 1568 side_field_gather_float("f64", offsetof(struct testfloat, f64), side_struct_field_sizeof(struct testfloat, f64),
a82ffcff 1569 SIDE_TYPE_GATHER_ACCESS_DIRECT),
905f68e3
MD
1570#endif
1571#if __HAVE_FLOAT128
67337c4a 1572 side_field_gather_float("f128", offsetof(struct testfloat, f128), side_struct_field_sizeof(struct testfloat, f128),
a82ffcff 1573 SIDE_TYPE_GATHER_ACCESS_DIRECT),
905f68e3 1574#endif
a82ffcff 1575 )
905f68e3
MD
1576);
1577
67337c4a
MD
1578side_static_event(my_provider_event_structgatherfloat,
1579 "myprovider", "myeventstructgatherfloat", SIDE_LOGLEVEL_DEBUG,
1580 side_field_list(
1581 side_field_gather_struct("structgatherfloat", &mystructgatherfloat, 0,
1582 sizeof(struct testfloat), SIDE_TYPE_GATHER_ACCESS_DIRECT),
a82ffcff 1583 )
905f68e3
MD
1584);
1585
1586static
d41cb7ee 1587void test_struct_gather_float(void)
905f68e3 1588{
67337c4a 1589 side_event_cond(my_provider_event_structgatherfloat) {
905f68e3
MD
1590 struct testfloat mystruct = {
1591#if __HAVE_FLOAT16
1592 .f16 = 1.1,
1593#endif
1594#if __HAVE_FLOAT32
1595 .f32 = 2.2,
1596#endif
1597#if __HAVE_FLOAT64
1598 .f64 = 3.3,
1599#endif
1600#if __HAVE_FLOAT128
1601 .f128 = 4.4,
1602#endif
1603 };
67337c4a
MD
1604 side_event_call(my_provider_event_structgatherfloat,
1605 side_arg_list(
1606 side_arg_gather_struct(&mystruct),
905f68e3
MD
1607 )
1608 );
1609 }
1610}
1611
d41cb7ee 1612uint32_t mygatherarray[] = { 1, 2, 3, 4, 5 };
d9359cfa 1613
d41cb7ee 1614uint16_t mygatherarray2[] = { 6, 7, 8, 9 };
d9359cfa
MD
1615
1616struct testarray {
1617 int a;
1618 uint32_t *ptr;
1619};
1620
67337c4a
MD
1621static side_define_struct(mystructgatherarray,
1622 side_field_list(
1623 side_field_gather_array("array",
a82ffcff 1624 side_elem(side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
67337c4a 1625 SIDE_ARRAY_SIZE(mygatherarray),
d9359cfa 1626 offsetof(struct testarray, ptr),
a82ffcff
MD
1627 SIDE_TYPE_GATHER_ACCESS_POINTER
1628 ),
1629 )
d9359cfa
MD
1630);
1631
67337c4a
MD
1632side_static_event(my_provider_event_structgatherarray,
1633 "myprovider", "myeventstructgatherarray", SIDE_LOGLEVEL_DEBUG,
1634 side_field_list(
1635 side_field_gather_struct("structgatherarray", &mystructgatherarray, 0,
1636 sizeof(struct testarray), SIDE_TYPE_GATHER_ACCESS_DIRECT),
1637 side_field_gather_array("array2",
a82ffcff 1638 side_elem(side_type_gather_unsigned_integer(0, sizeof(uint16_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
67337c4a 1639 SIDE_ARRAY_SIZE(mygatherarray2), 0,
a82ffcff 1640 SIDE_TYPE_GATHER_ACCESS_DIRECT
d9359cfa 1641 ),
a82ffcff 1642 )
d9359cfa
MD
1643);
1644
1645static
d41cb7ee 1646void test_array_gather(void)
d9359cfa 1647{
67337c4a 1648 side_event_cond(my_provider_event_structgatherarray) {
d9359cfa
MD
1649 struct testarray mystruct = {
1650 .a = 55,
d41cb7ee 1651 .ptr = mygatherarray,
d9359cfa 1652 };
67337c4a
MD
1653 side_event_call(my_provider_event_structgatherarray,
1654 side_arg_list(
1655 side_arg_gather_struct(&mystruct),
1656 side_arg_gather_array(&mygatherarray2),
d9359cfa
MD
1657 )
1658 );
1659 }
1660}
1661
dd7947bf 1662#define TESTSGNESTARRAY_LEN 4
d41cb7ee 1663struct testgatherstructnest1 {
dd7947bf
MD
1664 int b;
1665 int c[TESTSGNESTARRAY_LEN];
1666};
1667
d41cb7ee
MD
1668struct testgatherstructnest0 {
1669 struct testgatherstructnest1 nest;
1670 struct testgatherstructnest1 nestarray[2];
dd7947bf
MD
1671 int a;
1672};
1673
67337c4a
MD
1674static side_define_struct(mystructgatherstructnest1,
1675 side_field_list(
1676 side_field_gather_signed_integer("b", offsetof(struct testgatherstructnest1, b),
1677 side_struct_field_sizeof(struct testgatherstructnest1, b), 0, 0,
a82ffcff 1678 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a
MD
1679 side_field_gather_array("c",
1680 side_elem(
1681 side_type_gather_signed_integer(0, sizeof(uint32_t), 0, 0,
a82ffcff 1682 SIDE_TYPE_GATHER_ACCESS_DIRECT)
dd7947bf
MD
1683 ),
1684 TESTSGNESTARRAY_LEN,
d41cb7ee 1685 offsetof(struct testgatherstructnest1, c),
a82ffcff
MD
1686 SIDE_TYPE_GATHER_ACCESS_DIRECT),
1687 )
dd7947bf
MD
1688);
1689
67337c4a
MD
1690static side_define_struct(mystructgatherstructnest0,
1691 side_field_list(
1692 side_field_gather_signed_integer("a", offsetof(struct testgatherstructnest0, a),
1693 side_struct_field_sizeof(struct testgatherstructnest0, a), 0, 0,
a82ffcff 1694 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1695 side_field_gather_struct("structnest0", &mystructgatherstructnest1,
d41cb7ee
MD
1696 offsetof(struct testgatherstructnest0, nest),
1697 sizeof(struct testgatherstructnest1),
67337c4a
MD
1698 SIDE_TYPE_GATHER_ACCESS_DIRECT),
1699 side_field_gather_array("nestarray",
1700 side_elem(
1701 side_type_gather_struct(&mystructgatherstructnest1,
dd7947bf 1702 0,
d41cb7ee 1703 sizeof(struct testgatherstructnest1),
a82ffcff 1704 SIDE_TYPE_GATHER_ACCESS_DIRECT)
dd7947bf
MD
1705 ),
1706 2,
d41cb7ee 1707 offsetof(struct testgatherstructnest0, nestarray),
a82ffcff
MD
1708 SIDE_TYPE_GATHER_ACCESS_DIRECT),
1709 )
dd7947bf
MD
1710);
1711
67337c4a
MD
1712side_static_event(my_provider_event_gatherstructnest,
1713 "myprovider", "myeventgatherstructnest", SIDE_LOGLEVEL_DEBUG,
1714 side_field_list(
1715 side_field_gather_struct("structgather", &mystructgatherstructnest0, 0,
1716 sizeof(struct testgatherstructnest0), SIDE_TYPE_GATHER_ACCESS_DIRECT),
a82ffcff 1717 )
dd7947bf
MD
1718);
1719
1720static
d41cb7ee 1721void test_gather_structnest(void)
dd7947bf 1722{
67337c4a 1723 side_event_cond(my_provider_event_gatherstructnest) {
d41cb7ee 1724 struct testgatherstructnest0 mystruct = {
dd7947bf
MD
1725 .nest = {
1726 .b = 66,
1727 .c = { 0, 1, 2, 3 },
1728 },
1729 .nestarray = {
1730 [0] = {
1731 .b = 77,
1732 .c = { 11, 12, 13, 14 },
1733 },
1734 [1] = {
1735 .b = 88,
1736 .c = { 15, 16, 17, 18 },
1737 },
1738 },
1739 .a = 55,
1740 };
67337c4a
MD
1741 side_event_call(my_provider_event_gatherstructnest,
1742 side_arg_list(
1743 side_arg_gather_struct(&mystruct),
dd7947bf
MD
1744 )
1745 );
1746 }
1747}
1748
d41cb7ee 1749uint32_t gathervla[] = { 1, 2, 3, 4 };
80429681 1750uint32_t gathervla2[] = { 5, 6, 7, 8, 9 };
65b8734a 1751
d41cb7ee 1752struct testgathervla {
65b8734a
MD
1753 int a;
1754 uint16_t len;
1755 uint32_t *p;
1756};
1757
67337c4a
MD
1758static side_define_struct(mystructgathervla,
1759 side_field_list(
1760 side_field_gather_signed_integer("a", offsetof(struct testgathervla, a),
1761 side_struct_field_sizeof(struct testgathervla, a), 0, 0,
a82ffcff 1762 SIDE_TYPE_GATHER_ACCESS_DIRECT
65b8734a 1763 ),
67337c4a 1764 side_field_gather_vla("nestvla",
a82ffcff 1765 side_elem(side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
d41cb7ee 1766 offsetof(struct testgathervla, p),
67337c4a
MD
1767 SIDE_TYPE_GATHER_ACCESS_POINTER,
1768 side_length(side_type_gather_unsigned_integer(offsetof(struct testgathervla, len),
a82ffcff 1769 sizeof(uint16_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT))
65b8734a 1770 ),
a82ffcff 1771 )
65b8734a
MD
1772);
1773
67337c4a
MD
1774side_static_event(my_provider_event_gathervla,
1775 "myprovider", "myeventgathervla", SIDE_LOGLEVEL_DEBUG,
1776 side_field_list(
1777 side_field_gather_struct("structgathervla", &mystructgathervla, 0,
1778 sizeof(struct testgathervla), SIDE_TYPE_GATHER_ACCESS_DIRECT),
1779 side_field_gather_vla("vla",
a82ffcff 1780 side_elem(side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
67337c4a 1781 0, SIDE_TYPE_GATHER_ACCESS_DIRECT,
a82ffcff 1782 side_length(side_type_gather_unsigned_integer(0, sizeof(uint16_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT))
80429681 1783 ),
a82ffcff 1784 )
65b8734a
MD
1785);
1786
1787static
d41cb7ee 1788void test_gather_vla(void)
65b8734a 1789{
67337c4a 1790 side_event_cond(my_provider_event_gathervla) {
d41cb7ee 1791 struct testgathervla mystruct = {
65b8734a 1792 .a = 55,
67337c4a 1793 .len = SIDE_ARRAY_SIZE(gathervla),
d41cb7ee 1794 .p = gathervla,
65b8734a 1795 };
80429681 1796 uint16_t vla2_len = 5;
67337c4a
MD
1797 side_event_call(my_provider_event_gathervla,
1798 side_arg_list(
1799 side_arg_gather_struct(&mystruct),
1800 side_arg_gather_vla(gathervla2, &vla2_len),
65b8734a
MD
1801 )
1802 );
1803 }
1804}
1805
d41cb7ee 1806struct testgathervlaflex {
65b8734a
MD
1807 uint8_t len;
1808 uint32_t otherfield;
1809 uint64_t array[];
1810};
1811
67337c4a
MD
1812static side_define_struct(mystructgathervlaflex,
1813 side_field_list(
1814 side_field_gather_vla("vlaflex",
a82ffcff 1815 side_elem(side_type_gather_unsigned_integer(0, sizeof(uint64_t), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
d41cb7ee 1816 offsetof(struct testgathervlaflex, array),
67337c4a
MD
1817 SIDE_TYPE_GATHER_ACCESS_DIRECT,
1818 side_length(side_type_gather_unsigned_integer(offsetof(struct testgathervlaflex, len),
a82ffcff 1819 side_struct_field_sizeof(struct testgathervlaflex, len), 0, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT))
65b8734a 1820 ),
a82ffcff 1821 )
65b8734a
MD
1822);
1823
67337c4a
MD
1824side_static_event(my_provider_event_gathervlaflex,
1825 "myprovider", "myeventgathervlaflex", SIDE_LOGLEVEL_DEBUG,
1826 side_field_list(
1827 side_field_gather_struct("structgathervlaflex", &mystructgathervlaflex, 0,
a82ffcff
MD
1828 sizeof(struct testgathervlaflex), SIDE_TYPE_GATHER_ACCESS_DIRECT)
1829 )
65b8734a
MD
1830);
1831
1832#define VLAFLEXLEN 6
1833static
d41cb7ee 1834void test_gather_vla_flex(void)
65b8734a 1835{
67337c4a 1836 side_event_cond(my_provider_event_gathervlaflex) {
358281a1 1837 struct testgathervlaflex *mystruct =
150b5c1d 1838 (struct testgathervlaflex *) malloc(sizeof(*mystruct) + VLAFLEXLEN * sizeof(uint64_t));
65b8734a
MD
1839
1840 mystruct->len = VLAFLEXLEN;
1841 mystruct->otherfield = 0;
1842 mystruct->array[0] = 1;
1843 mystruct->array[1] = 2;
1844 mystruct->array[2] = 3;
1845 mystruct->array[3] = 4;
1846 mystruct->array[4] = 5;
1847 mystruct->array[5] = 6;
67337c4a
MD
1848 side_event_call(my_provider_event_gathervlaflex,
1849 side_arg_list(
1850 side_arg_gather_struct(mystruct),
65b8734a
MD
1851 )
1852 );
1853 free(mystruct);
1854 }
1855}
1856
67337c4a
MD
1857side_static_event(my_provider_event_gatherbyte,
1858 "myprovider", "myeventgatherbyte", SIDE_LOGLEVEL_DEBUG,
1859 side_field_list(
a82ffcff 1860 side_field_gather_byte("byte", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1861 side_field_gather_array("array",
a82ffcff
MD
1862 side_elem(side_type_gather_byte(0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
1863 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT
d69918cc 1864 ),
a82ffcff 1865 )
d69918cc
MD
1866);
1867
1868static
1869void test_gather_byte(void)
1870{
67337c4a 1871 side_event_cond(my_provider_event_gatherbyte) {
d69918cc
MD
1872 uint8_t v = 0x44;
1873 uint8_t array[3] = { 0x1, 0x2, 0x3 };
1874
67337c4a
MD
1875 side_event_call(my_provider_event_gatherbyte,
1876 side_arg_list(
1877 side_arg_gather_byte(&v),
1878 side_arg_gather_array(array),
d69918cc
MD
1879 )
1880 );
1881 }
1882}
1883
8ad2f385
MD
1884#define ARRAYBOOLLEN 4
1885static bool arraybool[ARRAYBOOLLEN] = { false, true, false, true };
1886
67337c4a
MD
1887side_static_event(my_provider_event_gatherbool,
1888 "myprovider", "myeventgatherbool", SIDE_LOGLEVEL_DEBUG,
1889 side_field_list(
1890 side_field_gather_bool("v1_true", 0, sizeof(bool), 0, 0,
a82ffcff 1891 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1892 side_field_gather_bool("v2_false", 0, sizeof(bool), 0, 0,
a82ffcff 1893 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1894 side_field_gather_bool("v3_true", 0, sizeof(uint16_t), 1, 1,
a82ffcff 1895 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1896 side_field_gather_bool("v4_false", 0, sizeof(uint16_t), 1, 1,
a82ffcff 1897 SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a
MD
1898 side_field_gather_array("arraybool",
1899 side_elem(side_type_gather_bool(0, sizeof(bool), 0, 0,
a82ffcff
MD
1900 SIDE_TYPE_GATHER_ACCESS_DIRECT)),
1901 ARRAYBOOLLEN, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT
8ad2f385 1902 ),
a82ffcff 1903 )
8ad2f385
MD
1904);
1905
1906static
1907void test_gather_bool(void)
1908{
67337c4a 1909 side_event_cond(my_provider_event_structgatherarray) {
8ad2f385
MD
1910 bool v1 = true;
1911 bool v2 = false;
1912 uint16_t v3 = 1U << 1;
1913 uint16_t v4 = 1U << 2;
1914
67337c4a
MD
1915 side_event_call(my_provider_event_gatherbool,
1916 side_arg_list(
1917 side_arg_gather_bool(&v1),
1918 side_arg_gather_bool(&v2),
1919 side_arg_gather_bool(&v3),
1920 side_arg_gather_bool(&v4),
1921 side_arg_gather_array(arraybool),
8ad2f385
MD
1922 )
1923 );
1924 }
1925}
1926
67337c4a
MD
1927side_static_event(my_provider_event_gatherpointer,
1928 "myprovider", "myeventgatherpointer", SIDE_LOGLEVEL_DEBUG,
1929 side_field_list(
a82ffcff 1930 side_field_gather_pointer("ptr", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 1931 side_field_gather_array("array",
a82ffcff
MD
1932 side_elem(side_type_gather_pointer(0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
1933 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT
4e1b0e0e 1934 ),
a82ffcff 1935 )
4e1b0e0e
MD
1936);
1937
1938static
1939void test_gather_pointer(void)
1940{
67337c4a 1941 side_event_cond(my_provider_event_structgatherarray) {
4e1b0e0e
MD
1942 void *v = (void *)0x44;
1943 void *array[3] = { (void *)0x1, (void *)0x2, (void *)0x3 };
1944
67337c4a
MD
1945 side_event_call(my_provider_event_gatherpointer,
1946 side_arg_list(
1947 side_arg_gather_pointer(&v),
1948 side_arg_gather_array(array),
4e1b0e0e
MD
1949 )
1950 );
1951 }
1952}
0519cb86 1953
67337c4a
MD
1954static side_define_enum(myenumgather,
1955 side_enum_mapping_list(
1956 side_enum_mapping_range("one-ten", 1, 10),
1957 side_enum_mapping_range("100-200", 100, 200),
1958 side_enum_mapping_value("200", 200),
1959 side_enum_mapping_value("300", 300),
a82ffcff 1960 )
0519cb86
MD
1961);
1962
67337c4a
MD
1963side_static_event(my_provider_event_enum_gather, "myprovider", "myeventenumgather", SIDE_LOGLEVEL_DEBUG,
1964 side_field_list(
1965 side_field_gather_enum("5", &myenumgather,
1966 side_elem(
1967 side_type_gather_unsigned_integer(0, sizeof(uint32_t), 0, 0,
a82ffcff 1968 SIDE_TYPE_GATHER_ACCESS_DIRECT)
0519cb86
MD
1969 )
1970 ),
67337c4a
MD
1971 side_field_gather_enum("400", &myenumgather,
1972 side_elem(
1973 side_type_gather_unsigned_integer(0, sizeof(uint64_t), 0, 0,
a82ffcff 1974 SIDE_TYPE_GATHER_ACCESS_DIRECT)
0519cb86
MD
1975 )
1976 ),
67337c4a
MD
1977 side_field_gather_enum("200", &myenumgather,
1978 side_elem(
1979 side_type_gather_unsigned_integer(0, sizeof(uint8_t), 0, 0,
a82ffcff 1980 SIDE_TYPE_GATHER_ACCESS_DIRECT)
0519cb86
MD
1981 )
1982 ),
67337c4a
MD
1983 side_field_gather_enum("-100", &myenumgather,
1984 side_elem(
1985 side_type_gather_signed_integer(0, sizeof(int8_t), 0, 0,
a82ffcff 1986 SIDE_TYPE_GATHER_ACCESS_DIRECT)
0519cb86
MD
1987 )
1988 ),
67337c4a
MD
1989 side_field_gather_enum("6_be", &myenumgather,
1990 side_elem(
1991 side_type_gather_unsigned_integer_be(0, sizeof(uint32_t), 0, 0,
a82ffcff 1992 SIDE_TYPE_GATHER_ACCESS_DIRECT)
0519cb86
MD
1993 )
1994 ),
67337c4a
MD
1995 side_field_gather_enum("6_le", &myenumgather,
1996 side_elem(
1997 side_type_gather_unsigned_integer_le(0, sizeof(uint32_t), 0, 0,
a82ffcff 1998 SIDE_TYPE_GATHER_ACCESS_DIRECT)
0519cb86
MD
1999 )
2000 ),
a82ffcff 2001 )
0519cb86
MD
2002);
2003
2004static
2005void test_gather_enum(void)
2006{
2007 uint32_t v1 = 5;
2008 uint64_t v2 = 400;
2009 uint8_t v3 = 200;
2010 int8_t v4 = -100;
67337c4a
MD
2011#if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
2012 uint32_t v5 = side_bswap_32(6);
0519cb86
MD
2013 uint32_t v6 = 6;
2014#else
2015 uint32_t v5 = 6;
67337c4a 2016 uint32_t v6 = side_bswap_32(6);
0519cb86
MD
2017#endif
2018
67337c4a
MD
2019 side_event(my_provider_event_enum_gather,
2020 side_arg_list(
2021 side_arg_gather_integer(&v1),
2022 side_arg_gather_integer(&v2),
2023 side_arg_gather_integer(&v3),
2024 side_arg_gather_integer(&v4),
2025 side_arg_gather_integer(&v5),
2026 side_arg_gather_integer(&v6),
0519cb86
MD
2027 )
2028 );
2029}
2030
67337c4a
MD
2031side_static_event(my_provider_event_gatherstring,
2032 "myprovider", "myeventgatherstring", SIDE_LOGLEVEL_DEBUG,
2033 side_field_list(
a82ffcff 2034 side_field_gather_string("string", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT),
67337c4a 2035 side_field_gather_array("arrayptr",
a82ffcff
MD
2036 side_elem(side_type_gather_string(0, SIDE_TYPE_GATHER_ACCESS_POINTER)),
2037 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT
7d34edfc 2038 ),
67337c4a 2039 side_field_gather_array("array",
a82ffcff
MD
2040 side_elem(side_type_gather_string(0, SIDE_TYPE_GATHER_ACCESS_DIRECT)),
2041 3, 0, SIDE_TYPE_GATHER_ACCESS_DIRECT
7d34edfc 2042 ),
a82ffcff 2043 )
7d34edfc
MD
2044);
2045
2046static
2047void test_gather_string(void)
2048{
67337c4a 2049 side_event_cond(my_provider_event_gatherstring) {
9365e936
MJ
2050 const char *str1 = "abcdef";
2051 const char *ptrarray[3] = {
7d34edfc
MD
2052 "abc",
2053 "def",
2054 "ghi",
2055 };
2056 char flatarray[] = { 'a', 'b', '\0', 'c', 'd', '\0', 'e', 'f', '\0' };
2057
67337c4a
MD
2058 side_event_call(my_provider_event_gatherstring,
2059 side_arg_list(
2060 side_arg_gather_string(str1),
2061 side_arg_gather_array(ptrarray),
2062 side_arg_gather_array(flatarray),
7d34edfc
MD
2063 )
2064 );
2065 }
2066}
2067
67337c4a
MD
2068side_static_event(my_provider_event_str_utf, "myprovider", "myevent_str_utf", SIDE_LOGLEVEL_DEBUG,
2069 side_field_list(
a82ffcff
MD
2070 side_field_string("utf8"),
2071 side_field_string32("utf32"),
2072 side_field_string16("utf16"),
2073 side_field_string32_le("utf32_le"),
2074 side_field_string16_le("utf16_le"),
2075 side_field_string32_be("utf32_be"),
2076 side_field_string16_be("utf16_be"),
67337c4a 2077 side_field_dynamic("dynamic_utf32"),
a82ffcff
MD
2078 side_field_gather_string32("gather_utf32", 0, SIDE_TYPE_GATHER_ACCESS_DIRECT),
2079 )
52990f65
MD
2080);
2081
2082static
2083void test_string_utf(void)
2084{
2085 /*
2086 * Character '®' is:
2087 * UTF-8: \c2 \ae
2088 * UTF-16: U+00ae
2089 * UTF-32: U+000000ae
2090 */
2091 uint8_t str8[] = { 0xc2, 0xae, 'a', 'b', 'c', 0 };
2092 uint32_t str32[] = { 0x000000ae, 'a', 'b', 'c', 0 };
2093 uint16_t str16[] = { 0x00ae, 'a', 'b', 'c', 0 };
67337c4a 2094#if SIDE_BYTE_ORDER == SIDE_LITTLE_ENDIAN
52990f65
MD
2095 uint32_t str32_le[] = { 0x000000ae, 'a', 'b', 'c', 0 };
2096 uint16_t str16_le[] = { 0x00ae, 'a', 'b', 'c', 0 };
67337c4a
MD
2097 uint32_t str32_be[] = { side_bswap_32(0x000000ae), side_bswap_32('a'), side_bswap_32('b'), side_bswap_32('c'), 0 };
2098 uint16_t str16_be[] = { side_bswap_16(0x00ae), side_bswap_16('a'), side_bswap_16('b'), side_bswap_16('c'), 0 };
52990f65 2099#else
67337c4a
MD
2100 uint32_t str32_le[] = { side_bswap_32(0x000000ae), side_bswap_32('a'), side_bswap_32('b'), side_bswap_32('c'), 0 };
2101 uint16_t str16_le[] = { side_bswap_16(0x00ae), side_bswap_16('a'), side_bswap_16('b'), side_bswap_16('c'), 0 };
52990f65
MD
2102 uint32_t str32_be[] = { 0x000000ae, 'a', 'b', 'c', 0 };
2103 uint16_t str16_be[] = { 0x00ae, 'a', 'b', 'c', 0 };
2104#endif
2105
67337c4a
MD
2106 side_event(my_provider_event_str_utf,
2107 side_arg_list(
2108 side_arg_string(str8),
2109 side_arg_string32(str32),
2110 side_arg_string16(str16),
2111 side_arg_string32(str32_le),
2112 side_arg_string16(str16_le),
2113 side_arg_string32(str32_be),
2114 side_arg_string16(str16_be),
a82ffcff 2115 side_arg_dynamic_string32(str32),
67337c4a 2116 side_arg_gather_string(str32),
52990f65
MD
2117 )
2118 );
2119}
2120
5530345d 2121static side_define_variant(myvariantdef,
a82ffcff 2122 side_type_u32(),
5530345d 2123 side_option_list(
a82ffcff
MD
2124 side_option_range(1, 3, side_type_u16()),
2125 side_option(5, side_type_string()),
2126 )
5530345d
MD
2127);
2128
2129side_static_event(my_provider_event_variant, "myprovider", "myeventvariant", SIDE_LOGLEVEL_DEBUG,
2130 side_field_list(
2131 side_field_variant("variant1", &myvariantdef),
2132 side_field_variant("variant2", &myvariantdef),
a82ffcff
MD
2133 side_field_u8("z"),
2134 )
5530345d
MD
2135);
2136
2137static
2138void test_variant(void)
2139{
2140 side_event_cond(my_provider_event_variant) {
2141 side_arg_define_variant(myvariant1, side_arg_u32(2), side_arg_u16(4));
2142 side_arg_define_variant(myvariant2, side_arg_u32(5), side_arg_string("abc"));
2143
2144 side_event_call(my_provider_event_variant,
2145 side_arg_list(
2146 side_arg_variant(&myvariant1),
2147 side_arg_variant(&myvariant2),
2148 side_arg_u8(55),
2149 )
2150 );
2151 }
2152}
2153
0cbdadb5
MD
2154#ifdef __SIZEOF_INT128__
2155side_static_event(my_provider_event_integer128, "myprovider", "myevent_integer128", SIDE_LOGLEVEL_DEBUG,
2156 side_field_list(
2157 side_field_s128("signed128_base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
2158 side_field_u128("unsigned128_base2", side_attr_list(side_attr("std.integer.base", side_attr_u8(2)))),
2159 side_field_s128("signed128_base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
2160 side_field_u128("unsigned128_base8", side_attr_list(side_attr("std.integer.base", side_attr_u8(8)))),
2161 side_field_s128("signed128_base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
2162 side_field_u128("unsigned128_base10", side_attr_list(side_attr("std.integer.base", side_attr_u8(10)))),
2163 side_field_s128("signed128_base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
2164 side_field_u128("unsigned128_base16", side_attr_list(side_attr("std.integer.base", side_attr_u8(16)))),
2165 )
2166);
2167
2168static
2169void test_integer128(void)
2170{
2171 side_event_cond(my_provider_event_integer128) {
2172 __int128 s_v128 = 0;
2173 unsigned __int128 u_v128;
2174
2175 /* -2^63 - 1 */
2176 s_v128 = INT64_MIN;
2177 s_v128--;
2178 /* Maximum unsigned 128-bit value: 340282366920938463463374607431768211455. */
2179 u_v128 = 0;
2180 u_v128--;
2181 side_event_call(my_provider_event_integer128,
2182 side_arg_list(
2183 side_arg_s128(s_v128),
2184 side_arg_u128(u_v128),
2185 side_arg_s128(s_v128),
2186 side_arg_u128(u_v128),
2187 side_arg_s128(s_v128),
2188 side_arg_u128(u_v128),
2189 side_arg_s128(s_v128),
2190 side_arg_u128(u_v128),
2191 )
2192 );
2193 }
2194 side_event_cond(my_provider_event_integer128) {
2195 __int128 s_v128 = 0;
2196 unsigned __int128 u_v128;
2197
2198 /* Minimum signed 128-bit value: -170141183460469231731687303715884105728 */
2199 s_v128 = 1;
2200 s_v128 <<= 64;
2201 s_v128 <<= 63;
2202 /* Zero. */
2203 u_v128 = 0;
2204 side_event_call(my_provider_event_integer128,
2205 side_arg_list(
2206 side_arg_s128(s_v128),
2207 side_arg_u128(u_v128),
2208 side_arg_s128(s_v128),
2209 side_arg_u128(u_v128),
2210 side_arg_s128(s_v128),
2211 side_arg_u128(u_v128),
2212 side_arg_s128(s_v128),
2213 side_arg_u128(u_v128),
2214 )
2215 );
2216 }
2217 side_event_cond(my_provider_event_integer128) {
2218 __int128 s_v128 = 0;
2219 unsigned __int128 u_v128;
2220
2221 /* Minimum signed 128-bit value + 1: -170141183460469231731687303715884105727 */
2222 s_v128 = 1;
2223 s_v128 <<= 64;
2224 s_v128 <<= 63;
2225 s_v128++;
2226 /* INT64_MAX + 1. */
2227 u_v128 = INT64_MAX; /* 9223372036854775807LL */
2228 u_v128++;
2229 side_event_call(my_provider_event_integer128,
2230 side_arg_list(
2231 side_arg_s128(s_v128),
2232 side_arg_u128(u_v128),
2233 side_arg_s128(s_v128),
2234 side_arg_u128(u_v128),
2235 side_arg_s128(s_v128),
2236 side_arg_u128(u_v128),
2237 side_arg_s128(s_v128),
2238 side_arg_u128(u_v128),
2239 )
2240 );
2241 }
2242}
2243#else
2244static
2245void test_integer128(void)
2246{
2247}
2248#endif
2249
2250
f611d0c3
MD
2251int main()
2252{
2253 test_fields();
89747802
MD
2254 test_event_hidden();
2255 test_event_export();
c7a14585 2256 test_struct_literal();
f611d0c3
MD
2257 test_struct();
2258 test_array();
2259 test_vla();
2260 test_vla_visitor();
cdd6e858 2261 test_vla_visitor_2d();
a2e2357e
MD
2262 test_dynamic_basic_type();
2263 test_dynamic_vla();
465e5e7e 2264 test_dynamic_null();
c208889e
MD
2265 test_dynamic_struct();
2266 test_dynamic_nested_struct();
2267 test_dynamic_vla_struct();
2268 test_dynamic_struct_vla();
948e3e72 2269 test_dynamic_nested_vla();
19fa6aa2 2270 test_variadic();
41c4d119 2271 test_static_variadic();
4f40d951
MD
2272 test_bool();
2273 test_dynamic_bool();
8ceca0cd 2274 test_dynamic_vla_with_visitor();
2b359235 2275 test_dynamic_struct_with_visitor();
65010f43 2276 test_event_user_attribute();
a848763d 2277 test_field_user_attribute();
808bd9bf
MD
2278 test_variadic_attr();
2279 test_variadic_vla_attr();
2280 test_variadic_struct_attr();
fb25b355
MD
2281 test_float();
2282 test_variadic_float();
79f677ba 2283 test_enum();
ea32e5fc 2284 test_enum_bitmap();
7aec0d09 2285 test_blob();
71aa8975 2286 test_fmt_string();
8bdd5c12 2287 test_endian();
1d9c515c 2288 test_base();
d41cb7ee
MD
2289 test_struct_gather();
2290 test_struct_gather_nest_ptr();
2291 test_struct_gather_float();
2292 test_array_gather();
2293 test_gather_structnest();
2294 test_gather_vla();
2295 test_gather_vla_flex();
d69918cc 2296 test_gather_byte();
8ad2f385 2297 test_gather_bool();
4e1b0e0e 2298 test_gather_pointer();
0519cb86 2299 test_gather_enum();
7d34edfc 2300 test_gather_string();
52990f65 2301 test_string_utf();
5530345d 2302 test_variant();
0cbdadb5 2303 test_integer128();
f611d0c3
MD
2304 return 0;
2305}
This page took 0.156096 seconds and 4 git commands to generate.