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