From 4f40d951e7dd25424b9b9346b5644126c5960937 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 17 Oct 2022 08:48:01 -0400 Subject: [PATCH] Implement bool type Signed-off-by: Mathieu Desnoyers --- include/side/trace.h | 10 ++++++++ src/test.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/tracer.c | 6 +++++ 3 files changed, 76 insertions(+) diff --git a/include/side/trace.h b/include/side/trace.h index 0a25887..51bbf08 100644 --- a/include/side/trace.h +++ b/include/side/trace.h @@ -25,6 +25,8 @@ struct side_tracer_dynamic_struct_visitor_ctx; struct side_tracer_dynamic_vla_visitor_ctx; enum side_type { + SIDE_TYPE_BOOL, + SIDE_TYPE_U8, SIDE_TYPE_U16, SIDE_TYPE_U32, @@ -65,6 +67,8 @@ enum side_type { enum side_dynamic_type { SIDE_DYNAMIC_TYPE_NULL, + SIDE_DYNAMIC_TYPE_BOOL, + SIDE_DYNAMIC_TYPE_U8, SIDE_DYNAMIC_TYPE_U16, SIDE_DYNAMIC_TYPE_U32, @@ -154,6 +158,8 @@ struct side_arg_dynamic_vec_vla { struct side_arg_dynamic_vec { uint32_t dynamic_type; /* enum side_dynamic_type */ union { + uint8_t side_bool; + uint8_t side_u8; uint16_t side_u16; uint32_t side_u32; @@ -193,6 +199,8 @@ struct side_arg_dynamic_event_struct { struct side_arg_vec { enum side_type type; union { + uint8_t side_bool; + uint8_t side_u8; uint16_t side_u16; uint32_t side_u32; @@ -325,6 +333,7 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_field_list(...) \ SIDE_COMPOUND_LITERAL(const struct side_event_field, __VA_ARGS__) +#define side_arg_bool(val) { .type = SIDE_TYPE_BOOL, .u = { .side_bool = !!(val) } } #define side_arg_u8(val) { .type = SIDE_TYPE_U8, .u = { .side_u8 = (val) } } #define side_arg_u16(val) { .type = SIDE_TYPE_U16, .u = { .side_u16 = (val) } } #define side_arg_u32(val) { .type = SIDE_TYPE_U32, .u = { .side_u32 = (val) } } @@ -367,6 +376,7 @@ struct side_tracer_dynamic_vla_visitor_ctx { #define side_arg_dynamic_null(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_NULL } +#define side_arg_dynamic_bool(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_BOOL, .u = { .side_bool = !!(val) } } #define side_arg_dynamic_u8(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U8, .u = { .side_u8 = (val) } } #define side_arg_dynamic_u16(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U16, .u = { .side_u16 = (val) } } #define side_arg_dynamic_u32(val) { .dynamic_type = SIDE_DYNAMIC_TYPE_U32, .u = { .side_u32 = (val) } } diff --git a/src/test.c b/src/test.c index 8a9b0c8..c6d5afb 100644 --- a/src/test.c +++ b/src/test.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "tracer.h" @@ -485,6 +486,63 @@ void test_static_variadic(void) ); } +static side_define_event(my_provider_event_bool, "myprovider", "myeventbool", SIDE_LOGLEVEL_DEBUG, + side_field_list( + side_field("a_false", SIDE_TYPE_BOOL), + side_field("b_true", SIDE_TYPE_BOOL), + side_field("c_true", SIDE_TYPE_BOOL), + side_field("d_true", SIDE_TYPE_BOOL), + side_field("e_true", SIDE_TYPE_BOOL), + side_field("f_false", SIDE_TYPE_BOOL), + side_field("g_true", SIDE_TYPE_BOOL), + ) +); + +static +void test_bool(void) +{ + uint32_t a = 0; + uint32_t b = 1; + uint64_t c = 0x12345678; + int16_t d = -32768; + bool e = true; + bool f = false; + uint32_t g = 256; + + my_provider_event_bool.enabled = 1; + side_event(&my_provider_event_bool, + side_arg_list( + side_arg_bool(a), + side_arg_bool(b), + side_arg_bool(c), + side_arg_bool(d), + side_arg_bool(e), + side_arg_bool(f), + side_arg_bool(g), + ) + ); +} + +static side_define_event(my_provider_event_dynamic_bool, + "myprovider", "mydynamicbool", SIDE_LOGLEVEL_DEBUG, + side_field_list() +); + +static +void test_dynamic_bool(void) +{ + my_provider_event_dynamic_bool.enabled = 1; + side_event_variadic(&my_provider_event_dynamic_bool, + side_arg_list(), + side_arg_list( + side_arg_dynamic_field("a_true", side_arg_dynamic_bool(55)), + side_arg_dynamic_field("b_true", side_arg_dynamic_bool(-4)), + side_arg_dynamic_field("c_false", side_arg_dynamic_bool(0)), + side_arg_dynamic_field("d_true", side_arg_dynamic_bool(256)), + ) + ); +} + int main() { test_fields(); @@ -505,5 +563,7 @@ int main() test_dynamic_nested_vla(); test_variadic(); test_static_variadic(); + test_bool(); + test_dynamic_bool(); return 0; } diff --git a/src/tracer.c b/src/tracer.c index 10eeb44..97b7774 100644 --- a/src/tracer.c +++ b/src/tracer.c @@ -64,6 +64,9 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru break; } switch (item->type) { + case SIDE_TYPE_BOOL: + printf("%s", item->u.side_bool ? "true" : "false"); + break; case SIDE_TYPE_U8: printf("%" PRIu8, item->u.side_u8); break; @@ -471,6 +474,9 @@ void tracer_print_dynamic(const struct side_arg_dynamic_vec *item) case SIDE_DYNAMIC_TYPE_NULL: printf(""); break; + case SIDE_DYNAMIC_TYPE_BOOL: + printf("%s", item->u.side_bool ? "true" : "false"); + break; case SIDE_DYNAMIC_TYPE_U8: printf("%" PRIu8, item->u.side_u8); break; -- 2.34.1