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