lib: split real FC/field into single and double prec FC/field
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 26 Sep 2019 20:13:22 +0000 (16:13 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Mon, 30 Sep 2019 12:28:49 +0000 (08:28 -0400)
This commit removes the BT_FIELD_CLASS_TYPE_REAL field class and the
corresponding fields and adds BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL
and BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL field classes and their
fields.

This seems like cleaner way to express the different types of floating
point representations and while keeping the door open for other
(smaller and/or larger) representations.

The test_field.py testcases for `_SinglePrecisionRealField` are
implemented using a default value of 52.0 which can be converted from
Python float(double precision) to C float(single precision) without loss
of precision. It's the best way I found to support the
`_TestNumericField` test cases without scattering specific conditions
for `_SinglePrecisionRealField`

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I6057e1626b71fee5dce1c374bda3faf3451b5fef
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2099
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
31 files changed:
include/babeltrace2/trace-ir/field-class-const.h
include/babeltrace2/trace-ir/field-class.h
include/babeltrace2/trace-ir/field-const.h
include/babeltrace2/trace-ir/field.h
src/bindings/python/bt2/bt2/__init__.py
src/bindings/python/bt2/bt2/field.py
src/bindings/python/bt2/bt2/field_class.py
src/bindings/python/bt2/bt2/trace_class.py
src/common/common.h
src/lib/lib-logging.c
src/lib/trace-ir/field-class.c
src/lib/trace-ir/field-class.h
src/lib/trace-ir/field.c
src/plugins/ctf/common/metadata/ctf-meta-translate.c
src/plugins/ctf/common/msg-iter/msg-iter.c
src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c
src/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c
src/plugins/lttng-utils/debug-info/trace-ir-data-copy.c
src/plugins/lttng-utils/debug-info/trace-ir-metadata-field-class-copy.c
src/plugins/text/details/write.c
src/plugins/text/pretty/print.c
tests/bindings/python/bt2/test_event.py
tests/bindings/python/bt2/test_field.py
tests/bindings/python/bt2/test_field_class.py
tests/bindings/python/bt2/test_package.py
tests/bindings/python/bt2/test_packet.py
tests/data/plugins/sink.ctf.fs/succeed/trace-double.expect
tests/data/plugins/sink.ctf.fs/succeed/trace-float.expect
tests/data/plugins/src.ctf.fs/succeed/trace-session-rotation.expect

index 777e07b0f060c69b518ba92ed9beaca9dd3f1f6a..e7541848bed4248b5639ddc1ee9a360f33160866 100644 (file)
@@ -43,15 +43,16 @@ typedef enum bt_field_class_type {
        BT_FIELD_CLASS_TYPE_SIGNED_INTEGER                      = 3,
        BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION                = 4,
        BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION                  = 5,
-       BT_FIELD_CLASS_TYPE_REAL                                = 6,
-       BT_FIELD_CLASS_TYPE_STRING                              = 7,
-       BT_FIELD_CLASS_TYPE_STRUCTURE                           = 8,
-       BT_FIELD_CLASS_TYPE_STATIC_ARRAY                        = 9,
-       BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY                       = 10,
-       BT_FIELD_CLASS_TYPE_OPTION                              = 11,
-       BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR            = 12,
-       BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR      = 13,
-       BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR        = 14,
+       BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL               = 6,
+       BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL               = 7,
+       BT_FIELD_CLASS_TYPE_STRING                              = 8,
+       BT_FIELD_CLASS_TYPE_STRUCTURE                           = 9,
+       BT_FIELD_CLASS_TYPE_STATIC_ARRAY                        = 10,
+       BT_FIELD_CLASS_TYPE_DYNAMIC_ARRAY                       = 11,
+       BT_FIELD_CLASS_TYPE_OPTION                              = 12,
+       BT_FIELD_CLASS_TYPE_VARIANT_WITHOUT_SELECTOR            = 13,
+       BT_FIELD_CLASS_TYPE_VARIANT_WITH_UNSIGNED_SELECTOR      = 14,
+       BT_FIELD_CLASS_TYPE_VARIANT_WITH_SIGNED_SELECTOR        = 15,
 } bt_field_class_type;
 
 typedef enum bt_field_class_integer_preferred_display_base {
@@ -77,9 +78,6 @@ extern bt_field_class_integer_preferred_display_base
 bt_field_class_integer_get_preferred_display_base(
                const bt_field_class *field_class);
 
-extern bt_bool bt_field_class_real_is_single_precision(
-               const bt_field_class *field_class);
-
 extern uint64_t bt_field_class_enumeration_get_mapping_count(
                const bt_field_class *field_class);
 
index 2881000480fd7dc9ef22b54419d25809513cdc79..9e28a9b2070e9511e3b5bd917b7e000ec9f6950a 100644 (file)
@@ -62,11 +62,11 @@ extern void bt_field_class_integer_set_preferred_display_base(
                bt_field_class *field_class,
                bt_field_class_integer_preferred_display_base base);
 
-extern bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class);
+extern bt_field_class *bt_field_class_real_single_precision_create(
+               bt_trace_class *trace_class);
 
-extern void bt_field_class_real_set_is_single_precision(
-               bt_field_class *field_class,
-               bt_bool is_single_precision);
+extern bt_field_class *bt_field_class_real_double_precision_create(
+               bt_trace_class *trace_class);
 
 extern bt_field_class *bt_field_class_enumeration_unsigned_create(
                bt_trace_class *trace_class);
index dcaf40c17d692dd3db4a05d30f4711899ae02f02..a3902ce25a9da3e305b99f0ec31998c6e55e72e8 100644 (file)
@@ -52,7 +52,9 @@ extern int64_t bt_field_integer_signed_get_value(const bt_field *field);
 extern uint64_t bt_field_integer_unsigned_get_value(
                const bt_field *field);
 
-extern double bt_field_real_get_value(const bt_field *field);
+extern float bt_field_real_single_precision_get_value(const bt_field *field);
+
+extern double bt_field_real_double_precision_get_value(const bt_field *field);
 
 typedef enum bt_field_enumeration_get_mapping_labels_status {
        BT_FIELD_ENUMERATION_GET_MAPPING_LABELS_STATUS_MEMORY_ERROR     = __BT_FUNC_STATUS_MEMORY_ERROR,
index e7419a6ee5935caccb53b77dcc7455d33877359b..341ea719028f5150f7e26d6ad89a11239bbf2ed7 100644 (file)
@@ -48,7 +48,11 @@ extern void bt_field_integer_signed_set_value(bt_field *field,
 extern void bt_field_integer_unsigned_set_value(bt_field *field,
                uint64_t value);
 
-extern void bt_field_real_set_value(bt_field *field, double value);
+extern void bt_field_real_single_precision_set_value(bt_field *field,
+               float value);
+
+extern void bt_field_real_double_precision_set_value(bt_field *field,
+               double value);
 
 typedef enum bt_field_string_set_value_status {
        BT_FIELD_STRING_SET_VALUE_STATUS_MEMORY_ERROR   = __BT_FUNC_STATUS_MEMORY_ERROR,
index 0e4342aa03537c6d57a850d2226f67017b5a7f97..3d102e66208d7bea27200a69fa497c37e6915986 100644 (file)
@@ -49,6 +49,8 @@ from bt2.field import _IntegerField
 from bt2.field import _UnsignedIntegerField
 from bt2.field import _SignedIntegerField
 from bt2.field import _RealField
+from bt2.field import _SinglePrecisionRealField
+from bt2.field import _DoublePrecisionRealField
 from bt2.field import _EnumerationField
 from bt2.field import _UnsignedEnumerationField
 from bt2.field import _SignedEnumerationField
@@ -65,6 +67,8 @@ from bt2.field import _IntegerFieldConst
 from bt2.field import _UnsignedIntegerFieldConst
 from bt2.field import _SignedIntegerFieldConst
 from bt2.field import _RealFieldConst
+from bt2.field import _SinglePrecisionRealFieldConst
+from bt2.field import _DoublePrecisionRealFieldConst
 from bt2.field import _EnumerationFieldConst
 from bt2.field import _UnsignedEnumerationFieldConst
 from bt2.field import _SignedEnumerationFieldConst
index 275d500d6fdd4c11e7a4456b602249c788cb89d3..eb2b63a71a86ae752d763902aa5a05faff5d3664 100644 (file)
@@ -421,17 +421,43 @@ class _RealFieldConst(_NumericFieldConst, numbers.Real):
 
         return float(value)
 
+
+class _SinglePrecisionRealFieldConst(_RealFieldConst):
+    _NAME = 'Const single-precision real'
+
+    @property
+    def _value(self):
+        return native_bt.field_real_single_precision_get_value(self._ptr)
+
+
+class _DoublePrecisionRealFieldConst(_RealFieldConst):
+    _NAME = 'Const double-precision real'
+
     @property
     def _value(self):
-        return native_bt.field_real_get_value(self._ptr)
+        return native_bt.field_real_double_precision_get_value(self._ptr)
 
 
 class _RealField(_RealFieldConst, _NumericField):
     _NAME = 'Real'
 
+
+class _SinglePrecisionRealField(_SinglePrecisionRealFieldConst, _RealField):
+    _NAME = 'Single-precision real'
+
+    def _set_value(self, value):
+        value = self._value_to_float(value)
+        native_bt.field_real_single_precision_set_value(self._ptr, value)
+
+    value = property(fset=_set_value)
+
+
+class _DoublePrecisionRealField(_DoublePrecisionRealFieldConst, _RealField):
+    _NAME = 'Double-precision real'
+
     def _set_value(self, value):
         value = self._value_to_float(value)
-        native_bt.field_real_set_value(self._ptr, value)
+        native_bt.field_real_double_precision_set_value(self._ptr, value)
 
     value = property(fset=_set_value)
 
@@ -901,7 +927,8 @@ _TYPE_ID_TO_CONST_OBJ = {
     native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldConst,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldConst,
     native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldConst,
-    native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldConst,
+    native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldConst,
+    native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldConst,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldConst,
     native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldConst,
     native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldConst,
@@ -919,7 +946,8 @@ _TYPE_ID_TO_OBJ = {
     native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayField,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerField,
     native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerField,
-    native_bt.FIELD_CLASS_TYPE_REAL: _RealField,
+    native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealField,
+    native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealField,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationField,
     native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationField,
     native_bt.FIELD_CLASS_TYPE_STRING: _StringField,
index bad407b41401234cb3c4220a2c867bff270f2e7e..b873a15bb16b8e0f3a5f7e2e1386945fb86e8c64 100644 (file)
@@ -172,23 +172,27 @@ class _SignedIntegerFieldClass(
 
 
 class _RealFieldClassConst(_FieldClassConst):
-    _NAME = 'Const real'
+    pass
 
-    @property
-    def is_single_precision(self):
-        return native_bt.field_class_real_is_single_precision(self._ptr)
+
+class _SinglePrecisionRealFieldClassConst(_RealFieldClassConst):
+    _NAME = 'Const single-precision real'
+
+
+class _DoublePrecisionRealFieldClassConst(_RealFieldClassConst):
+    _NAME = 'Const double-precision real'
 
 
 class _RealFieldClass(_FieldClass, _RealFieldClassConst):
-    _NAME = 'Real'
+    pass
+
+
+class _SinglePrecisionRealFieldClass(_RealFieldClass):
+    _NAME = 'Single-precision real'
 
-    def _is_single_precision(self, is_single_precision):
-        utils._check_bool(is_single_precision)
-        native_bt.field_class_real_set_is_single_precision(
-            self._ptr, is_single_precision
-        )
 
-    _is_single_precision = property(fset=_is_single_precision)
+class _DoublePrecisionRealFieldClass(_RealFieldClass):
+    _NAME = 'Double-precision real'
 
 
 # an enumeration field class mapping does not have a reference count, so
@@ -907,7 +911,8 @@ _FIELD_CLASS_TYPE_TO_CONST_OBJ = {
     native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldClassConst,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClassConst,
     native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClassConst,
-    native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldClassConst,
+    native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldClassConst,
+    native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldClassConst,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldClassConst,
     native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldClassConst,
     native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldClassConst,
@@ -925,7 +930,8 @@ _FIELD_CLASS_TYPE_TO_OBJ = {
     native_bt.FIELD_CLASS_TYPE_BIT_ARRAY: _BitArrayFieldClass,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_INTEGER: _UnsignedIntegerFieldClass,
     native_bt.FIELD_CLASS_TYPE_SIGNED_INTEGER: _SignedIntegerFieldClass,
-    native_bt.FIELD_CLASS_TYPE_REAL: _RealFieldClass,
+    native_bt.FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL: _SinglePrecisionRealFieldClass,
+    native_bt.FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL: _DoublePrecisionRealFieldClass,
     native_bt.FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION: _UnsignedEnumerationFieldClass,
     native_bt.FIELD_CLASS_TYPE_SIGNED_ENUMERATION: _SignedEnumerationFieldClass,
     native_bt.FIELD_CLASS_TYPE_STRING: _StringFieldClass,
index 9146efacb927b7389857ae189ed7baf8ba18ea57..d510a36e1e2fbdddd96e94a5cbfb4f59847d4a52 100644 (file)
@@ -368,13 +368,26 @@ class _TraceClass(_TraceClassConst):
             user_attributes,
         )
 
-    def create_real_field_class(self, is_single_precision=False, user_attributes=None):
-        field_class_ptr = native_bt.field_class_real_create(self._ptr)
-        self._check_field_class_create_status(field_class_ptr, 'real')
+    def create_single_precision_real_field_class(self, user_attributes=None):
+        field_class_ptr = native_bt.field_class_real_single_precision_create(self._ptr)
+        self._check_field_class_create_status(field_class_ptr, 'single-precision real')
 
-        field_class = bt2_field_class._RealFieldClass._create_from_ptr(field_class_ptr)
+        field_class = bt2_field_class._SinglePrecisionRealFieldClass._create_from_ptr(
+            field_class_ptr
+        )
+
+        self._set_field_class_user_attrs(field_class, user_attributes)
+
+        return field_class
+
+    def create_double_precision_real_field_class(self, user_attributes=None):
+        field_class_ptr = native_bt.field_class_real_double_precision_create(self._ptr)
+        self._check_field_class_create_status(field_class_ptr, 'double-precision real')
+
+        field_class = bt2_field_class._DoublePrecisionRealFieldClass._create_from_ptr(
+            field_class_ptr
+        )
 
-        field_class._is_single_precision = is_single_precision
         self._set_field_class_user_attrs(field_class, user_attributes)
 
         return field_class
index 1751f20bd74ad65c47fcb07b1362906f6ac7b7d2..41815454e61b0b6e141746a5cfa1ba57715a0f87 100644 (file)
@@ -421,8 +421,10 @@ const char *bt_common_field_class_type_string(enum bt_field_class_type class_typ
                return "UNSIGNED_INTEGER";
        case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
                return "SIGNED_INTEGER";
-       case BT_FIELD_CLASS_TYPE_REAL:
-               return "REAL";
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               return "SINGLE_PRECISION_REAL";
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               return "DOUBLE_PRECISION_REAL";
        case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
                return "UNSIGNED_ENUMERATION";
        case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
index 461a67d9e25c6e42505703c8269bac4039d28e9e..af30bd2f82c0817b43bf03f1b22bb325df65fc3e 100644 (file)
@@ -207,14 +207,6 @@ static inline void format_field_class(char **buf_ch, bool extended,
                format_integer_field_class(buf_ch, extended, prefix, field_class);
                break;
        }
-       case BT_FIELD_CLASS_TYPE_REAL:
-       {
-               const struct bt_field_class_real *real_fc = (void *) field_class;
-
-               BUF_APPEND(", %sis-single-precision=%d",
-                       PRFIELD(real_fc->is_single_precision));
-               break;
-       }
        case BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION:
        case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
        {
@@ -406,7 +398,8 @@ static inline void format_field(char **buf_ch, bool extended,
                format_field_integer_extended(buf_ch, prefix, field);
                break;
        }
-       case BT_FIELD_CLASS_TYPE_REAL:
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
        {
                const struct bt_field_real *real_field = (const void *) field;
 
index 4dfed4929317822c26734a21906ce146b65d1f3f..ecb827a5fe836bd816730b9a587f2e4c23067d10 100644 (file)
@@ -694,20 +694,22 @@ void destroy_real_field_class(struct bt_object *obj)
        g_free(obj);
 }
 
-struct bt_field_class *bt_field_class_real_create(bt_trace_class *trace_class)
+static
+struct bt_field_class *create_real_field_class(bt_trace_class *trace_class,
+               enum bt_field_class_type type)
 {
        struct bt_field_class_real *real_fc = NULL;
 
        BT_ASSERT_PRE_NON_NULL(trace_class, "Trace class");
-       BT_LOGD_STR("Creating default real field class object.");
+       BT_LOGD("Creating default real field class object: type=%s",
+               bt_common_field_class_type_string(type));
        real_fc = g_new0(struct bt_field_class_real, 1);
        if (!real_fc) {
                BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field class.");
                goto error;
        }
 
-       if (init_field_class((void *) real_fc, BT_FIELD_CLASS_TYPE_REAL,
-                       destroy_real_field_class)) {
+       if (init_field_class((void *) real_fc, type, destroy_real_field_class)) {
                goto error;
        }
 
@@ -721,26 +723,18 @@ end:
        return (void *) real_fc;
 }
 
-bt_bool bt_field_class_real_is_single_precision(const struct bt_field_class *fc)
+struct bt_field_class *bt_field_class_real_single_precision_create(
+       bt_trace_class *trace_class)
 {
-       const struct bt_field_class_real *real_fc = (const void *) fc;
-
-       BT_ASSERT_PRE_DEV_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_DEV_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_REAL, "Field class");
-       return real_fc->is_single_precision;
+       return create_real_field_class(trace_class,
+               BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
 }
 
-void bt_field_class_real_set_is_single_precision(struct bt_field_class *fc,
-               bt_bool is_single_precision)
+struct bt_field_class *bt_field_class_real_double_precision_create(
+       bt_trace_class *trace_class)
 {
-       struct bt_field_class_real *real_fc = (void *) fc;
-
-       BT_ASSERT_PRE_NON_NULL(fc, "Field class");
-       BT_ASSERT_PRE_FC_HAS_ID(fc, BT_FIELD_CLASS_TYPE_REAL, "Field class");
-       BT_ASSERT_PRE_DEV_FC_HOT(fc, "Field class");
-       real_fc->is_single_precision = (bool) is_single_precision;
-       BT_LIB_LOGD("Set real field class's \"is single precision\" property: "
-               "%!+F", fc);
+       return create_real_field_class(trace_class,
+               BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL);
 }
 
 static
index e7eff691ed746619fd377e934d0ea4fda51c24e6..568edaf9ac738a870580b05f28dc0a3ea0b76433 100644 (file)
@@ -244,7 +244,6 @@ struct bt_field_class_enumeration {
 
 struct bt_field_class_real {
        struct bt_field_class common;
-       bool is_single_precision;
 };
 
 struct bt_field_class_string {
index 90dde2e51712ff4c137379b8a9f6aa12fd89d2b8..f10b893ddacbf5b41e5cc9743e7121916eb3b14e 100644 (file)
@@ -163,7 +163,6 @@ struct bt_field *create_string_field(struct bt_field_class *);
 
 static
 struct bt_field *create_structure_field(struct bt_field_class *);
-
 static
 struct bt_field *create_static_array_field(struct bt_field_class *);
 
@@ -184,7 +183,8 @@ struct bt_field *(* const field_create_funcs[])(struct bt_field_class *) = {
        [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]                    = create_integer_field,
        [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION]              = create_integer_field,
        [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]                = create_integer_field,
-       [BT_FIELD_CLASS_TYPE_REAL]                              = create_real_field,
+       [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL]             = create_real_field,
+       [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL]             = create_real_field,
        [BT_FIELD_CLASS_TYPE_STRING]                            = create_string_field,
        [BT_FIELD_CLASS_TYPE_STRUCTURE]                         = create_structure_field,
        [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]                      = create_static_array_field,
@@ -230,7 +230,8 @@ void (* const field_destroy_funcs[])(struct bt_field *) = {
        [BT_FIELD_CLASS_TYPE_SIGNED_INTEGER]                    = destroy_integer_field,
        [BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION]              = destroy_integer_field,
        [BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION]                = destroy_integer_field,
-       [BT_FIELD_CLASS_TYPE_REAL]                              = destroy_real_field,
+       [BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL]             = destroy_real_field,
+       [BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL]             = destroy_real_field,
        [BT_FIELD_CLASS_TYPE_STRING]                            = destroy_string_field,
        [BT_FIELD_CLASS_TYPE_STRUCTURE]                         = destroy_structure_field,
        [BT_FIELD_CLASS_TYPE_STATIC_ARRAY]                      = destroy_array_field,
@@ -724,28 +725,53 @@ void bt_field_integer_unsigned_set_value(struct bt_field *field, uint64_t value)
        bt_field_set_single(field, true);
 }
 
-double bt_field_real_get_value(const struct bt_field *field)
+float bt_field_real_single_precision_get_value(const struct bt_field *field)
+{
+       const struct bt_field_real *real_field = (const void *) field;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
+       return (float) real_field->value;
+}
+
+double bt_field_real_double_precision_get_value(const struct bt_field *field)
 {
        const struct bt_field_real *real_field = (const void *) field;
 
        BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
        BT_ASSERT_PRE_DEV_FIELD_IS_SET(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
+
        return real_field->value;
 }
 
-void bt_field_real_set_value(struct bt_field *field, double value)
+void bt_field_real_single_precision_set_value(struct bt_field *field,
+               float value)
 {
        struct bt_field_real *real_field = (void *) field;
 
        BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
-       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_REAL, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL, "Field");
        BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
-       BT_ASSERT_PRE_DEV(
-               !((struct bt_field_class_real *) field->class)->is_single_precision ||
-               (double) (float) value == value,
-               "Invalid value for a single-precision real number: value=%f, "
-               "%![fc-]+F", value, field->class);
+
+       real_field->value = (double) value;
+       bt_field_set_single(field, true);
+}
+
+void bt_field_real_double_precision_set_value(struct bt_field *field,
+               double value)
+{
+       struct bt_field_real *real_field = (void *) field;
+
+       BT_ASSERT_PRE_DEV_NON_NULL(field, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HAS_CLASS_TYPE(field,
+               BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL, "Field");
+       BT_ASSERT_PRE_DEV_FIELD_HOT(field, "Field");
+
        real_field->value = value;
        bt_field_set_single(field, true);
 }
index 7d0d966acc0fada002887d520aa22f6630bce880..b7f2cbdb1a0bb44c689fafdc1a3c1e69fbf9a744 100644 (file)
@@ -134,13 +134,12 @@ bt_field_class *ctf_field_class_float_to_ir(struct ctx *ctx,
 {
        bt_field_class *ir_fc;
 
-       ir_fc = bt_field_class_real_create(ctx->ir_tc);
-       BT_ASSERT(ir_fc);
-
        if (fc->base.size == 32) {
-               bt_field_class_real_set_is_single_precision(ir_fc,
-                       BT_TRUE);
+               ir_fc = bt_field_class_real_single_precision_create(ctx->ir_tc);
+       } else {
+               ir_fc = bt_field_class_real_double_precision_create(ctx->ir_tc);
        }
+       BT_ASSERT(ir_fc);
 
        return ir_fc;
 }
index 20ca19de04e6ebda4950975e0dd7b943e7548e39..dd350c75ecfe4bb52f7b3b3904aeff1a5fed0334 100644 (file)
@@ -2113,11 +2113,17 @@ enum bt_bfcr_status bfcr_floating_point_cb(double value,
        }
 
        field = borrow_next_field(notit);
+       bt_field_class_type type = bt_field_get_class_type(field);
        BT_ASSERT(field);
        BT_ASSERT(bt_field_borrow_class_const(field) == fc->ir_fc);
-       BT_ASSERT(bt_field_get_class_type(field) ==
-                 BT_FIELD_CLASS_TYPE_REAL);
-       bt_field_real_set_value(field, value);
+       BT_ASSERT(type == BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL ||
+                 type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL);
+
+       if (type == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
+               bt_field_real_single_precision_set_value(field, (float) value);
+       } else {
+               bt_field_real_double_precision_set_value(field, value);
+       }
        stack_top(notit->stack)->index++;
 
 end:
index 4789f0ffd2321577952c9759ef89cf7b039dff69..81a74ffd5d0b334b2c448d3e8744df13a644ddd2 100644 (file)
@@ -307,7 +307,8 @@ struct fs_sink_ctf_field_class_float *fs_sink_ctf_field_class_float_create(
        BT_ASSERT(fc);
        _fs_sink_ctf_field_class_bit_array_init((void *) fc,
                FS_SINK_CTF_FIELD_CLASS_TYPE_FLOAT,
-               ir_fc, bt_field_class_real_is_single_precision(ir_fc) ? 32 : 64,
+               ir_fc,
+               bt_field_class_get_type(ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL ? 32 : 64,
                index_in_parent);
        return fc;
 }
index 717571e0d2f3b903d0692ef295136680529cc21e..ca61d10ff1c9bbee4cc450bf64178438c06af54a 100644 (file)
@@ -250,12 +250,14 @@ int write_float_field(struct fs_sink_stream *stream,
                struct fs_sink_ctf_field_class_float *fc, const bt_field *field)
 {
        int ret;
-       double val = bt_field_real_get_value(field);
+       double val;
 
        if (fc->base.size == 32) {
+               val = (double) bt_field_real_single_precision_get_value(field);
                ret = bt_ctfser_write_float32(&stream->ctfser, val,
                        fc->base.base.alignment, BYTE_ORDER);
        } else {
+               val = bt_field_real_double_precision_get_value(field);
                ret = bt_ctfser_write_float64(&stream->ctfser, val,
                        fc->base.base.alignment, BYTE_ORDER);
        }
index 399f3b3cfc6291b6146b053e5007003104e4d446..a94c615e4f410040c9852d72cd74a5f1f90454c3 100644 (file)
@@ -334,7 +334,7 @@ void append_float_field_class(struct ctx *ctx,
 {
        unsigned int mant_dig, exp_dig;
 
-       if (bt_field_class_real_is_single_precision(fc->base.base.ir_fc)) {
+       if (bt_field_class_get_type(fc->base.base.ir_fc) == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
                mant_dig = 24;
                exp_dig = 8;
        } else {
index 4a4bbeee259785d67249dc83fd22ac29ead3fb74..fa79548b83d8162271f4b935d34efc7d177c1a1c 100644 (file)
@@ -1318,7 +1318,8 @@ int translate_field_class(struct ctx *ctx)
        case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
                ret = translate_integer_field_class(ctx);
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
                ret = translate_real_field_class(ctx);
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
index c25e4b3d794efa434f960cd4ea73fca4f7286052..a2b92f7c67f8392958d1fb967094222c9d298d0b 100644 (file)
@@ -250,9 +250,13 @@ void copy_field_content(const bt_field *in_field, bt_field *out_field,
                bt_field_integer_signed_set_value(out_field,
                                bt_field_integer_signed_get_value(in_field));
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               bt_field_real_set_value(out_field,
-                               bt_field_real_get_value(in_field));
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               bt_field_real_single_precision_set_value(out_field,
+                               bt_field_real_single_precision_get_value(in_field));
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               bt_field_real_double_precision_set_value(out_field,
+                               bt_field_real_double_precision_get_value(in_field));
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
        {
index 73a7ad44aea2ee580eedfe7a3f742f79f04aa46e..dc757d03934be630b2242029d1acb2d07973c6de 100644 (file)
@@ -321,20 +321,31 @@ error:
 }
 
 static inline
-int field_class_real_copy(
+int field_class_single_precision_real_copy(
                struct trace_ir_metadata_maps *md_maps,
                const bt_field_class *in_field_class,
                bt_field_class *out_field_class)
 {
-       BT_COMP_LOGD("Copying content of real field class: "
-                       "in-fc-addr=%p, out-fc-addr=%p",
-                       in_field_class, out_field_class);
+       BT_COMP_LOGD("Copying content of single-precision real field class: "
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
 
-       bt_field_class_real_set_is_single_precision(out_field_class,
-                       bt_field_class_real_is_single_precision(in_field_class));
+       BT_COMP_LOGD("Copied content single-precision real field class:"
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
 
-       BT_COMP_LOGD("Copied content real field class: in-fc-addr=%p, "
-                       "out-fc-addr=%p", in_field_class, out_field_class);
+       return 0;
+}
+
+static inline
+int field_class_double_precision_real_copy(
+               struct trace_ir_metadata_maps *md_maps,
+               const bt_field_class *in_field_class,
+               bt_field_class *out_field_class)
+{
+       BT_COMP_LOGD("Copying content of double-precision real field class: "
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
+
+       BT_COMP_LOGD("Copied content double-precision real field class:"
+               "in-fc-addr=%p, out-fc-addr=%p", in_field_class, out_field_class);
 
        return 0;
 }
@@ -673,8 +684,12 @@ bt_field_class *create_field_class_copy_internal(struct trace_ir_metadata_maps *
                out_field_class = bt_field_class_enumeration_signed_create(
                                md_maps->output_trace_class);
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               out_field_class = bt_field_class_real_create(
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               out_field_class = bt_field_class_real_single_precision_create(
+                               md_maps->output_trace_class);
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               out_field_class = bt_field_class_real_double_precision_create(
                                md_maps->output_trace_class);
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
@@ -871,8 +886,12 @@ int copy_field_class_content_internal(
                ret = field_class_signed_enumeration_copy(md_maps,
                                in_field_class, out_field_class);
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               ret = field_class_real_copy(md_maps,
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               ret = field_class_single_precision_real_copy(md_maps,
+                               in_field_class, out_field_class);
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               ret = field_class_double_precision_real_copy(md_maps,
                                in_field_class, out_field_class);
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
index 394c63fd491da3fb67ff2adf5ef492befad2ca50..1eab46b24e09977f8a76eedc575d06464c2768ef 100644 (file)
@@ -931,8 +931,11 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
        case BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION:
                type = "Signed enumeration";
                break;
-       case BT_FIELD_CLASS_TYPE_REAL:
-               type = "Real";
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               type = "Single-precision real";
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
+               type = "Double-precision real";
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
                type = "String";
@@ -986,14 +989,6 @@ void write_field_class(struct details_write_ctx *ctx, const bt_field_class *fc)
                        plural(mapping_count));
                break;
        }
-       case BT_FIELD_CLASS_TYPE_REAL:
-               if (bt_field_class_real_is_single_precision(fc)) {
-                       g_string_append(ctx->str, " (Single precision)");
-               } else {
-                       g_string_append(ctx->str, " (Double precision)");
-               }
-
-               break;
        case BT_FIELD_CLASS_TYPE_STRUCTURE:
        {
                uint64_t member_count =
@@ -1854,9 +1849,13 @@ void write_field(struct details_write_ctx *ctx, const bt_field *field,
 
                break;
        }
-       case BT_FIELD_CLASS_TYPE_REAL:
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+               write_sp(ctx);
+               write_float_prop_value(ctx, bt_field_real_single_precision_get_value(field));
+               break;
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
                write_sp(ctx);
-               write_float_prop_value(ctx, bt_field_real_get_value(field));
+               write_float_prop_value(ctx, bt_field_real_double_precision_get_value(field));
                break;
        case BT_FIELD_CLASS_TYPE_STRING:
                write_sp(ctx);
index d015cdd2feec870dbc8094baa4aa339ca413bc02..b89045d8c0d650e9ebf920c0b30bcec8299edf55 100644 (file)
@@ -1016,11 +1016,17 @@ int print_field(struct pretty_component *pretty,
        case BT_FIELD_CLASS_TYPE_UNSIGNED_INTEGER:
        case BT_FIELD_CLASS_TYPE_SIGNED_INTEGER:
                return print_integer(pretty, field);
-       case BT_FIELD_CLASS_TYPE_REAL:
+       case BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL:
+       case BT_FIELD_CLASS_TYPE_DOUBLE_PRECISION_REAL:
        {
                double v;
 
-               v = bt_field_real_get_value(field);
+               if (class_id == BT_FIELD_CLASS_TYPE_SINGLE_PRECISION_REAL) {
+                       v = (float) bt_field_real_single_precision_get_value(field);
+               } else {
+                       v = bt_field_real_double_precision_get_value(field);
+               }
+
                if (pretty->use_colors) {
                        bt_common_g_string_append(pretty->string, COLOR_NUMBER_VALUE);
                }
index 4288fd91f1471e54bab75be2f3325bc1e5df838b..a770c8f5d58c4316b6f5de9346e509783415b7c6 100644 (file)
@@ -95,7 +95,7 @@ class EventTestCase(unittest.TestCase):
                     cc = tc.create_structure_field_class()
                     cc += [
                         ('cpu_id', tc.create_signed_integer_field_class(8)),
-                        ('stuff', tc.create_real_field_class()),
+                        ('stuff', tc.create_double_precision_real_field_class()),
                     ]
 
                 # packet context (stream-class-defined)
@@ -105,7 +105,10 @@ class EventTestCase(unittest.TestCase):
                     pc = tc.create_structure_field_class()
                     pc += [
                         ('something', tc.create_unsigned_integer_field_class(8)),
-                        ('something_else', tc.create_real_field_class()),
+                        (
+                            'something_else',
+                            tc.create_double_precision_real_field_class(),
+                        ),
                     ]
 
                 stream_class = tc.create_stream_class(
index 53906b97c065a4a5ed28eef0c5c82a62dad5334c..2f855e8bf44484ec5ee5b158615f862bae995c18 100644 (file)
@@ -1390,20 +1390,118 @@ class SignedEnumerationFieldTestCase(_TestIntegerFieldCommon, unittest.TestCase)
         self.assertEqual(labels, ['something', 'whole range', 'zip'])
 
 
-class RealFieldTestCase(_TestNumericField, unittest.TestCase):
+class SingleRealFieldTestCase(_TestNumericField, unittest.TestCase):
+    @staticmethod
+    def _const_value_setter(field):
+        field.value = 52.0
+
+    def _create_fc(self, tc):
+        return tc.create_single_precision_real_field_class()
+
+    def setUp(self):
+        self._tc = get_default_trace_class()
+        self._field = _create_field(self._tc, self._create_fc(self._tc))
+        self._def = _create_field(self._tc, self._create_fc(self._tc))
+        self._def_const = _create_const_field(
+            self._tc,
+            self._tc.create_single_precision_real_field_class(),
+            self._const_value_setter,
+        )
+        self._def.value = 52.0
+        self._def_value = 52.0
+        self._def_new_value = -17.0
+
+    def _test_invalid_op(self, cb):
+        with self.assertRaises(TypeError):
+            cb()
+
+    def test_assign_true(self):
+        self._def.value = True
+        self.assertTrue(self._def)
+
+    def test_assign_false(self):
+        self._def.value = False
+        self.assertFalse(self._def)
+
+    def test_assign_pos_int(self):
+        raw = 477
+        self._def.value = raw
+        self.assertEqual(self._def, float(raw))
+
+    def test_assign_neg_int(self):
+        raw = -13
+        self._def.value = raw
+        self.assertEqual(self._def, float(raw))
+
+    def test_assign_int_field(self):
+        int_fc = self._tc.create_signed_integer_field_class(32)
+        int_field = _create_field(self._tc, int_fc)
+        raw = 999
+        int_field.value = raw
+        self._def.value = int_field
+        self.assertEqual(self._def, float(raw))
+
+    def test_assign_float(self):
+        raw = -19.23
+        self._def.value = raw
+        # It's expected to have some lost of precision because of the field
+        # that is in single precision.
+        self.assertEqual(round(self._def, 5), raw)
+
+    def test_assign_float_field(self):
+        field = _create_field(self._tc, self._create_fc(self._tc))
+        raw = 101.32
+        field.value = raw
+        self._def.value = field
+        # It's expected to have some lost of precision because of the field
+        # that is in single precision.
+        self.assertEqual(round(self._def, 5), raw)
+
+    def test_assign_invalid_type(self):
+        with self.assertRaises(TypeError):
+            self._def.value = 'yes'
+
+    def test_invalid_lshift(self):
+        self._test_invalid_op(lambda: self._def << 23)
+
+    def test_invalid_rshift(self):
+        self._test_invalid_op(lambda: self._def >> 23)
+
+    def test_invalid_and(self):
+        self._test_invalid_op(lambda: self._def & 23)
+
+    def test_invalid_or(self):
+        self._test_invalid_op(lambda: self._def | 23)
+
+    def test_invalid_xor(self):
+        self._test_invalid_op(lambda: self._def ^ 23)
+
+    def test_invalid_invert(self):
+        self._test_invalid_op(lambda: ~self._def)
+
+    def test_str_op(self):
+        self.assertEqual(str(round(self._def, 5)), str(self._def_value))
+
+
+_inject_numeric_testing_methods(SingleRealFieldTestCase)
+
+
+class DoubleRealFieldTestCase(_TestNumericField, unittest.TestCase):
     @staticmethod
     def _const_value_setter(field):
         field.value = 52.7
 
     def _create_fc(self, tc):
-        return tc.create_real_field_class()
+        return tc.create_double_precision_real_field_class()
 
     def setUp(self):
         self._tc = get_default_trace_class()
         self._field = _create_field(self._tc, self._create_fc(self._tc))
         self._def = _create_field(self._tc, self._create_fc(self._tc))
         self._def_const = _create_const_field(
-            self._tc, self._tc.create_real_field_class(), self._const_value_setter
+            self._tc,
+            self._tc.create_double_precision_real_field_class(),
+            self._const_value_setter,
         )
         self._def.value = 52.7
         self._def_value = 52.7
@@ -1477,7 +1575,7 @@ class RealFieldTestCase(_TestNumericField, unittest.TestCase):
         self.assertEqual(str(self._def), str(self._def_value))
 
 
-_inject_numeric_testing_methods(RealFieldTestCase)
+_inject_numeric_testing_methods(DoubleRealFieldTestCase)
 
 
 class StringFieldTestCase(unittest.TestCase):
@@ -1847,7 +1945,7 @@ class StructureFieldTestCase(unittest.TestCase):
         self._tc = get_default_trace_class()
         self._fc0_fn = self._tc.create_signed_integer_field_class
         self._fc1_fn = self._tc.create_string_field_class
-        self._fc2_fn = self._tc.create_real_field_class
+        self._fc2_fn = self._tc.create_double_precision_real_field_class
         self._fc3_fn = self._tc.create_signed_integer_field_class
         self._fc4_fn = self._tc.create_structure_field_class
         self._fc5_fn = self._tc.create_structure_field_class
@@ -1901,7 +1999,7 @@ class StructureFieldTestCase(unittest.TestCase):
         self.assertIs(type(field2), bt2._StringField)
         self.assertEqual(field2, 'salut')
 
-        self.assertIs(type(field3), bt2._RealField)
+        self.assertIs(type(field3), bt2._DoublePrecisionRealField)
         self.assertEqual(field3, 17.5)
 
         self.assertIs(type(field4), bt2._SignedIntegerField)
@@ -1927,7 +2025,7 @@ class StructureFieldTestCase(unittest.TestCase):
         self.assertIs(type(field2), bt2._StringFieldConst)
         self.assertEqual(field2, 'salut')
 
-        self.assertIs(type(field3), bt2._RealFieldConst)
+        self.assertIs(type(field3), bt2._DoublePrecisionRealFieldConst)
         self.assertEqual(field3, 17.5)
 
         self.assertIs(type(field4), bt2._SignedIntegerFieldConst)
@@ -2240,7 +2338,7 @@ class VariantFieldTestCase(unittest.TestCase):
     def _create_fc(self, tc):
         ft0 = tc.create_signed_integer_field_class(32)
         ft1 = tc.create_string_field_class()
-        ft2 = tc.create_real_field_class()
+        ft2 = tc.create_double_precision_real_field_class()
         ft3 = tc.create_signed_integer_field_class(17)
         fc = tc.create_variant_field_class()
         fc.append_option('corner', ft0)
@@ -2292,7 +2390,7 @@ class VariantFieldTestCase(unittest.TestCase):
         self._def.selected_option_index = 2
         self._def.value = -17.34
         self.assertEqual(self._def.selected_option, -17.34)
-        self.assertEqual(type(self._def.selected_option), bt2._RealField)
+        self.assertEqual(type(self._def.selected_option), bt2._DoublePrecisionRealField)
 
         self._def.selected_option_index = 3
         self._def.value = 1921
index e6380474126cc6dd32b55d9bf5fbc588ca780354..b59cc72f48424c2c8248b0d5132ad68f14d4faf3 100644 (file)
@@ -245,34 +245,46 @@ class UnsignedIntegerFieldClassTestCase(
     _create_default_field_class = _create_field_class
 
 
-class RealFieldClassTestCase(_TestFieldClass, unittest.TestCase):
+class SingleRealFieldClassTestCase(_TestFieldClass, unittest.TestCase):
     @staticmethod
     def _const_value_setter(field):
-        field.value = -18
+        field.value = -18.0
 
     def _create_field_class(self, *args, **kwargs):
         tc = get_default_trace_class()
-        return tc.create_real_field_class(*args, **kwargs)
+        return tc.create_single_precision_real_field_class(*args, **kwargs)
 
     def _create_default_const_field_class(self, *args, **kwargs):
         tc = get_default_trace_class()
-        fc = tc.create_real_field_class(*args, **kwargs)
+        fc = tc.create_single_precision_real_field_class(*args, **kwargs)
         return _create_const_field_class(tc, fc, self._const_value_setter)
 
     _create_default_field_class = _create_field_class
 
     def test_create_default(self):
         fc = self._create_field_class()
-        self.assertFalse(fc.is_single_precision)
         self.assertEqual(len(fc.user_attributes), 0)
 
-    def test_create_is_single_precision(self):
-        fc = self._create_field_class(is_single_precision=True)
-        self.assertTrue(fc.is_single_precision)
 
-    def test_create_invalid_is_single_precision(self):
-        with self.assertRaises(TypeError):
-            self._create_field_class(is_single_precision='hohoho')
+class DoubleRealFieldClassTestCase(_TestFieldClass, unittest.TestCase):
+    @staticmethod
+    def _const_value_setter(field):
+        field.value = -18.0
+
+    def _create_field_class(self, *args, **kwargs):
+        tc = get_default_trace_class()
+        return tc.create_double_precision_real_field_class(*args, **kwargs)
+
+    def _create_default_const_field_class(self, *args, **kwargs):
+        tc = get_default_trace_class()
+        fc = tc.create_double_precision_real_field_class(*args, **kwargs)
+        return _create_const_field_class(tc, fc, self._const_value_setter)
+
+    _create_default_field_class = _create_field_class
+
+    def test_create_default(self):
+        fc = self._create_field_class()
+        self.assertEqual(len(fc.user_attributes), 0)
 
 
 # Converts an _EnumerationFieldClassMapping to a list of ranges:
@@ -522,7 +534,7 @@ class _TestElementContainer:
         self.assertIs(type(field_class), bt2_field_class._SignedIntegerFieldClassConst)
 
     def test_iadd(self):
-        a_field_class = self._tc.create_real_field_class()
+        a_field_class = self._tc.create_single_precision_real_field_class()
         b_field_class = self._tc.create_signed_integer_field_class(17)
         self._append_element_method(self._fc, 'a_float', a_field_class)
         self._append_element_method(self._fc, 'b_int', b_field_class)
@@ -548,7 +560,7 @@ class _TestElementContainer:
         self.assertEqual(self._fc['e_struct'].name, 'e_struct')
 
     def test_const_iadd(self):
-        a_field_class = self._tc.create_real_field_class()
+        a_field_class = self._tc.create_single_precision_real_field_class()
         with self.assertRaises(TypeError):
             self._fc_const += a_field_class
 
@@ -566,7 +578,7 @@ class _TestElementContainer:
     def test_getitem(self):
         a_fc = self._tc.create_signed_integer_field_class(32)
         b_fc = self._tc.create_string_field_class()
-        c_fc = self._tc.create_real_field_class()
+        c_fc = self._tc.create_single_precision_real_field_class()
         self._append_element_method(self._fc, 'a', a_fc)
         self._append_element_method(self._fc, 'b', b_fc)
         self._append_element_method(self._fc, 'c', c_fc)
@@ -589,7 +601,7 @@ class _TestElementContainer:
     def test_iter(self):
         a_fc = self._tc.create_signed_integer_field_class(32)
         b_fc = self._tc.create_string_field_class()
-        c_fc = self._tc.create_real_field_class()
+        c_fc = self._tc.create_single_precision_real_field_class()
         elements = (('a', a_fc), ('b', b_fc), ('c', c_fc))
 
         for elem in elements:
@@ -604,7 +616,7 @@ class _TestElementContainer:
     def test_at_index(self):
         a_fc = self._tc.create_signed_integer_field_class(32)
         b_fc = self._tc.create_string_field_class()
-        c_fc = self._tc.create_real_field_class()
+        c_fc = self._tc.create_single_precision_real_field_class()
         self._append_element_method(self._fc, 'c', c_fc)
         self._append_element_method(self._fc, 'a', a_fc)
         self._append_element_method(self._fc, 'b', b_fc)
@@ -682,21 +694,24 @@ class StructureFieldClassTestCase(
 
         tc = get_default_trace_class()
         fc = tc.create_structure_field_class()
-        member_fc = self._tc.create_real_field_class()
+        member_fc = self._tc.create_single_precision_real_field_class()
         fc.append_member('real', member_fc)
         const_fc = _create_const_field_class(tc, fc, _real_value_setter)
 
         self.assertIs(
-            type(const_fc['real'].field_class), bt2_field_class._RealFieldClassConst
+            type(const_fc['real'].field_class),
+            bt2_field_class._SinglePrecisionRealFieldClassConst,
         )
 
     def test_member_field_class(self):
         tc = get_default_trace_class()
         fc = tc.create_structure_field_class()
-        member_fc = self._tc.create_real_field_class()
+        member_fc = self._tc.create_single_precision_real_field_class()
         fc.append_member('real', member_fc)
 
-        self.assertIs(type(fc['real'].field_class), bt2_field_class._RealFieldClass)
+        self.assertIs(
+            type(fc['real'].field_class), bt2_field_class._SinglePrecisionRealFieldClass
+        )
 
 
 class OptionFieldClassTestCase(_TestFieldClass, unittest.TestCase):
@@ -736,7 +751,7 @@ class OptionFieldClassTestCase(_TestFieldClass, unittest.TestCase):
     def _create_field_class_for_field_path_test(self):
         fc = self._create_default_field_class(selector_fc=self._tag_fc)
 
-        foo_fc = self._tc.create_real_field_class()
+        foo_fc = self._tc.create_single_precision_real_field_class()
         bar_fc = self._tc.create_string_field_class()
         baz_fc = self._tc.create_string_field_class()
 
@@ -948,7 +963,7 @@ class _VariantFieldClassWithSelectorTestCase:
             )
 
     def test_iadd(self):
-        a_field_class = self._tc.create_real_field_class()
+        a_field_class = self._tc.create_single_precision_real_field_class()
         self._fc.append_option('a_float', a_field_class, self._ranges1)
         c_field_class = self._tc.create_string_field_class()
         d_field_class = self._tc.create_signed_enumeration_field_class(
@@ -970,7 +985,7 @@ class _VariantFieldClassWithSelectorTestCase:
 
     def test_const_iadd(self):
         fc_const = self._create_default_const_field_class()
-        a_field_class = self._tc.create_real_field_class()
+        a_field_class = self._tc.create_single_precision_real_field_class()
         with self.assertRaises(TypeError):
             fc_const += [('a_float', a_field_class, self._ranges1)]
 
@@ -988,7 +1003,7 @@ class _VariantFieldClassWithSelectorTestCase:
     def test_getitem(self):
         a_fc = self._tc.create_signed_integer_field_class(32)
         b_fc = self._tc.create_string_field_class()
-        c_fc = self._tc.create_real_field_class()
+        c_fc = self._tc.create_single_precision_real_field_class()
         self._fc.append_option('a', a_fc, self._ranges1)
         self._fc.append_option('b', b_fc, self._ranges2)
         self._fc.append_option('c', c_fc, self._ranges3)
@@ -1026,7 +1041,7 @@ class _VariantFieldClassWithSelectorTestCase:
     def test_iter(self):
         a_fc = self._tc.create_signed_integer_field_class(32)
         b_fc = self._tc.create_string_field_class()
-        c_fc = self._tc.create_real_field_class()
+        c_fc = self._tc.create_single_precision_real_field_class()
         opts = (
             ('a', a_fc, self._ranges1),
             ('b', b_fc, self._ranges2),
@@ -1045,7 +1060,7 @@ class _VariantFieldClassWithSelectorTestCase:
     def test_at_index(self):
         a_fc = self._tc.create_signed_integer_field_class(32)
         b_fc = self._tc.create_string_field_class()
-        c_fc = self._tc.create_real_field_class()
+        c_fc = self._tc.create_single_precision_real_field_class()
         self._fc.append_option('c', c_fc, self._ranges1)
         self._fc.append_option('a', a_fc, self._ranges2)
         self._fc.append_option('b', b_fc, self._ranges3)
@@ -1085,7 +1100,9 @@ class _VariantFieldClassWithSelectorTestCase:
         #     } variant;
         #   } inner_struct[2];
         # };
-        self._fc.append_option('a', self._tc.create_real_field_class(), self._ranges1)
+        self._fc.append_option(
+            'a', self._tc.create_single_precision_real_field_class(), self._ranges1
+        )
         self._fc.append_option(
             'b', self._tc.create_signed_integer_field_class(21), self._ranges2
         )
@@ -1093,7 +1110,7 @@ class _VariantFieldClassWithSelectorTestCase:
             'c', self._tc.create_unsigned_integer_field_class(34), self._ranges3
         )
 
-        foo_fc = self._tc.create_real_field_class()
+        foo_fc = self._tc.create_single_precision_real_field_class()
         bar_fc = self._tc.create_string_field_class()
         baz_fc = self._tc.create_string_field_class()
 
@@ -1255,7 +1272,7 @@ class DynamicArrayFieldClassTestCase(_ArrayFieldClassTestCase, unittest.TestCase
 
         fc = self._tc.create_dynamic_array_field_class(self._elem_fc, self._len_fc)
 
-        foo_fc = self._tc.create_real_field_class()
+        foo_fc = self._tc.create_single_precision_real_field_class()
         bar_fc = self._tc.create_string_field_class()
         baz_fc = self._tc.create_string_field_class()
 
index d067a8e215033ff24031c34487d98ff5cf967316..c3295c8a33cb8ed2b14cd8496c443ad9a145c46d 100644 (file)
@@ -99,6 +99,12 @@ class PackageTestCase(unittest.TestCase):
     def test_has__RealField(self):
         self._assert_in_bt2('_RealField')
 
+    def test_has__SinglePrecisionRealField(self):
+        self._assert_in_bt2('_SinglePrecisionRealField')
+
+    def test_has__DoublePrecisionRealField(self):
+        self._assert_in_bt2('_DoublePrecisionRealField')
+
     def test_has__EnumerationField(self):
         self._assert_in_bt2('_EnumerationField')
 
@@ -147,6 +153,12 @@ class PackageTestCase(unittest.TestCase):
     def test_has__RealFieldConst(self):
         self._assert_in_bt2('_RealFieldConst')
 
+    def test_has__SinglePrecisionRealFieldConst(self):
+        self._assert_in_bt2('_SinglePrecisionRealFieldConst')
+
+    def test_has__DoublePrecisionRealFieldConst(self):
+        self._assert_in_bt2('_DoublePrecisionRealFieldConst')
+
     def test_has__EnumerationFieldConst(self):
         self._assert_in_bt2('_EnumerationFieldConst')
 
index 196c9fbeaebdab4b2febf87be83cfc9d03bdf35c..255aaf20821df4d72bd1be9831a85ffe10bd4b38 100644 (file)
@@ -37,7 +37,7 @@ class PacketTestCase(unittest.TestCase):
         sec = tc.create_structure_field_class()
         sec += [
             ('cpu_id', tc.create_signed_integer_field_class(8)),
-            ('stuff', tc.create_real_field_class()),
+            ('stuff', tc.create_double_precision_real_field_class()),
         ]
 
         # packet context
@@ -46,7 +46,7 @@ class PacketTestCase(unittest.TestCase):
             pc = tc.create_structure_field_class()
             pc += [
                 ('something', tc.create_signed_integer_field_class(8)),
-                ('something_else', tc.create_real_field_class()),
+                ('something_else', tc.create_double_precision_real_field_class()),
                 ('events_discarded', tc.create_unsigned_integer_field_class(64)),
                 ('packet_seq_num', tc.create_unsigned_integer_field_class(64)),
             ]
index 9fb33b043a3fcca542bd6f40adf63dcdce6286e2..bf7b1afd0ca8ede00676fa1e2c47aa660b154818 100644 (file)
@@ -16,7 +16,7 @@ Trace class:
       Origin is Unix epoch: No
     Event class `ev` (ID 0):
       Payload field class: Structure (1 member):
-        dbl: Real (Double precision)
+        dbl: Double-precision real
 
 [Unknown]
 {Trace 0, Stream class ID 0, Stream ID 0}
index f2bcf31710fb8eeea9ae818af1cca2178a6d42e5..b9ff6876b9a3ed4b80397613aa0b6e5d6bfd063e 100644 (file)
@@ -16,7 +16,7 @@ Trace class:
       Origin is Unix epoch: No
     Event class `ev` (ID 0):
       Payload field class: Structure (1 member):
-        flt: Real (Single precision)
+        flt: Single-precision real
 
 [Unknown]
 {Trace 0, Stream class ID 0, Stream ID 0}
index 9ac2644b1d4c2b80a8f1dbc2c14e83fa65e5931c..28032e7239b0dac805a98c2a1cf54e0f559e3214 100644 (file)
@@ -227,8 +227,8 @@ Trace class:
         seqfield_network_3: Dynamic array (Length field path [Event payload: 17]):
           Element: Signed integer (64-bit, Base 10)
         stringfield: String
-        floatfield: Real (Single precision)
-        doublefield: Real (Double precision)
+        floatfield: Single-precision real
+        doublefield: Double-precision real
         boolfield: Unsigned integer (8-bit, Base 10)
     Event class `ust_tests_hello:tptest_sighandler` (ID 26):
       Log level: Debug (line)
@@ -539,8 +539,8 @@ Trace class:
         seqfield_network_3: Dynamic array (Length field path [Event payload: 17]):
           Element: Signed integer (64-bit, Base 10)
         stringfield: String
-        floatfield: Real (Single precision)
-        doublefield: Real (Double precision)
+        floatfield: Single-precision real
+        doublefield: Double-precision real
         boolfield: Unsigned integer (8-bit, Base 10)
     Event class `ust_tests_hello:tptest_sighandler` (ID 26):
       Log level: Debug (line)
This page took 0.052048 seconds and 4 git commands to generate.