Implement bool type
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Oct 2022 12:48:01 +0000 (08:48 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 17 Oct 2022 12:48:01 +0000 (08:48 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/trace.h
src/test.c
src/tracer.c

index 0a25887c29a5a0ab162fb03130b7c1a2454bc9a9..51bbf08c28c8fa7158a2ddfdf4a2d1d45f8a1234 100644 (file)
@@ -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) } }
index 8a9b0c898e2ce51ef59a753cf9756f6e6c03b5d3..c6d5afb8c01724ef16c4f63d571bc0e80c1c1a44 100644 (file)
@@ -7,6 +7,7 @@
 #include <inttypes.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <stdbool.h>
 
 #include <side/trace.h>
 #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;
 }
index 10eeb44927cb216841499b50db698b17c7e3a5c6..97b7774d025ce5666353e3e9cb2697a4b678a637 100644 (file)
@@ -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("<NULL TYPE>");
                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;
This page took 0.027204 seconds and 4 git commands to generate.