Add binary blob static type
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 21 Oct 2022 16:03:46 +0000 (12:03 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Fri, 21 Oct 2022 16:03:46 +0000 (12:03 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/side/trace.h
src/test.c
src/tracer.c

index 623a854190dcf173c65c3de9c032472a64f91e61..3b1283dce92b7a69143765f1c8205765075f19b1 100644 (file)
@@ -40,6 +40,7 @@ enum side_type {
        SIDE_TYPE_S16,
        SIDE_TYPE_S32,
        SIDE_TYPE_S64,
+       SIDE_TYPE_BLOB,
 
        SIDE_TYPE_ENUM_U8,
        SIDE_TYPE_ENUM_U16,
@@ -75,6 +76,7 @@ enum side_type {
        SIDE_TYPE_ARRAY_S16,
        SIDE_TYPE_ARRAY_S32,
        SIDE_TYPE_ARRAY_S64,
+       SIDE_TYPE_ARRAY_BLOB,
 
        SIDE_TYPE_VLA_U8,
        SIDE_TYPE_VLA_U16,
@@ -84,6 +86,7 @@ enum side_type {
        SIDE_TYPE_VLA_S16,
        SIDE_TYPE_VLA_S32,
        SIDE_TYPE_VLA_S64,
+       SIDE_TYPE_VLA_BLOB,
 
        SIDE_TYPE_DYNAMIC,
 };
@@ -342,6 +345,7 @@ struct side_arg_vec {
                int16_t side_s16;
                int32_t side_s32;
                int64_t side_s64;
+               uint8_t side_blob;
 
 #if __HAVE_FLOAT16
                _Float16 side_float_binary16;
@@ -424,6 +428,7 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_type_s16(_attr)                           _side_type(SIDE_TYPE_S16, SIDE_PARAM(_attr))
 #define side_type_s32(_attr)                           _side_type(SIDE_TYPE_S32, SIDE_PARAM(_attr))
 #define side_type_s64(_attr)                           _side_type(SIDE_TYPE_S64, SIDE_PARAM(_attr))
+#define side_type_blob(_attr)                          _side_type(SIDE_TYPE_BLOB, SIDE_PARAM(_attr))
 #define side_type_float_binary16(_attr)                        _side_type(SIDE_TYPE_FLOAT_BINARY16, SIDE_PARAM(_attr))
 #define side_type_float_binary32(_attr)                        _side_type(SIDE_TYPE_FLOAT_BINARY32, SIDE_PARAM(_attr))
 #define side_type_float_binary64(_attr)                        _side_type(SIDE_TYPE_FLOAT_BINARY64, SIDE_PARAM(_attr))
@@ -446,6 +451,7 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_field_s16(_name, _attr)                   _side_field(_name, side_type_s16(SIDE_PARAM(_attr)))
 #define side_field_s32(_name, _attr)                   _side_field(_name, side_type_s32(SIDE_PARAM(_attr)))
 #define side_field_s64(_name, _attr)                   _side_field(_name, side_type_s64(SIDE_PARAM(_attr)))
+#define side_field_blob(_name, _attr)                  _side_field(_name, side_type_blob(SIDE_PARAM(_attr)))
 #define side_field_float_binary16(_name, _attr)                _side_field(_name, side_type_float_binary16(SIDE_PARAM(_attr)))
 #define side_field_float_binary32(_name, _attr)                _side_field(_name, side_type_float_binary32(SIDE_PARAM(_attr)))
 #define side_field_float_binary64(_name, _attr)                _side_field(_name, side_type_float_binary64(SIDE_PARAM(_attr)))
@@ -577,6 +583,7 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_arg_s16(val)              { .type = SIDE_TYPE_S16, .u = { .side_s16 = (val) } }
 #define side_arg_s32(val)              { .type = SIDE_TYPE_S32, .u = { .side_s32 = (val) } }
 #define side_arg_s64(val)              { .type = SIDE_TYPE_S64, .u = { .side_s64 = (val) } }
+#define side_arg_blob(val)             { .type = SIDE_TYPE_BLOB, .u = { .side_blob = (val) } }
 #define side_arg_enum_u8(val)          { .type = SIDE_TYPE_ENUM_U8, .u = { .side_u8 = (val) } }
 #define side_arg_enum_u16(val)         { .type = SIDE_TYPE_ENUM_U16, .u = { .side_u16 = (val) } }
 #define side_arg_enum_u32(val)         { .type = SIDE_TYPE_ENUM_U32, .u = { .side_u32 = (val) } }
@@ -608,6 +615,7 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_arg_array_s16(_ptr)       { .type = SIDE_TYPE_ARRAY_S16, .u = { .side_array_fixint  = (_ptr) } }
 #define side_arg_array_s32(_ptr)       { .type = SIDE_TYPE_ARRAY_S32, .u = { .side_array_fixint = (_ptr) } }
 #define side_arg_array_s64(_ptr)       { .type = SIDE_TYPE_ARRAY_S64, .u = { .side_array_fixint = (_ptr) } }
+#define side_arg_array_blob(_ptr)      { .type = SIDE_TYPE_ARRAY_BLOB, .u = { .side_array_fixint = (_ptr) } }
 
 #define side_arg_vla_u8(_ptr, _length) { .type = SIDE_TYPE_VLA_U8, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } }
 #define side_arg_vla_u16(_ptr, _length)        { .type = SIDE_TYPE_VLA_U16, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
@@ -617,6 +625,7 @@ struct side_tracer_dynamic_vla_visitor_ctx {
 #define side_arg_vla_s16(_ptr, _length)        { .type = SIDE_TYPE_VLA_S16, .u = { .side_vla_fixint  = { .p = (_ptr), .length = (_length) } } }
 #define side_arg_vla_s32(_ptr, _length)        { .type = SIDE_TYPE_VLA_S32, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
 #define side_arg_vla_s64(_ptr, _length)        { .type = SIDE_TYPE_VLA_S64, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
+#define side_arg_vla_blob(_ptr, _length) { .type = SIDE_TYPE_VLA_BLOB, .u = { .side_vla_fixint = { .p = (_ptr), .length = (_length) } } }
 
 #define side_arg_dynamic(dynamic_arg_type) \
        { \
index 5c301c541d996525acc09c7874635a4a5a3003a7..bfa30eecf5ac697c28d7bb528f08e3bd6fa3ffd3 100644 (file)
@@ -1000,6 +1000,34 @@ void test_enum_bitmap(void)
        );
 }
 
+static uint8_t blob_fixint[] = { 0x55, 0x44, 0x33, 0x22, 0x11 };
+
+static side_define_event(my_provider_event_blob, "myprovider", "myeventblob", SIDE_LOGLEVEL_DEBUG,
+       side_field_list(
+               side_field_blob("blobfield", side_attr_list()),
+               side_field_array("arrayblob", side_elem(side_type_blob(side_attr_list())), 3, side_attr_list()),
+               side_field_array("arrayblobfix", side_elem(side_type_blob(side_attr_list())), SIDE_ARRAY_SIZE(blob_fixint), side_attr_list()),
+               side_field_vla("vlablobfix", side_elem(side_type_blob(side_attr_list())), side_attr_list()),
+       ),
+       side_attr_list()
+);
+
+static
+void test_blob(void)
+{
+       my_provider_event_blob.enabled = 1;
+       side_event_cond(&my_provider_event_blob) {
+               side_arg_define_vec(myarray, side_arg_list(side_arg_blob(1), side_arg_blob(2), side_arg_blob(3)));
+               side_event_call(&my_provider_event_blob,
+                       side_arg_list(
+                               side_arg_blob(0x55),
+                               side_arg_array(&myarray),
+                               side_arg_array_blob(blob_fixint),
+                               side_arg_vla_blob(blob_fixint, SIDE_ARRAY_SIZE(blob_fixint)),
+                       )
+               );
+       }
+}
 
 int main()
 {
@@ -1034,5 +1062,6 @@ int main()
        test_variadic_float();
        test_enum();
        test_enum_bitmap();
+       test_blob();
        return 0;
 }
index 62555d7c1e33a4d27b0be6ddbea60485939c7237..9a90de8c407a62fbddd7826aeae84c7671cd57fa 100644 (file)
@@ -184,6 +184,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru
        case SIDE_TYPE_ARRAY_S16:
        case SIDE_TYPE_ARRAY_S32:
        case SIDE_TYPE_ARRAY_S64:
+       case SIDE_TYPE_ARRAY_BLOB:
                if (type_desc->type != SIDE_TYPE_ARRAY) {
                        printf("ERROR: type mismatch between description and arguments\n");
                        abort();
@@ -197,6 +198,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru
        case SIDE_TYPE_VLA_S16:
        case SIDE_TYPE_VLA_S32:
        case SIDE_TYPE_VLA_S64:
+       case SIDE_TYPE_VLA_BLOB:
                if (type_desc->type != SIDE_TYPE_VLA) {
                        printf("ERROR: type mismatch between description and arguments\n");
                        abort();
@@ -242,6 +244,9 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru
        case SIDE_TYPE_S64:
                printf("%" PRId64, item->u.side_s64);
                break;
+       case SIDE_TYPE_BLOB:
+               printf("0x%" PRIx8, item->u.side_blob);
+               break;
 
        case SIDE_TYPE_ENUM_U8:
                print_enum(type_desc->u.side_enum_mappings,
@@ -348,6 +353,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru
        case SIDE_TYPE_ARRAY_S16:
        case SIDE_TYPE_ARRAY_S32:
        case SIDE_TYPE_ARRAY_S64:
+       case SIDE_TYPE_ARRAY_BLOB:
                tracer_print_array_fixint(type_desc, item);
                break;
        case SIDE_TYPE_VLA_U8:
@@ -358,6 +364,7 @@ void tracer_print_type(const struct side_type_description *type_desc, const stru
        case SIDE_TYPE_VLA_S16:
        case SIDE_TYPE_VLA_S32:
        case SIDE_TYPE_VLA_S64:
+       case SIDE_TYPE_VLA_BLOB:
                tracer_print_vla_fixint(type_desc, item);
                break;
        case SIDE_TYPE_DYNAMIC:
@@ -512,6 +519,10 @@ void tracer_print_array_fixint(const struct side_type_description *type_desc, co
                if (elem_type->type != SIDE_TYPE_S64)
                        goto type_error;
                break;
+       case SIDE_TYPE_ARRAY_BLOB:
+               if (elem_type->type != SIDE_TYPE_BLOB)
+                       goto type_error;
+               break;
        default:
                goto type_error;
        }
@@ -548,6 +559,9 @@ void tracer_print_array_fixint(const struct side_type_description *type_desc, co
                case SIDE_TYPE_S64:
                        sav_elem.u.side_s64 = ((const int64_t *) p)[i];
                        break;
+               case SIDE_TYPE_BLOB:
+                       sav_elem.u.side_blob = ((const uint8_t *) p)[i];
+                       break;
 
                default:
                        printf("ERROR: Unexpected type\n");
@@ -606,6 +620,10 @@ void tracer_print_vla_fixint(const struct side_type_description *type_desc, cons
                if (elem_type->type != SIDE_TYPE_S64)
                        goto type_error;
                break;
+       case SIDE_TYPE_VLA_BLOB:
+               if (elem_type->type != SIDE_TYPE_BLOB)
+                       goto type_error;
+               break;
        default:
                goto type_error;
        }
@@ -642,6 +660,9 @@ void tracer_print_vla_fixint(const struct side_type_description *type_desc, cons
                case SIDE_TYPE_S64:
                        sav_elem.u.side_s64 = ((const int64_t *) p)[i];
                        break;
+               case SIDE_TYPE_BLOB:
+                       sav_elem.u.side_blob = ((const uint8_t *) p)[i];
+                       break;
 
                default:
                        printf("ERROR: Unexpected type\n");
This page took 0.040679 seconds and 4 git commands to generate.