lib: add unsigned and signed integer value API
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 3 May 2019 19:14:18 +0000 (15:14 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 6 May 2019 14:13:09 +0000 (10:13 -0400)
This patch replaces the integer value API with the more specific
unsigned and signed integer value API. This opens the whole unsigned
64-bit set for component initialization parameters, query parameters,
queyr results, and, eventually, custom metadata attributes. This is also
more in line with the field API, which has both the unsigned and signed
versions.

Library
=======
The API is simply split in two, where an unsigned integer value contains
a `uint64_t` raw value and a signed integer value is the equivalent of
the previous integer value (`int64_t` raw value).

The types are `BT_VALUE_TYPE_UNSIGNED_INTEGER` and
`BT_VALUE_TYPE_SIGNED_INTEGER`.

There's no interaction between unsigned and signed integer values, in
that, for example, you cannot compare an unsigned integer value with a
signed integer value with bt_value_compare().

Behind the scenes, I kept a single `struct bt_value_integer` for
simplicity. It contains a union of `uint64_t` and `int64_t`. Most
functions call a generic unsigned version, casting to `uint64_t` when
necessary. For example, there's a common bt_value_integer_compare()
which compares the `uint64_t` values.

CLI
===
Before this patch, the `--params` option's format makes any integer
constant a signed integer value object. With this patch, you can create
an unsigned integer value by prepending the constant with `+`. For
example:

    hello=+293, meow=+0x388ab88fd, uint-zero=+0

I wanted to use the `U` suffix, like in C/C++, but the GLib lexical
scanner won't allow a constant to be followed by an identifier without a
whitespace.

The documentation about the format of `--params` is updated for the
CLI's `--help` option and in the man pages.

Plugins
=======
It's up to each plugin to accept, for a given parameter, an unsigned
integer value, a signed integer value, or both. A plugin can be very
strict and it's not a bad thing: there are situations where an unsigned
integer is conceptually required.

The individual changes are:

`src.ctf.fs`:
    In the `trace-info` query result, create unsigned integer values for
    the `id` (stream ID) and `class-id` (stream class ID) entries. A CTF
    metadata ID is never negative.

`src.ctf.lttng-live`:
    In the `sessions` query result, the `timer-us`, `stream-count`, and
    `client-count` entries are still signed integer values. They could
    probably be unsigned, but I want to confirm this with developers
    more involved with this component class before doing the change. For
    the moment, the query operation is unchanged.

`sink.utils.counter`:
    The `step` initialization parameter is now expected to be an
    unsigned integer value. This is never negative.

    I also made the initialization refuse parameters when they don't
    have the expected type. There are new `logging.c` and `logging.h`
    files for this component class because I used logging to communicate
    said errors.

Library tests
=============
The integer value tests now test the signed value API.

I added equivalent unsigned value object tests.

Python bindings
===============
`_IntegerValue` is now the base class of `UnsignedIntegerValue` and
`SignedIntegerValue`. `_IntegerValue` contains the whole public
interface, using template methods with specialized parts defined in
subclasses.

`_IntegerValue` is imported in the `bt2` package for this use case:

    if isinstance(val, bt2._IntegerValue):
        do_something_with(val)

because `int(val)` is always valid.

The bt2.create_value() function still creates a `SignedIntegerValue`
object with an `int` value. This is the safest, as there's no way to
know that this value will be changed to a negative value in the future,
before the value object is frozen. For example, this would not be
possible with a conversion to an `UnsignedIntegerValue`:

    val = bt2.create_value(47)
    val.value = -23

whereas it is possible with a `SignedIntegerValue`. You can still
explicitly create an unsigned integer value:

    counter_comp = my_graph.add_component(counter_cls, 'counter', {
        'step': bt2.UnsignedIntegerValue(29)
    });

Python bindings tests
=====================
`test_value.py` is updated to also test the `UnsignedIntegerValue`
class. _inject_numeric_testing_methods() now accepts an optional
`has_neg` parameter which, if false, does not inject tests which involve
negative integer values.

There is a common `_TestIntegerValue` class which
`SignedIntegerValueTestCase` and `UnsignedIntegerValueTestCase` inherit.
The tests are almost the same, but `SignedIntegerValueTestCase` adds a
few tests related to negative values. Both specific test cases set the
`_CLS` class attribute to the value object class to test, either
`UnsignedIntegerValue` or `SignedIntegerValue`.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ic96ef9e1e16883cb5c59844c6ba5a060936efdb0
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1257
Tested-by: jenkins
29 files changed:
bindings/python/bt2/bt2/__init__.py.in
bindings/python/bt2/bt2/native_bt_value.i
bindings/python/bt2/bt2/value.py
cli/babeltrace-cfg-cli-args.c
cli/babeltrace.c
doc/man/common-cmd-params-format.txt
include/babeltrace/common-internal.h
include/babeltrace/value-const.h
include/babeltrace/value-internal.h
include/babeltrace/value.h
lib/lib-logging.c
lib/trace-ir/trace-class.c
lib/value.c
plugins/ctf/fs-sink/fs-sink-trace.c
plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c
plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c
plugins/ctf/fs-src/fs.c
plugins/ctf/fs-src/query.c
plugins/ctf/lttng-live/viewer-connection.c
plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c
plugins/text/pretty/print.c
plugins/utils/counter/Makefile.am
plugins/utils/counter/counter.c
plugins/utils/counter/logging.c [new file with mode: 0644]
plugins/utils/counter/logging.h [new file with mode: 0644]
plugins/utils/trimmer/trimmer.c
tests/bindings/python/bt2/test_value.py
tests/lib/test_bt_values.c
tests/lib/test_plugin.c

index d064dc592847688e40501cc677ec712cd248ef92..8c79b088a1a6c5271eb9b3ca57d067dcca479a7b 100644 (file)
@@ -77,6 +77,7 @@ from bt2.trace import *
 from bt2.trace_collection_message_iterator import *
 from bt2.value import *
 from bt2.value import _Value
+from bt2.value import _IntegerValue
 
 
 class Error(Exception):
index 6d1aeff963c379e40c1ad1a44e991474de50444c..1ecd21e36b52b2784513933a8ed3e094b152bb0d 100644 (file)
@@ -37,52 +37,43 @@ typedef enum bt_value_status {
 
 typedef enum bt_value_type {
        /// Null value object.
-       BT_VALUE_TYPE_NULL =            0,
+       BT_VALUE_TYPE_NULL              = 0,
 
        /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
-       BT_VALUE_TYPE_BOOL =            1,
+       BT_VALUE_TYPE_BOOL              = 1,
 
-       /// Integer value object (holds a signed 64-bit integer raw value).
-       BT_VALUE_TYPE_INTEGER =         2,
+       /// Unsigned integer value object (holds an unsigned 64-bit integer raw value).
+       BT_VALUE_TYPE_UNSIGNED_INTEGER  = 2,
+
+       /// Signed integer value object (holds a signed 64-bit integer raw value).
+       BT_VALUE_TYPE_SIGNED_INTEGER    = 3,
 
        /// Floating point number value object (holds a \c double raw value).
-       BT_VALUE_TYPE_REAL =            3,
+       BT_VALUE_TYPE_REAL              = 4,
 
        /// String value object.
-       BT_VALUE_TYPE_STRING =          4,
+       BT_VALUE_TYPE_STRING            = 5,
 
        /// Array value object.
-       BT_VALUE_TYPE_ARRAY =           5,
+       BT_VALUE_TYPE_ARRAY             = 6,
 
        /// Map value object.
-       BT_VALUE_TYPE_MAP =             6,
+       BT_VALUE_TYPE_MAP               = 7,
 } bt_value_type;
 
 extern bt_value_type bt_value_get_type(const bt_value *object);
 
-bt_bool bt_value_is_null(const bt_value *object);
-
-bt_bool bt_value_is_bool(const bt_value *object);
-
-bt_bool bt_value_is_integer(const bt_value *object);
-
-bt_bool bt_value_is_real(const bt_value *object);
-
-bt_bool bt_value_is_string(const bt_value *object);
-
-bt_bool bt_value_is_array(const bt_value *object);
-
-bt_bool bt_value_is_map(const bt_value *object);
-
 extern bt_value_status bt_value_copy(const bt_value *object,
-               bt_value **OUT);
+               bt_value **copy);
 
 extern bt_bool bt_value_compare(const bt_value *object_a,
                const bt_value *object_b);
 
 extern bt_bool bt_value_bool_get(const bt_value *bool_obj);
 
-extern int64_t bt_value_integer_get(const bt_value *integer_obj);
+extern uint64_t bt_value_unsigned_integer_get(const bt_value *integer_obj);
+
+extern int64_t bt_value_signed_integer_get(const bt_value *integer_obj);
 
 extern double bt_value_real_get(const bt_value *real_obj);
 
@@ -90,15 +81,11 @@ extern const char *bt_value_string_get(const bt_value *string_obj);
 
 extern uint64_t bt_value_array_get_size(const bt_value *array_obj);
 
-bt_bool bt_value_array_is_empty(const bt_value *array_obj);
-
 extern const bt_value *bt_value_array_borrow_element_by_index_const(
                const bt_value *array_obj, uint64_t index);
 
 extern uint64_t bt_value_map_get_size(const bt_value *map_obj);
 
-bt_bool bt_value_map_is_empty(const bt_value *map_obj);
-
 extern const bt_value *bt_value_map_borrow_entry_value_const(
                const bt_value *map_obj, const char *key);
 
@@ -131,12 +118,17 @@ extern bt_value *bt_value_bool_create_init(bt_bool val);
 
 extern void bt_value_bool_set(bt_value *bool_obj, bt_bool val);
 
-extern bt_value *bt_value_integer_create(void);
+extern bt_value *bt_value_unsigned_integer_create(void);
+
+extern bt_value *bt_value_unsigned_integer_create_init(uint64_t val);
 
-extern bt_value *bt_value_integer_create_init(
-               int64_t val);
+extern void bt_value_unsigned_integer_set(bt_value *integer_obj, uint64_t val);
 
-extern void bt_value_integer_set(bt_value *integer_obj, int64_t val);
+extern bt_value *bt_value_signed_integer_create(void);
+
+extern bt_value *bt_value_signed_integer_create_init(int64_t val);
+
+extern void bt_value_signed_integer_set(bt_value *integer_obj, int64_t val);
 
 extern bt_value *bt_value_real_create(void);
 
@@ -163,7 +155,10 @@ extern bt_value_status bt_value_array_append_element(
 extern bt_value_status bt_value_array_append_bool_element(
                bt_value *array_obj, bt_bool val);
 
-extern bt_value_status bt_value_array_append_integer_element(
+extern bt_value_status bt_value_array_append_unsigned_integer_element(
+               bt_value *array_obj, uint64_t val);
+
+extern bt_value_status bt_value_array_append_signed_integer_element(
                bt_value *array_obj, int64_t val);
 
 extern bt_value_status bt_value_array_append_real_element(
@@ -201,7 +196,10 @@ extern bt_value_status bt_value_map_insert_entry(
 extern bt_value_status bt_value_map_insert_bool_entry(
                bt_value *map_obj, const char *key, bt_bool val);
 
-extern bt_value_status bt_value_map_insert_integer_entry(
+extern bt_value_status bt_value_map_insert_unsigned_integer_entry(
+               bt_value *map_obj, const char *key, uint64_t val);
+
+extern bt_value_status bt_value_map_insert_signed_integer_entry(
                bt_value *map_obj, const char *key, int64_t val);
 
 extern bt_value_status bt_value_map_insert_real_entry(
index 1a5612da49ae0bb5baf1011067513b7b40163746..5beccbcd197689666c8485c869f48470a85acd7f 100644 (file)
@@ -64,7 +64,7 @@ def create_value(value):
         return BoolValue(value)
 
     if isinstance(value, int):
-        return IntegerValue(value)
+        return SignedIntegerValue(value)
 
     if isinstance(value, float):
         return RealValue(value)
@@ -366,14 +366,12 @@ class BoolValue(_Value):
     value = property(fset=_set_value)
 
 
-class IntegerValue(_IntegralValue):
-    _NAME = 'Integer'
-
+class _IntegerValue(_IntegralValue):
     def __init__(self, value=None):
         if value is None:
-            ptr = native_bt.value_integer_create()
+            ptr = self._create_default_value()
         else:
-            ptr = native_bt.value_integer_create_init(self._value_to_int(value))
+            ptr = self._create_value(self._value_to_int(value))
 
         self._check_create_status(ptr)
         super().__init__(ptr)
@@ -383,17 +381,33 @@ class IntegerValue(_IntegralValue):
             raise TypeError('expecting a number object')
 
         value = int(value)
-        utils._check_int64(value)
+        self._check_int_range(value)
         return value
 
     @property
     def _value(self):
-        return native_bt.value_integer_get(self._ptr)
+        return self._get_value(self._ptr)
 
-    def _set_value(self, value):
-        native_bt.value_integer_set(self._ptr, self._value_to_int(value))
+    def _prop_set_value(self, value):
+        self._set_value(self._ptr, self._value_to_int(value))
 
-    value = property(fset=_set_value)
+    value = property(fset=_prop_set_value)
+
+
+class UnsignedIntegerValue(_IntegerValue):
+    _check_int_range = staticmethod(utils._check_uint64)
+    _create_default_value = native_bt.value_unsigned_integer_create
+    _create_value = native_bt.value_unsigned_integer_create_init
+    _set_value = native_bt.value_unsigned_integer_set
+    _get_value = native_bt.value_unsigned_integer_get
+
+
+class SignedIntegerValue(_IntegerValue):
+    _check_int_range = staticmethod(utils._check_int64)
+    _create_default_value = native_bt.value_signed_integer_create
+    _create_value = native_bt.value_signed_integer_create_init
+    _set_value = native_bt.value_signed_integer_set
+    _get_value = native_bt.value_signed_integer_get
 
 
 class RealValue(_RealValue):
@@ -689,7 +703,8 @@ class MapValue(_Container, collections.abc.MutableMapping, _Value):
 
 _TYPE_TO_OBJ = {
     native_bt.VALUE_TYPE_BOOL: BoolValue,
-    native_bt.VALUE_TYPE_INTEGER: IntegerValue,
+    native_bt.VALUE_TYPE_UNSIGNED_INTEGER: UnsignedIntegerValue,
+    native_bt.VALUE_TYPE_SIGNED_INTEGER: SignedIntegerValue,
     native_bt.VALUE_TYPE_REAL: RealValue,
     native_bt.VALUE_TYPE_STRING: StringValue,
     native_bt.VALUE_TYPE_ARRAY: ArrayValue,
index dfce55bdec8a41698ac5b252df32f67d35e3e6ad..05193d3bdf2c46c60758c8fdab1d78630a906f38 100644 (file)
@@ -185,6 +185,26 @@ void ini_append_error_expecting(struct ini_parsing_state *state,
        g_string_append_printf(state->ini_error, "^\n\n");
 }
 
+/* Parse the next token as an unsigned integer. */
+static
+bt_value *ini_parse_uint(struct ini_parsing_state *state)
+{
+       bt_value *value = NULL;
+       GTokenType token_type = g_scanner_get_next_token(state->scanner);
+
+       if (token_type != G_TOKEN_INT) {
+               ini_append_error_expecting(state, state->scanner,
+                       "integer value");
+               goto end;
+       }
+
+       value = bt_value_unsigned_integer_create_init(
+               state->scanner->value.v_int64);
+
+end:
+       return value;
+}
+
 /* Parse the next token as a number and return its negation. */
 static
 bt_value *ini_parse_neg_number(struct ini_parsing_state *state)
@@ -203,7 +223,8 @@ bt_value *ini_parse_neg_number(struct ini_parsing_state *state)
                                "Integer value -%" PRIu64 " is outside the range of a 64-bit signed integer\n",
                                int_val);
                } else {
-                       value = bt_value_integer_create_init(-((int64_t) int_val));
+                       value = bt_value_signed_integer_create_init(
+                               -((int64_t) int_val));
                }
 
                break;
@@ -306,6 +327,9 @@ bt_value *ini_parse_value(struct ini_parsing_state *state)
                if (state->scanner->value.v_char == '-') {
                        /* Negative number */
                        value = ini_parse_neg_number(state);
+               } else if (state->scanner->value.v_char == '+') {
+                       /* Unsigned integer */
+                       value = ini_parse_uint(state);
                } else if (state->scanner->value.v_char == '[') {
                        /* Array */
                        value = ini_parse_array(state);
@@ -315,7 +339,7 @@ bt_value *ini_parse_value(struct ini_parsing_state *state)
                break;
        case G_TOKEN_INT:
        {
-               /* Positive integer */
+               /* Positive, signed integer */
                uint64_t int_val = state->scanner->value.v_int64;
 
                if (int_val > INT64_MAX) {
@@ -323,7 +347,8 @@ bt_value *ini_parse_value(struct ini_parsing_state *state)
                                "Integer value %" PRIu64 " is outside the range of a 64-bit signed integer\n",
                                int_val);
                } else {
-                       value = bt_value_integer_create_init((int64_t)int_val);
+                       value = bt_value_signed_integer_create_init(
+                               (int64_t) int_val);
                }
                break;
        }
@@ -1836,7 +1861,7 @@ void print_expected_params_format(FILE *fp)
        fprintf(fp, "* `true`, `TRUE`, `yes`, `YES`: true boolean value (no backticks).\n");
        fprintf(fp, "* `false`, `FALSE`, `no`, `NO`: false boolean value (no backticks).\n");
        fprintf(fp, "* Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal\n");
-       fprintf(fp, "  (`0x` prefix) signed 64-bit integer.\n");
+       fprintf(fp, "  (`0x` prefix) unsigned (with `+` prefix) or signed 64-bit integer.\n");
        fprintf(fp, "* Double precision floating point number (scientific notation is accepted).\n");
        fprintf(fp, "* Unquoted string with no special characters, and not matching any of\n");
        fprintf(fp, "  the null and boolean value symbols above.\n");
@@ -1849,7 +1874,7 @@ void print_expected_params_format(FILE *fp)
        fprintf(fp, "Example:\n");
        fprintf(fp, "\n");
        fprintf(fp, "    many=null, fresh=yes, condition=false, squirrel=-782329,\n");
-       fprintf(fp, "    observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
+       fprintf(fp, "    play=+23, observe=3.14, simple=beef, needs-quotes=\"some string\",\n");
        fprintf(fp, "    escape.chars-are:allowed=\"this is a \\\" double quote\",\n");
        fprintf(fp, "    things=[1, \"2\", 3]\n");
        fprintf(fp, "\n");
index a0de86f770139881ca8599f97a6312ff704b079a..39b1f3c2a501d1efd4708fabc16666830d6504f1 100644 (file)
@@ -493,6 +493,7 @@ void print_value_rec(FILE *fp, const bt_value *value, size_t indent)
 {
        bt_bool bool_val;
        int64_t int_val;
+       uint64_t uint_val;
        double dbl_val;
        const char *str_val;
        int size;
@@ -513,8 +514,14 @@ void print_value_rec(FILE *fp, const bt_value *value, size_t indent)
                        bt_common_color_fg_cyan(), bool_val ? "yes" : "no",
                        bt_common_color_reset());
                break;
-       case BT_VALUE_TYPE_INTEGER:
-               int_val = bt_value_integer_get(value);
+       case BT_VALUE_TYPE_UNSIGNED_INTEGER:
+               uint_val = bt_value_unsigned_integer_get(value);
+               fprintf(fp, "%s%s%" PRIu64 "%s\n", bt_common_color_bold(),
+                       bt_common_color_fg_red(), uint_val,
+                       bt_common_color_reset());
+               break;
+       case BT_VALUE_TYPE_SIGNED_INTEGER:
+               int_val = bt_value_signed_integer_get(value);
                fprintf(fp, "%s%s%" PRId64 "%s\n", bt_common_color_bold(),
                        bt_common_color_fg_red(), int_val,
                        bt_common_color_reset());
@@ -1313,21 +1320,21 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                        BT_LOGE_STR("Unexpected empty array \"timer-us\" entry.");
                        goto error;
                }
-               timer_us = bt_value_integer_get(v);
+               timer_us = bt_value_signed_integer_get(v);
                fprintf(out_stream, " (timer = %" PRIu64 ", ", timer_us);
                v = bt_value_map_borrow_entry_value_const(map, "stream-count");
                if (!v) {
                        BT_LOGE_STR("Unexpected empty array \"stream-count\" entry.");
                        goto error;
                }
-               streams = bt_value_integer_get(v);
+               streams = bt_value_signed_integer_get(v);
                fprintf(out_stream, "%" PRIu64 " stream(s), ", streams);
                v = bt_value_map_borrow_entry_value_const(map, "client-count");
                if (!v) {
                        BT_LOGE_STR("Unexpected empty array \"client-count\" entry.");
                        goto error;
                }
-               clients = bt_value_integer_get(v);
+               clients = bt_value_signed_integer_get(v);
                fprintf(out_stream, "%" PRIu64 " client(s) connected)\n", clients);
        }
 
@@ -2229,8 +2236,8 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                        goto error;
                }
 
-               begin = bt_value_integer_get(intersection_begin);
-               end = bt_value_integer_get(intersection_end);
+               begin = bt_value_signed_integer_get(intersection_begin);
+               end = bt_value_signed_integer_get(intersection_end);
 
                if (begin < 0 || end < 0 || end < begin) {
                        BT_LOGW("Invalid trace stream intersection values: "
index efceab479f4c4353b6fa13ecec39101ae7a210d5..4acce3d7ed4e071e1a106dbabbc632804e011b6a 100644 (file)
@@ -21,7 +21,7 @@ list of `NAME=VALUE` assignments:
 * `false`, `FALSE`, `no`, `NO`: false boolean value.
 
 * Binary (`0b` prefix), octal (`0` prefix), decimal, or hexadecimal
-  (`0x` prefix) signed 64-bit integer.
+  (`0x` prefix) unsigned (with `+` prefix) or signed 64-bit integer.
 
 * Double precision floating point number (scientific notation is
   accepted).
@@ -42,7 +42,7 @@ Example:
 
 ----
 babeltrace ... --params='many=null, fresh=yes, condition=false,
-                         squirrel=-782329, observe=3.14,
+                         squirrel=-782329, play=+23, observe=3.14,
                          simple=beef, needs-quotes="some string",
                          escape.chars-are:allowed="a \" quote",
                          things=[1, "2", 3]'
index 19594fe3c347f4345788befe9078df3dac13bcf2..4290f0bd3ecb0d600c5db69d90d97663a09e6ef7 100644 (file)
@@ -466,8 +466,10 @@ const char *bt_common_value_type_string(enum bt_value_type type)
                return "BT_VALUE_TYPE_NULL";
        case BT_VALUE_TYPE_BOOL:
                return "BT_VALUE_TYPE_BOOL";
-       case BT_VALUE_TYPE_INTEGER:
-               return "BT_VALUE_TYPE_INTEGER";
+       case BT_VALUE_TYPE_UNSIGNED_INTEGER:
+               return "BT_VALUE_TYPE_UNSIGNED_INTEGER";
+       case BT_VALUE_TYPE_SIGNED_INTEGER:
+               return "BT_VALUE_TYPE_SIGNED_INTEGER";
        case BT_VALUE_TYPE_REAL:
                return "BT_VALUE_TYPE_REAL";
        case BT_VALUE_TYPE_STRING:
index e5ff39da546e578bd991a1b6841ed4eb93d160b6..63368085792cd45268a5cca91cb7d6f077cea2ff 100644 (file)
@@ -46,25 +46,28 @@ typedef enum bt_value_status {
 
 typedef enum bt_value_type {
        /// Null value object.
-       BT_VALUE_TYPE_NULL =            0,
+       BT_VALUE_TYPE_NULL              = 0,
 
        /// Boolean value object (holds #BT_TRUE or #BT_FALSE).
-       BT_VALUE_TYPE_BOOL =            1,
+       BT_VALUE_TYPE_BOOL              = 1,
 
-       /// Integer value object (holds a signed 64-bit integer raw value).
-       BT_VALUE_TYPE_INTEGER =         2,
+       /// Unsigned integer value object (holds an unsigned 64-bit integer raw value).
+       BT_VALUE_TYPE_UNSIGNED_INTEGER  = 2,
+
+       /// Signed integer value object (holds a signed 64-bit integer raw value).
+       BT_VALUE_TYPE_SIGNED_INTEGER    = 3,
 
        /// Floating point number value object (holds a \c double raw value).
-       BT_VALUE_TYPE_REAL =            3,
+       BT_VALUE_TYPE_REAL              = 4,
 
        /// String value object.
-       BT_VALUE_TYPE_STRING =          4,
+       BT_VALUE_TYPE_STRING            = 5,
 
        /// Array value object.
-       BT_VALUE_TYPE_ARRAY =           5,
+       BT_VALUE_TYPE_ARRAY             = 6,
 
        /// Map value object.
-       BT_VALUE_TYPE_MAP =             6,
+       BT_VALUE_TYPE_MAP               = 7,
 } bt_value_type;
 
 extern bt_value_type bt_value_get_type(const bt_value *object);
@@ -82,9 +85,15 @@ bt_bool bt_value_is_bool(const bt_value *object)
 }
 
 static inline
-bt_bool bt_value_is_integer(const bt_value *object)
+bt_bool bt_value_is_unsigned_integer(const bt_value *object)
+{
+       return bt_value_get_type(object) == BT_VALUE_TYPE_UNSIGNED_INTEGER;
+}
+
+static inline
+bt_bool bt_value_is_signed_integer(const bt_value *object)
 {
-       return bt_value_get_type(object) == BT_VALUE_TYPE_INTEGER;
+       return bt_value_get_type(object) == BT_VALUE_TYPE_SIGNED_INTEGER;
 }
 
 static inline
@@ -119,7 +128,9 @@ extern bt_bool bt_value_compare(const bt_value *object_a,
 
 extern bt_bool bt_value_bool_get(const bt_value *bool_obj);
 
-extern int64_t bt_value_integer_get(const bt_value *integer_obj);
+extern uint64_t bt_value_unsigned_integer_get(const bt_value *integer_obj);
+
+extern int64_t bt_value_signed_integer_get(const bt_value *integer_obj);
 
 extern double bt_value_real_get(const bt_value *real_obj);
 
index dd3fb7d9fae321ca39ac086043346ef3c635ecb4..0e50e2de0fb4c3c1566fd5bf053507e2d9496e09 100644 (file)
@@ -42,7 +42,10 @@ struct bt_value_bool {
 
 struct bt_value_integer {
        struct bt_value base;
-       int64_t value;
+       union {
+               uint64_t i;
+               int64_t u;
+       } value;
 };
 
 struct bt_value_real {
index 89c4c64ef5311ea8b874c2d1d977a0017801b129..0425b6b4d6005eddc2c412b7613aebe1afaae826 100644 (file)
@@ -44,12 +44,17 @@ extern bt_value *bt_value_bool_create_init(bt_bool val);
 
 extern void bt_value_bool_set(bt_value *bool_obj, bt_bool val);
 
-extern bt_value *bt_value_integer_create(void);
+extern bt_value *bt_value_unsigned_integer_create(void);
 
-extern bt_value *bt_value_integer_create_init(
-               int64_t val);
+extern bt_value *bt_value_unsigned_integer_create_init(uint64_t val);
 
-extern void bt_value_integer_set(bt_value *integer_obj, int64_t val);
+extern void bt_value_unsigned_integer_set(bt_value *integer_obj, uint64_t val);
+
+extern bt_value *bt_value_signed_integer_create(void);
+
+extern bt_value *bt_value_signed_integer_create_init(int64_t val);
+
+extern void bt_value_signed_integer_set(bt_value *integer_obj, int64_t val);
 
 extern bt_value *bt_value_real_create(void);
 
@@ -76,7 +81,10 @@ extern bt_value_status bt_value_array_append_element(
 extern bt_value_status bt_value_array_append_bool_element(
                bt_value *array_obj, bt_bool val);
 
-extern bt_value_status bt_value_array_append_integer_element(
+extern bt_value_status bt_value_array_append_unsigned_integer_element(
+               bt_value *array_obj, uint64_t val);
+
+extern bt_value_status bt_value_array_append_signed_integer_element(
                bt_value *array_obj, int64_t val);
 
 extern bt_value_status bt_value_array_append_real_element(
@@ -114,7 +122,10 @@ extern bt_value_status bt_value_map_insert_entry(
 extern bt_value_status bt_value_map_insert_bool_entry(
                bt_value *map_obj, const char *key, bt_bool val);
 
-extern bt_value_status bt_value_map_insert_integer_entry(
+extern bt_value_status bt_value_map_insert_unsigned_integer_entry(
+               bt_value *map_obj, const char *key, uint64_t val);
+
+extern bt_value_status bt_value_map_insert_signed_integer_entry(
                bt_value *map_obj, const char *key, int64_t val);
 
 extern bt_value_status bt_value_map_insert_real_entry(
index 7e897fa38e457c3ae7ba1321662d6b6028dd965c..657363edb27d3c21dae41a57e8fa03fc4d2090cb 100644 (file)
@@ -819,11 +819,16 @@ static inline void format_value(char **buf_ch, bool extended,
                BUF_APPEND(", %svalue=%d", PRFIELD(val));
                break;
        }
-       case BT_VALUE_TYPE_INTEGER:
+       case BT_VALUE_TYPE_UNSIGNED_INTEGER:
        {
-               int64_t val = bt_value_integer_get(value);
-
-               BUF_APPEND(", %svalue=%" PRId64, PRFIELD(val));
+               BUF_APPEND(", %svalue=%" PRIu64,
+                       PRFIELD(bt_value_unsigned_integer_get(value)));
+               break;
+       }
+       case BT_VALUE_TYPE_SIGNED_INTEGER:
+       {
+               BUF_APPEND(", %svalue=%" PRId64,
+                       PRFIELD(bt_value_signed_integer_get(value)));
                break;
        }
        case BT_VALUE_TYPE_REAL:
index 3aa398fb94904744f0906925bfdbbe457c3ea76a..64a057b56a42be7dc640ec934f069e4cc0ca9104 100644 (file)
@@ -337,7 +337,7 @@ enum bt_trace_class_status bt_trace_class_set_environment_entry_integer(
        struct bt_value *value_obj;
        BT_ASSERT_PRE_NON_NULL(tc, "Trace class");
        BT_ASSERT_PRE_NON_NULL(name, "Name");
-       value_obj = bt_value_integer_create_init(value);
+       value_obj = bt_value_signed_integer_create_init(value);
        if (!value_obj) {
                BT_LOGE_STR("Cannot create an integer value object.");
                ret = BT_TRACE_CLASS_STATUS_NOMEM;
index 6e33ae7b23e5ee8d2c97ea596fe356fb3bf499ee..bf07dc8ccef88ed6a28f1281fe7ff2a0701dc8a1 100644 (file)
@@ -116,13 +116,14 @@ void bt_value_map_destroy(struct bt_value *object)
 
 static
 void (* const destroy_funcs[])(struct bt_value *) = {
-       [BT_VALUE_TYPE_NULL] =          NULL,
-       [BT_VALUE_TYPE_BOOL] =          NULL,
-       [BT_VALUE_TYPE_INTEGER] =       NULL,
-       [BT_VALUE_TYPE_REAL] =          NULL,
-       [BT_VALUE_TYPE_STRING] =        bt_value_string_destroy,
-       [BT_VALUE_TYPE_ARRAY] =         bt_value_array_destroy,
-       [BT_VALUE_TYPE_MAP] =           bt_value_map_destroy,
+       [BT_VALUE_TYPE_NULL] =                  NULL,
+       [BT_VALUE_TYPE_BOOL] =                  NULL,
+       [BT_VALUE_TYPE_UNSIGNED_INTEGER] =      NULL,
+       [BT_VALUE_TYPE_SIGNED_INTEGER] =        NULL,
+       [BT_VALUE_TYPE_REAL] =                  NULL,
+       [BT_VALUE_TYPE_STRING] =                bt_value_string_destroy,
+       [BT_VALUE_TYPE_ARRAY] =                 bt_value_array_destroy,
+       [BT_VALUE_TYPE_MAP] =                   bt_value_map_destroy,
 };
 
 static
@@ -138,12 +139,16 @@ struct bt_value *bt_value_bool_copy(const struct bt_value *bool_obj)
                BT_VALUE_TO_BOOL(bool_obj)->value);
 }
 
+static inline
+struct bt_value *bt_value_integer_create_init(enum bt_value_type type,
+               uint64_t uval);
+
 static
 struct bt_value *bt_value_integer_copy(
                const struct bt_value *integer_obj)
 {
-       return bt_value_integer_create_init(
-               BT_VALUE_TO_INTEGER(integer_obj)->value);
+       return bt_value_integer_create_init(integer_obj->type,
+               BT_VALUE_TO_INTEGER(integer_obj)->value.u);
 }
 
 static
@@ -267,13 +272,14 @@ end:
 
 static
 struct bt_value *(* const copy_funcs[])(const struct bt_value *) = {
-       [BT_VALUE_TYPE_NULL] =          bt_value_null_copy,
-       [BT_VALUE_TYPE_BOOL] =          bt_value_bool_copy,
-       [BT_VALUE_TYPE_INTEGER] =       bt_value_integer_copy,
-       [BT_VALUE_TYPE_REAL] =          bt_value_real_copy,
-       [BT_VALUE_TYPE_STRING] =        bt_value_string_copy,
-       [BT_VALUE_TYPE_ARRAY] =         bt_value_array_copy,
-       [BT_VALUE_TYPE_MAP] =           bt_value_map_copy,
+       [BT_VALUE_TYPE_NULL] =                  bt_value_null_copy,
+       [BT_VALUE_TYPE_BOOL] =                  bt_value_bool_copy,
+       [BT_VALUE_TYPE_UNSIGNED_INTEGER] =      bt_value_integer_copy,
+       [BT_VALUE_TYPE_SIGNED_INTEGER] =        bt_value_integer_copy,
+       [BT_VALUE_TYPE_REAL] =                  bt_value_real_copy,
+       [BT_VALUE_TYPE_STRING] =                bt_value_string_copy,
+       [BT_VALUE_TYPE_ARRAY] =                 bt_value_array_copy,
+       [BT_VALUE_TYPE_MAP] =                   bt_value_map_copy,
 };
 
 static
@@ -308,12 +314,20 @@ static
 bt_bool bt_value_integer_compare(const struct bt_value *object_a,
                const struct bt_value *object_b)
 {
-       if (BT_VALUE_TO_INTEGER(object_a)->value !=
-                       BT_VALUE_TO_INTEGER(object_b)->value) {
-               BT_LOGV("Integer value objects are different: "
-                       "int-a-val=%" PRId64 ", int-b-val=%" PRId64,
-                       BT_VALUE_TO_INTEGER(object_a)->value,
-                       BT_VALUE_TO_INTEGER(object_b)->value);
+       if (BT_VALUE_TO_INTEGER(object_a)->value.u !=
+                       BT_VALUE_TO_INTEGER(object_b)->value.u) {
+               if (object_a->type == BT_VALUE_TYPE_UNSIGNED_INTEGER) {
+                       BT_LOGV("Unsigned integer value objects are different: "
+                               "int-a-val=%" PRIu64 ", int-b-val=%" PRIu64,
+                               BT_VALUE_TO_INTEGER(object_a)->value.u,
+                               BT_VALUE_TO_INTEGER(object_b)->value.u);
+               } else {
+                       BT_LOGV("Signed integer value objects are different: "
+                               "int-a-val=%" PRId64 ", int-b-val=%" PRId64,
+                               BT_VALUE_TO_INTEGER(object_a)->value.i,
+                               BT_VALUE_TO_INTEGER(object_b)->value.i);
+               }
+
                return BT_FALSE;
        }
 
@@ -441,13 +455,14 @@ end:
 static
 bt_bool (* const compare_funcs[])(const struct bt_value *,
                const struct bt_value *) = {
-       [BT_VALUE_TYPE_NULL] =          bt_value_null_compare,
-       [BT_VALUE_TYPE_BOOL] =          bt_value_bool_compare,
-       [BT_VALUE_TYPE_INTEGER] =       bt_value_integer_compare,
-       [BT_VALUE_TYPE_REAL] =          bt_value_real_compare,
-       [BT_VALUE_TYPE_STRING] =        bt_value_string_compare,
-       [BT_VALUE_TYPE_ARRAY] =         bt_value_array_compare,
-       [BT_VALUE_TYPE_MAP] =           bt_value_map_compare,
+       [BT_VALUE_TYPE_NULL] =                  bt_value_null_compare,
+       [BT_VALUE_TYPE_BOOL] =                  bt_value_bool_compare,
+       [BT_VALUE_TYPE_UNSIGNED_INTEGER] =      bt_value_integer_compare,
+       [BT_VALUE_TYPE_SIGNED_INTEGER] =        bt_value_integer_compare,
+       [BT_VALUE_TYPE_REAL] =                  bt_value_real_compare,
+       [BT_VALUE_TYPE_STRING] =                bt_value_string_compare,
+       [BT_VALUE_TYPE_ARRAY] =                 bt_value_array_compare,
+       [BT_VALUE_TYPE_MAP] =                   bt_value_map_compare,
 };
 
 static
@@ -493,13 +508,14 @@ void bt_value_map_freeze(struct bt_value *object)
 
 static
 void (* const freeze_funcs[])(struct bt_value *) = {
-       [BT_VALUE_TYPE_NULL] =          bt_value_null_freeze,
-       [BT_VALUE_TYPE_BOOL] =          bt_value_generic_freeze,
-       [BT_VALUE_TYPE_INTEGER] =       bt_value_generic_freeze,
-       [BT_VALUE_TYPE_REAL] =          bt_value_generic_freeze,
-       [BT_VALUE_TYPE_STRING] =        bt_value_generic_freeze,
-       [BT_VALUE_TYPE_ARRAY] =         bt_value_array_freeze,
-       [BT_VALUE_TYPE_MAP] =           bt_value_map_freeze,
+       [BT_VALUE_TYPE_NULL] =                  bt_value_null_freeze,
+       [BT_VALUE_TYPE_BOOL] =                  bt_value_generic_freeze,
+       [BT_VALUE_TYPE_UNSIGNED_INTEGER] =      bt_value_generic_freeze,
+       [BT_VALUE_TYPE_SIGNED_INTEGER] =        bt_value_generic_freeze,
+       [BT_VALUE_TYPE_REAL] =                  bt_value_generic_freeze,
+       [BT_VALUE_TYPE_STRING] =                bt_value_generic_freeze,
+       [BT_VALUE_TYPE_ARRAY] =                 bt_value_array_freeze,
+       [BT_VALUE_TYPE_MAP] =                   bt_value_map_freeze,
 };
 
 static
@@ -582,29 +598,59 @@ struct bt_value *bt_value_bool_create(void)
        return bt_value_bool_create_init(BT_FALSE);
 }
 
-struct bt_value *bt_value_integer_create_init(int64_t val)
+static inline
+struct bt_value *bt_value_integer_create_init(enum bt_value_type type,
+               uint64_t uval)
 {
        struct bt_value_integer *integer_obj;
 
-       BT_LOGD("Creating integer value object: val=%" PRId64, val);
+       BT_ASSERT(type == BT_VALUE_TYPE_UNSIGNED_INTEGER ||
+               type == BT_VALUE_TYPE_SIGNED_INTEGER);
+
+       if (type == BT_VALUE_TYPE_UNSIGNED_INTEGER) {
+               BT_LOGD("Creating unsigned integer value object: val=%" PRIu64,
+                       uval);
+       } else {
+               BT_LOGD("Creating signed integer value object: val=%" PRId64,
+                       (int64_t) uval);
+       }
+
        integer_obj = g_new0(struct bt_value_integer, 1);
        if (!integer_obj) {
                BT_LOGE_STR("Failed to allocate one integer value object.");
                goto end;
        }
 
-       integer_obj->base = bt_value_create_base(BT_VALUE_TYPE_INTEGER);
-       integer_obj->value = val;
-       BT_LOGD("Created integer value object: addr=%p",
+       integer_obj->base = bt_value_create_base(type);
+       integer_obj->value.u = uval;
+       BT_LOGD("Created %ssigned integer value object: addr=%p",
+               type == BT_VALUE_TYPE_UNSIGNED_INTEGER ? "un" : "",
                integer_obj);
 
 end:
        return (void *) integer_obj;
 }
 
-struct bt_value *bt_value_integer_create(void)
+struct bt_value *bt_value_unsigned_integer_create_init(uint64_t val)
+{
+       return bt_value_integer_create_init(BT_VALUE_TYPE_UNSIGNED_INTEGER,
+               val);
+}
+
+struct bt_value *bt_value_unsigned_integer_create(void)
+{
+       return bt_value_unsigned_integer_create_init(0);
+}
+
+struct bt_value *bt_value_signed_integer_create_init(int64_t val)
+{
+       return bt_value_integer_create_init(BT_VALUE_TYPE_SIGNED_INTEGER,
+               (uint64_t) val);
+}
+
+struct bt_value *bt_value_signed_integer_create(void)
 {
-       return bt_value_integer_create_init(0);
+       return bt_value_signed_integer_create_init(0);
 }
 
 struct bt_value *bt_value_real_create_init(double val)
@@ -742,22 +788,47 @@ void bt_value_bool_set(struct bt_value *bool_obj, bt_bool val)
                bool_obj, val);
 }
 
-int64_t bt_value_integer_get(const struct bt_value *integer_obj)
+uint64_t bt_value_unsigned_integer_get(const struct bt_value *integer_obj)
+{
+       BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
+       BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj,
+               BT_VALUE_TYPE_UNSIGNED_INTEGER);
+       return BT_VALUE_TO_INTEGER(integer_obj)->value.u;
+}
+
+int64_t bt_value_signed_integer_get(const struct bt_value *integer_obj)
 {
        BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
-       BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_VALUE_TYPE_INTEGER);
-       return BT_VALUE_TO_INTEGER(integer_obj)->value;
+       BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj,
+               BT_VALUE_TYPE_SIGNED_INTEGER);
+       return BT_VALUE_TO_INTEGER(integer_obj)->value.i;
 }
 
+static inline
 void bt_value_integer_set(struct bt_value *integer_obj,
-               int64_t val)
+               enum bt_value_type expected_type, uint64_t uval)
 {
        BT_ASSERT_PRE_NON_NULL(integer_obj, "Value object");
-       BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, BT_VALUE_TYPE_INTEGER);
+       BT_ASSERT_PRE_VALUE_IS_TYPE(integer_obj, expected_type);
        BT_ASSERT_PRE_VALUE_HOT(integer_obj, "Value object");
-       BT_VALUE_TO_INTEGER(integer_obj)->value = val;
-       BT_LOGV("Set integer value's raw value: value-addr=%p, value=%" PRId64,
-               integer_obj, val);
+       BT_VALUE_TO_INTEGER(integer_obj)->value.u = uval;
+}
+
+void bt_value_unsigned_integer_set(struct bt_value *integer_obj,
+               uint64_t val)
+{
+       bt_value_integer_set(integer_obj, BT_VALUE_TYPE_UNSIGNED_INTEGER, val);
+       BT_LOGV("Set unsigned integer value's raw value: "
+               "value-addr=%p, value=%" PRIu64, integer_obj, val);
+}
+
+void bt_value_signed_integer_set(struct bt_value *integer_obj,
+               int64_t val)
+{
+       bt_value_integer_set(integer_obj, BT_VALUE_TYPE_SIGNED_INTEGER,
+               (uint64_t) val);
+       BT_LOGV("Set signed integer value's raw value: "
+               "value-addr=%p, value=%" PRId64, integer_obj, val);
 }
 
 double bt_value_real_get(const struct bt_value *real_obj)
@@ -856,13 +927,26 @@ enum bt_value_status bt_value_array_append_bool_element(
        return ret;
 }
 
-enum bt_value_status bt_value_array_append_integer_element(
+enum bt_value_status bt_value_array_append_unsigned_integer_element(
+               struct bt_value *array_obj, uint64_t val)
+{
+       enum bt_value_status ret;
+       struct bt_value *integer_obj = NULL;
+
+       integer_obj = bt_value_unsigned_integer_create_init(val);
+       ret = bt_value_array_append_element(array_obj,
+               (void *) integer_obj);
+       bt_object_put_ref(integer_obj);
+       return ret;
+}
+
+enum bt_value_status bt_value_array_append_signed_integer_element(
                struct bt_value *array_obj, int64_t val)
 {
        enum bt_value_status ret;
        struct bt_value *integer_obj = NULL;
 
-       integer_obj = bt_value_integer_create_init(val);
+       integer_obj = bt_value_signed_integer_create_init(val);
        ret = bt_value_array_append_element(array_obj,
                (void *) integer_obj);
        bt_object_put_ref(integer_obj);
@@ -1006,13 +1090,26 @@ enum bt_value_status bt_value_map_insert_bool_entry(
        return ret;
 }
 
-enum bt_value_status bt_value_map_insert_integer_entry(
+enum bt_value_status bt_value_map_insert_unsigned_integer_entry(
+               struct bt_value *map_obj, const char *key, uint64_t val)
+{
+       enum bt_value_status ret;
+       struct bt_value *integer_obj = NULL;
+
+       integer_obj = bt_value_unsigned_integer_create_init(val);
+       ret = bt_value_map_insert_entry(map_obj, key,
+               (void *) integer_obj);
+       bt_object_put_ref(integer_obj);
+       return ret;
+}
+
+enum bt_value_status bt_value_map_insert_signed_integer_entry(
                struct bt_value *map_obj, const char *key, int64_t val)
 {
        enum bt_value_status ret;
        struct bt_value *integer_obj = NULL;
 
-       integer_obj = bt_value_integer_create_init(val);
+       integer_obj = bt_value_signed_integer_create_init(val);
        ret = bt_value_map_insert_entry(map_obj, key,
                (void *) integer_obj);
        bt_object_put_ref(integer_obj);
index c6989ccc0929fee1c65d95430f4376caff6d8ed9..f01787747f60215dedb3d4ed7af70b0de7ca7e63 100644 (file)
@@ -166,20 +166,22 @@ int append_lttng_trace_path_ust_uid(GString *path, const bt_trace_class *tc)
        int ret;
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_buffering_id");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"tracer_buffering_id\"");
                goto error;
        }
 
-       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64, bt_value_integer_get(v));
+       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRId64,
+               bt_value_signed_integer_get(v));
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "isa_length");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"isa_length\"");
                goto error;
        }
 
-       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRIu64 "-bit", bt_value_integer_get(v));
+       g_string_append_printf(path, G_DIR_SEPARATOR_S "%" PRIu64 "-bit",
+               bt_value_signed_integer_get(v));
 
        ret = 0;
        goto end;
@@ -207,12 +209,12 @@ int append_lttng_trace_path_ust_pid(GString *path, const bt_trace_class *tc)
        g_string_append_printf(path, G_DIR_SEPARATOR_S "%s", bt_value_string_get(v));
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"vpid\"");
                goto error;
        }
 
-       g_string_append_printf(path, "-%" PRId64, bt_value_integer_get(v));
+       g_string_append_printf(path, "-%" PRId64, bt_value_signed_integer_get(v));
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "vpid_datetime");
        if (!v || !bt_value_is_string(v)) {
@@ -273,20 +275,20 @@ GString *make_lttng_trace_path_rel(const struct fs_sink_trace *trace)
        }
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_major");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"tracer_major\"");
                goto error;
        }
 
-       tracer_major = bt_value_integer_get(v);
+       tracer_major = bt_value_signed_integer_get(v);
 
        v = bt_trace_class_borrow_environment_entry_value_by_name_const(tc, "tracer_minor");
-       if (!v || !bt_value_is_integer(v)) {
+       if (!v || !bt_value_is_signed_integer(v)) {
                BT_LOGD_STR("Couldn't get environment value: name=\"tracer_minor\"");
                goto error;
        }
 
-       tracer_minor = bt_value_integer_get(v);
+       tracer_minor = bt_value_signed_integer_get(v);
 
        if (!(tracer_major >= 3 || (tracer_major == 2 && tracer_minor >= 11))) {
                BT_LOGD("Unsupported LTTng version for automatic trace path: major=%" PRId64 ", minor=%" PRId64,
index efc02b305850d1a441b7f9e85feceaeb50bf804c..c148caea410f11972f1969d693df68015bdbf692 100644 (file)
@@ -867,9 +867,9 @@ void translate_trace_class_ctf_ir_to_tsdl(struct fs_sink_ctf_trace_class *tc,
                        g_string_append_printf(tsdl, "%s = ", name);
 
                        switch (bt_value_get_type(val)) {
-                       case BT_VALUE_TYPE_INTEGER:
+                       case BT_VALUE_TYPE_SIGNED_INTEGER:
                                g_string_append_printf(tsdl, "%" PRId64,
-                                       bt_value_integer_get(val));
+                                       bt_value_signed_integer_get(val));
                                break;
                        case BT_VALUE_TYPE_STRING:
                                append_quoted_string(&ctx, bt_value_string_get(val));
index 699b3a5b620d9bb6abb81994704285662f6819f6..69c20c6142e169cf61585621f99c2a7651611120 100644 (file)
@@ -1277,7 +1277,7 @@ struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
                }
 
                switch (bt_value_get_type(val)) {
-               case BT_VALUE_TYPE_INTEGER:
+               case BT_VALUE_TYPE_SIGNED_INTEGER:
                case BT_VALUE_TYPE_STRING:
                        break;
                default:
index 6672071fee6f2cac65851bc5500a452932057e68..7d2fb08be147c3a0f35beb95b995f8d1418890d1 100644 (file)
@@ -1720,24 +1720,24 @@ bool read_src_fs_parameters(const bt_value *params,
        value = bt_value_map_borrow_entry_value_const(params,
                "clock-class-offset-s");
        if (value) {
-               if (!bt_value_is_integer(value)) {
+               if (!bt_value_is_signed_integer(value)) {
                        BT_LOGE("clock-class-offset-s must be an integer");
                        goto error;
                }
                ctf_fs->metadata_config.clock_class_offset_s =
-                       bt_value_integer_get(value);
+                       bt_value_signed_integer_get(value);
        }
 
        /* clock-class-offset-ns parameter */
        value = bt_value_map_borrow_entry_value_const(params,
                "clock-class-offset-ns");
        if (value) {
-               if (!bt_value_is_integer(value)) {
+               if (!bt_value_is_signed_integer(value)) {
                        BT_LOGE("clock-class-offset-ns must be an integer");
                        goto error;
                }
                ctf_fs->metadata_config.clock_class_offset_ns =
-                       bt_value_integer_get(value);
+                       bt_value_signed_integer_get(value);
        }
 
 
index d632d42d51d76c199b0db561580c2c94b0ce6d3b..e7746f4573de2c0c1028ff41866b6079484bfaa8 100644 (file)
@@ -211,14 +211,14 @@ int add_range(bt_value *info, struct range *range,
                goto end;
        }
 
-       status = bt_value_map_insert_integer_entry(range_map, "begin",
+       status = bt_value_map_insert_signed_integer_entry(range_map, "begin",
                        range->begin_ns);
        if (status != BT_VALUE_STATUS_OK) {
                ret = -1;
                goto end;
        }
 
-       status = bt_value_map_insert_integer_entry(range_map, "end",
+       status = bt_value_map_insert_signed_integer_entry(range_map, "end",
                        range->end_ns);
        if (status != BT_VALUE_STATUS_OK) {
                ret = -1;
@@ -244,16 +244,16 @@ int add_stream_ids(bt_value *info, struct ctf_fs_ds_file_group *ds_file_group)
        bt_value_status status;
 
        if (ds_file_group->stream_id != UINT64_C(-1)) {
-               status = bt_value_map_insert_integer_entry(info, "id",
-                       (int64_t) ds_file_group->stream_id);
+               status = bt_value_map_insert_unsigned_integer_entry(info, "id",
+                       ds_file_group->stream_id);
                if (status != BT_VALUE_STATUS_OK) {
                        ret = -1;
                        goto end;
                }
        }
 
-       status = bt_value_map_insert_integer_entry(info, "class-id",
-               (int64_t) ds_file_group->sc->id);
+       status = bt_value_map_insert_unsigned_integer_entry(info, "class-id",
+               ds_file_group->sc->id);
        if (status != BT_VALUE_STATUS_OK) {
                ret = -1;
                goto end;
index b37db12ec46e2f9a0f464658b71e7e63a0440692..ec9dba29d3e9f8246325bec90fa4c73ab1478165 100644 (file)
@@ -360,10 +360,10 @@ int list_update_session(bt_value *results,
                                ret = -1;
                                goto end;
                        }
-                       val = bt_value_integer_get(btval);
+                       val = bt_value_signed_integer_get(btval);
                        /* sum */
                        val += streams;
-                       bt_value_integer_set(btval, val);
+                       bt_value_signed_integer_set(btval, val);
 
                        btval = bt_value_map_borrow_entry_value(map, "client-count");
                        if (!btval) {
@@ -371,10 +371,10 @@ int list_update_session(bt_value *results,
                                ret = -1;
                                goto end;
                        }
-                       val = bt_value_integer_get(btval);
+                       val = bt_value_signed_integer_get(btval);
                        /* max */
                        val = max_t(int64_t, clients, val);
-                       bt_value_integer_set(btval, val);
+                       bt_value_signed_integer_set(btval, val);
                }
 
                if (found) {
@@ -466,8 +466,8 @@ int list_append_session(bt_value *results,
        {
                uint32_t live_timer = be32toh(session->live_timer);
 
-               ret_status = bt_value_map_insert_integer_entry(map, "timer-us",
-                       live_timer);
+               ret_status = bt_value_map_insert_signed_integer_entry(
+                       map, "timer-us", live_timer);
                if (ret_status != BT_VALUE_STATUS_OK) {
                        BT_LOGE_STR("Error inserting \"timer-us\" entry.");
                        ret = -1;
@@ -482,8 +482,8 @@ int list_append_session(bt_value *results,
        {
                uint32_t streams = be32toh(session->streams);
 
-               ret_status = bt_value_map_insert_integer_entry(map, "stream-count",
-                       streams);
+               ret_status = bt_value_map_insert_signed_integer_entry(map,
+                       "stream-count", streams);
                if (ret_status != BT_VALUE_STATUS_OK) {
                        BT_LOGE_STR("Error inserting \"stream-count\" entry.");
                        ret = -1;
@@ -498,8 +498,8 @@ int list_append_session(bt_value *results,
        {
                uint32_t clients = be32toh(session->clients);
 
-               ret_status = bt_value_map_insert_integer_entry(map, "client-count",
-                       clients);
+               ret_status = bt_value_map_insert_signed_integer_entry(map,
+                       "client-count", clients);
                if (ret_status != BT_VALUE_STATUS_OK) {
                        BT_LOGE_STR("Error inserting \"client-count\" entry.");
                        ret = -1;
index 7e9b81e2c08d08a04bb8ef05692fafc32a16c4c2..bdcc18ca8760ac357bef378d0597d698ecb8da09 100644 (file)
@@ -81,11 +81,12 @@ int copy_trace_class_content(const bt_trace_class *in_trace_class,
                BT_ASSERT(value_name);
                BT_ASSERT(value);
 
-               if (bt_value_is_integer(value)) {
+               if (bt_value_is_signed_integer(value)) {
                        trace_class_status =
                                bt_trace_class_set_environment_entry_integer(
                                                out_trace_class, value_name,
-                                               bt_value_integer_get(value));
+                                               bt_value_signed_integer_get(
+                                                       value));
                } else if (bt_value_is_string(value)) {
                        trace_class_status =
                                bt_trace_class_set_environment_entry_string(
index 0d69b9bcd1f9018869330f85aaddd29d87b90060..95189d5e2fda7df18fea904cf87d6d2d4a173248 100644 (file)
@@ -416,7 +416,7 @@ int print_event_header(struct pretty_component *pretty,
                        } else if (dom_print) {
                                g_string_append(pretty->string, ":");
                        }
-                       value = bt_value_integer_get(vpid_value);
+                       value = bt_value_signed_integer_get(vpid_value);
                        g_string_append_printf(pretty->string,
                                "(%" PRId64 ")", value);
                        dom_print = 1;
index 10cf55054f875d83c68f0a67bd7b4d0a236fab81..789df18643466e732468a82a1615aab33c85ae68 100644 (file)
@@ -1,4 +1,8 @@
 AM_CPPFLAGS += -I$(top_srcdir)/plugins
 
 noinst_LTLIBRARIES = libbabeltrace-plugin-counter-cc.la
-libbabeltrace_plugin_counter_cc_la_SOURCES = counter.c counter.h
+libbabeltrace_plugin_counter_cc_la_SOURCES = \
+       counter.c \
+       counter.h \
+       logging.c \
+       logging.h
index 97bed28d4ab8abbc5c20496ab64462eaa39f3884..fea90c339b7e7f4194c073cf0f5d277561c3e7ad 100644 (file)
@@ -20,6 +20,9 @@
  * SOFTWARE.
  */
 
+#define BT_LOG_TAG "PLUGIN-UTILS-COUNTER-FLT"
+#include "logging.h"
+
 #include <babeltrace/babeltrace.h>
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/common-internal.h>
@@ -157,21 +160,27 @@ bt_self_component_status counter_init(
        counter->last_printed_total = -1ULL;
        counter->step = 10000;
        step = bt_value_map_borrow_entry_value_const(params, "step");
-       if (step && bt_value_is_integer(step)) {
-               int64_t val;
-
-               val = bt_value_integer_get(step);
-               if (val >= 0) {
-                       counter->step = (uint64_t) val;
+       if (step) {
+               if (!bt_value_is_unsigned_integer(step)) {
+                       BT_LOGE("`step` parameter: expecting an unsigned integer value: "
+                               "type=%s", bt_common_value_type_string(
+                                       bt_value_get_type(step)));
+                       goto error;
                }
+
+               counter->step = bt_value_unsigned_integer_get(step);
        }
 
        hide_zero = bt_value_map_borrow_entry_value_const(params, "hide-zero");
-       if (hide_zero && bt_value_is_bool(hide_zero)) {
-               bt_bool val;
+       if (hide_zero) {
+               if (!bt_value_is_bool(hide_zero)) {
+                       BT_LOGE("`hide-zero` parameter: expecting a boolean value: "
+                               "type=%s", bt_common_value_type_string(
+                                       bt_value_get_type(hide_zero)));
+                       goto error;
+               }
 
-               val = bt_value_bool_get(hide_zero);
-               counter->hide_zero = (bool) val;
+               counter->hide_zero = (bool) bt_value_bool_get(hide_zero);
        }
 
        bt_self_component_set_data(
@@ -181,6 +190,7 @@ bt_self_component_status counter_init(
 
 error:
        destroy_private_counter_data(counter);
+       ret = BT_SELF_COMPONENT_STATUS_ERROR;
 
 end:
        return ret;
diff --git a/plugins/utils/counter/logging.c b/plugins/utils/counter/logging.c
new file mode 100644 (file)
index 0000000..ff3e9c2
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_utils_counter_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_INIT_LOG_LEVEL(bt_plugin_utils_counter_log_level,
+       "BABELTRACE_FLT_UTILS_COUNTER_LOG_LEVEL");
diff --git a/plugins/utils/counter/logging.h b/plugins/utils/counter/logging.h
new file mode 100644 (file)
index 0000000..3c9dd65
--- /dev/null
@@ -0,0 +1,31 @@
+#ifndef PLUGINS_UTILS_MUXER_LOGGING_H
+#define PLUGINS_UTILS_MUXER_LOGGING_H
+
+/*
+ * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#define BT_LOG_OUTPUT_LEVEL bt_plugin_utils_muxer_log_level
+#include <babeltrace/logging-internal.h>
+
+BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_utils_muxer_log_level);
+
+#endif /* PLUGINS_UTILS_MUXER_LOGGING_H */
index ddf95b9d1845b5802f1fc673a8b0d25fbc365435..d9407bfda205e1341f8d3ed4186eab2bf0c30d7f 100644 (file)
@@ -358,8 +358,8 @@ int set_bound_from_param(const char *param_name, const bt_value *param,
        const char *arg;
        char tmp_arg[64];
 
-       if (bt_value_is_integer(param)) {
-               int64_t value = bt_value_integer_get(param);
+       if (bt_value_is_signed_integer(param)) {
+               int64_t value = bt_value_signed_integer_get(param);
 
                /*
                 * Just convert it to a temporary string to handle
index 6628e0450f11d8c15be8d37c0d5034afcdab343e..d0e5c38a714304d0e253558d5fe20cd0578b3fb9 100644 (file)
@@ -170,7 +170,7 @@ class _TestNumericValue(_TestCopySimple):
         # the current value of `int_value_obj`, so after this the value
         # of the object is 5. This does not compare to 5.3, which is
         # why we also use the `int()` type here.
-        if type(self._def) is bt2.IntegerValue:
+        if isinstance(self._def, bt2._IntegerValue):
             rv = int(rv)
 
         self.assertEqual(r, rv)
@@ -576,7 +576,7 @@ _UNARYOPS = (
 )
 
 
-def _inject_numeric_testing_methods(cls):
+def _inject_numeric_testing_methods(cls, has_neg=True):
     def test_binop_name(suffix):
         return 'test_binop_{}_{}'.format(name, suffix)
 
@@ -588,7 +588,6 @@ def _inject_numeric_testing_methods(cls):
 
     # inject testing methods for each binary operation
     for name, binop in _BINOPS:
-
         setattr(cls, test_binop_name('invalid_unknown'), partialmethod(_TestNumericValue._test_binop_invalid_unknown, op=binop))
         setattr(cls, test_binop_name('invalid_none'), partialmethod(_TestNumericValue._test_binop_invalid_none, op=binop))
         setattr(cls, test_binop_name('type_true'), partialmethod(_TestNumericValue._test_binop_type_true, op=binop))
@@ -603,14 +602,17 @@ def _inject_numeric_testing_methods(cls):
         setattr(cls, test_binop_name('lhs_value_same_true'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_true, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_pos_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_int, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_pos_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vint, op=binop))
-        setattr(cls, test_binop_name('type_neg_int'), partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop))
-        setattr(cls, test_binop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop))
-        setattr(cls, test_binop_name('value_neg_int'), partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop))
-        setattr(cls, test_binop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop))
-        setattr(cls, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop))
-        setattr(cls, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop))
-        setattr(cls, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop))
-        setattr(cls, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop))
+
+        if has_neg:
+            setattr(cls, test_binop_name('type_neg_int'), partialmethod(_TestNumericValue._test_binop_type_neg_int, op=binop))
+            setattr(cls, test_binop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_binop_type_neg_vint, op=binop))
+            setattr(cls, test_binop_name('value_neg_int'), partialmethod(_TestNumericValue._test_binop_value_neg_int, op=binop))
+            setattr(cls, test_binop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_binop_value_neg_vint, op=binop))
+            setattr(cls, test_binop_name('lhs_addr_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_int, op=binop))
+            setattr(cls, test_binop_name('lhs_addr_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vint, op=binop))
+            setattr(cls, test_binop_name('lhs_value_same_neg_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_int, op=binop))
+            setattr(cls, test_binop_name('lhs_value_same_neg_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vint, op=binop))
+
         setattr(cls, test_binop_name('type_false'), partialmethod(_TestNumericValue._test_binop_type_false, op=binop))
         setattr(cls, test_binop_name('type_zero_int'), partialmethod(_TestNumericValue._test_binop_type_zero_int, op=binop))
         setattr(cls, test_binop_name('type_zero_vint'), partialmethod(_TestNumericValue._test_binop_type_zero_vint, op=binop))
@@ -623,22 +625,25 @@ def _inject_numeric_testing_methods(cls):
         setattr(cls, test_binop_name('lhs_value_same_false'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_false, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_zero_int'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_int, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_zero_vint'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_zero_vint, op=binop))
+
+        if has_neg:
+            setattr(cls, test_binop_name('type_neg_float'), partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop))
+            setattr(cls, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop))
+            setattr(cls, test_binop_name('value_neg_float'), partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop))
+            setattr(cls, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop))
+            setattr(cls, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop))
+            setattr(cls, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop))
+            setattr(cls, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop))
+            setattr(cls, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop))
+
         setattr(cls, test_binop_name('type_pos_float'), partialmethod(_TestNumericValue._test_binop_type_pos_float, op=binop))
-        setattr(cls, test_binop_name('type_neg_float'), partialmethod(_TestNumericValue._test_binop_type_neg_float, op=binop))
         setattr(cls, test_binop_name('type_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_type_pos_vfloat, op=binop))
-        setattr(cls, test_binop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_type_neg_vfloat, op=binop))
         setattr(cls, test_binop_name('value_pos_float'), partialmethod(_TestNumericValue._test_binop_value_pos_float, op=binop))
-        setattr(cls, test_binop_name('value_neg_float'), partialmethod(_TestNumericValue._test_binop_value_neg_float, op=binop))
         setattr(cls, test_binop_name('value_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_value_pos_vfloat, op=binop))
-        setattr(cls, test_binop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_value_neg_vfloat, op=binop))
         setattr(cls, test_binop_name('lhs_addr_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_float, op=binop))
-        setattr(cls, test_binop_name('lhs_addr_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_float, op=binop))
         setattr(cls, test_binop_name('lhs_addr_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_pos_vfloat, op=binop))
-        setattr(cls, test_binop_name('lhs_addr_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_addr_same_neg_vfloat, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_pos_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_float, op=binop))
-        setattr(cls, test_binop_name('lhs_value_same_neg_float'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_float, op=binop))
         setattr(cls, test_binop_name('lhs_value_same_pos_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_pos_vfloat, op=binop))
-        setattr(cls, test_binop_name('lhs_value_same_neg_vfloat'), partialmethod(_TestNumericValue._test_binop_lhs_value_same_neg_vfloat, op=binop))
         setattr(cls, test_binop_name('type_zero_float'), partialmethod(_TestNumericValue._test_binop_type_zero_float, op=binop))
         setattr(cls, test_binop_name('type_zero_vfloat'), partialmethod(_TestNumericValue._test_binop_type_zero_vfloat, op=binop))
         setattr(cls, test_binop_name('value_zero_float'), partialmethod(_TestNumericValue._test_binop_value_zero_float, op=binop))
@@ -665,10 +670,13 @@ def _inject_numeric_testing_methods(cls):
         setattr(cls, test_ibinop_name('type_pos_vint'), partialmethod(_TestNumericValue._test_ibinop_type_pos_vint, op=ibinop))
         setattr(cls, test_ibinop_name('value_pos_int'), partialmethod(_TestNumericValue._test_ibinop_value_pos_int, op=ibinop))
         setattr(cls, test_ibinop_name('value_pos_vint'), partialmethod(_TestNumericValue._test_ibinop_value_pos_vint, op=ibinop))
-        setattr(cls, test_ibinop_name('type_neg_int'), partialmethod(_TestNumericValue._test_ibinop_type_neg_int, op=ibinop))
-        setattr(cls, test_ibinop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vint, op=ibinop))
-        setattr(cls, test_ibinop_name('value_neg_int'), partialmethod(_TestNumericValue._test_ibinop_value_neg_int, op=ibinop))
-        setattr(cls, test_ibinop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vint, op=ibinop))
+
+        if has_neg:
+            setattr(cls, test_ibinop_name('type_neg_int'), partialmethod(_TestNumericValue._test_ibinop_type_neg_int, op=ibinop))
+            setattr(cls, test_ibinop_name('type_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vint, op=ibinop))
+            setattr(cls, test_ibinop_name('value_neg_int'), partialmethod(_TestNumericValue._test_ibinop_value_neg_int, op=ibinop))
+            setattr(cls, test_ibinop_name('value_neg_vint'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vint, op=ibinop))
+
         setattr(cls, test_ibinop_name('type_false'), partialmethod(_TestNumericValue._test_ibinop_type_false, op=ibinop))
         setattr(cls, test_ibinop_name('value_false'), partialmethod(_TestNumericValue._test_ibinop_value_false, op=ibinop))
         setattr(cls, test_ibinop_name('type_zero_int'), partialmethod(_TestNumericValue._test_ibinop_type_zero_int, op=ibinop))
@@ -676,13 +684,16 @@ def _inject_numeric_testing_methods(cls):
         setattr(cls, test_ibinop_name('value_zero_int'), partialmethod(_TestNumericValue._test_ibinop_value_zero_int, op=ibinop))
         setattr(cls, test_ibinop_name('value_zero_vint'), partialmethod(_TestNumericValue._test_ibinop_value_zero_vint, op=ibinop))
         setattr(cls, test_ibinop_name('type_pos_float'), partialmethod(_TestNumericValue._test_ibinop_type_pos_float, op=ibinop))
-        setattr(cls, test_ibinop_name('type_neg_float'), partialmethod(_TestNumericValue._test_ibinop_type_neg_float, op=ibinop))
+
+        if has_neg:
+            setattr(cls, test_ibinop_name('type_neg_float'), partialmethod(_TestNumericValue._test_ibinop_type_neg_float, op=ibinop))
+            setattr(cls, test_ibinop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vfloat, op=ibinop))
+            setattr(cls, test_ibinop_name('value_neg_float'), partialmethod(_TestNumericValue._test_ibinop_value_neg_float, op=ibinop))
+            setattr(cls, test_ibinop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vfloat, op=ibinop))
+
         setattr(cls, test_ibinop_name('type_pos_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_pos_vfloat, op=ibinop))
-        setattr(cls, test_ibinop_name('type_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_neg_vfloat, op=ibinop))
         setattr(cls, test_ibinop_name('value_pos_float'), partialmethod(_TestNumericValue._test_ibinop_value_pos_float, op=ibinop))
-        setattr(cls, test_ibinop_name('value_neg_float'), partialmethod(_TestNumericValue._test_ibinop_value_neg_float, op=ibinop))
         setattr(cls, test_ibinop_name('value_pos_vfloat'), partialmethod(_TestNumericValue._test_ibinop_value_pos_vfloat, op=ibinop))
-        setattr(cls, test_ibinop_name('value_neg_vfloat'), partialmethod(_TestNumericValue._test_ibinop_value_neg_vfloat, op=ibinop))
         setattr(cls, test_ibinop_name('type_zero_float'), partialmethod(_TestNumericValue._test_ibinop_type_zero_float, op=ibinop))
         setattr(cls, test_ibinop_name('type_zero_vfloat'), partialmethod(_TestNumericValue._test_ibinop_type_zero_vfloat, op=ibinop))
         setattr(cls, test_ibinop_name('value_zero_float'), partialmethod(_TestNumericValue._test_ibinop_value_zero_float, op=ibinop))
@@ -707,13 +718,13 @@ class CreateValueFuncTestCase(unittest.TestCase):
     def test_create_int_pos(self):
         raw = 23
         v = bt2.create_value(raw)
-        self.assertIsInstance(v, bt2.IntegerValue)
+        self.assertIsInstance(v, bt2.SignedIntegerValue)
         self.assertEqual(v, raw)
 
     def test_create_int_neg(self):
         raw = -23
         v = bt2.create_value(raw)
-        self.assertIsInstance(v, bt2.IntegerValue)
+        self.assertIsInstance(v, bt2.SignedIntegerValue)
         self.assertEqual(v, raw)
 
     def test_create_float_pos(self):
@@ -883,19 +894,16 @@ class BoolValueTestCase(_TestCopySimple, unittest.TestCase):
         self.assertNotEqual(self._t, False)
 
 
-class IntegerValueTestCase(_TestNumericValue, unittest.TestCase):
+class _TestIntegerValue(_TestNumericValue):
     def setUp(self):
         self._pv = 23
-        self._nv = -52
-        self._ip = bt2.IntegerValue(self._pv)
-        self._in = bt2.IntegerValue(self._nv)
+        self._ip = self._CLS(self._pv)
         self._def = self._ip
         self._def_value = self._pv
-        self._def_new_value = -101
+        self._def_new_value = 101
 
     def tearDown(self):
         del self._ip
-        del self._in
         del self._def
         del self._def_value
 
@@ -909,7 +917,7 @@ class IntegerValueTestCase(_TestNumericValue, unittest.TestCase):
         return self.assertRaisesRegex(ValueError, r"expecting an unsigned 64-bit integral value")
 
     def test_create_default(self):
-        i = bt2.IntegerValue()
+        i = self._CLS()
         self.assertEqual(i, 0)
 
     def test_create_pos(self):
@@ -918,33 +926,25 @@ class IntegerValueTestCase(_TestNumericValue, unittest.TestCase):
     def test_create_neg(self):
         self.assertEqual(self._in, self._nv)
 
-    def test_create_pos_too_big(self):
-        with self._assert_expecting_int64():
-            i = bt2.IntegerValue(2 ** 63)
-
-    def test_create_neg_too_big(self):
-        with self._assert_expecting_int64():
-            i = bt2.IntegerValue(-(2 ** 63) - 1)
-
     def test_create_from_vint(self):
-        i = bt2.IntegerValue(self._ip)
+        i = self._CLS(self._ip)
         self.assertEqual(i, self._pv)
 
     def test_create_from_false(self):
-        i = bt2.IntegerValue(False)
+        i = self._CLS(False)
         self.assertFalse(i)
 
     def test_create_from_true(self):
-        i = bt2.IntegerValue(True)
+        i = self._CLS(True)
         self.assertTrue(i)
 
     def test_create_from_float(self):
-        i = bt2.IntegerValue(99.6)
+        i = self._CLS(99.6)
         self.assertEqual(i, 99)
 
     def test_create_from_vfloat(self):
         f = bt2.create_value(17.5)
-        i = bt2.IntegerValue(f)
+        i = self._CLS(f)
         self.assertEqual(i, 17)
 
     def test_create_from_unknown(self):
@@ -952,11 +952,11 @@ class IntegerValueTestCase(_TestNumericValue, unittest.TestCase):
             pass
 
         with self._assert_expecting_int():
-            i = bt2.IntegerValue(A())
+            i = self._CLS(A())
 
     def test_create_from_varray(self):
         with self._assert_expecting_int():
-            i = bt2.IntegerValue(bt2.ArrayValue())
+            i = self._CLS(bt2.ArrayValue())
 
     def test_assign_true(self):
         raw = True
@@ -973,11 +973,6 @@ class IntegerValueTestCase(_TestNumericValue, unittest.TestCase):
         self._def.value = raw
         self.assertEqual(self._def, raw)
 
-    def test_assign_neg_int(self):
-        raw = -13
-        self._def.value = raw
-        self.assertEqual(self._def, raw)
-
     def test_assign_vint(self):
         raw = 999
         self._def.value = bt2.create_value(raw)
@@ -989,7 +984,52 @@ class IntegerValueTestCase(_TestNumericValue, unittest.TestCase):
         self.assertEqual(self._def, int(raw))
 
 
-_inject_numeric_testing_methods(IntegerValueTestCase)
+class SignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase):
+    _CLS = bt2.SignedIntegerValue
+
+    def setUp(self):
+        super().setUp()
+        self._nv = -52
+        self._in = self._CLS(self._nv)
+        self._def_new_value = -101
+
+    def tearDown(self):
+        super().tearDown()
+        del self._in
+
+    def test_create_neg(self):
+        self.assertEqual(self._in, self._nv)
+
+    def test_create_pos_too_big(self):
+        with self._assert_expecting_int64():
+            i = self._CLS(2 ** 63)
+
+    def test_create_neg_too_big(self):
+        with self._assert_expecting_int64():
+            i = self._CLS(-(2 ** 63) - 1)
+
+    def test_assign_neg_int(self):
+        raw = -13
+        self._def.value = raw
+        self.assertEqual(self._def, raw)
+
+
+_inject_numeric_testing_methods(SignedIntegerValueTestCase)
+
+
+class UnsignedIntegerValueTestCase(_TestIntegerValue, unittest.TestCase):
+    _CLS = bt2.UnsignedIntegerValue
+
+    def test_create_pos_too_big(self):
+        with self._assert_expecting_uint64():
+            i = self._CLS(2 ** 64)
+
+    def test_create_neg(self):
+        with self._assert_expecting_uint64():
+            i = self._CLS(-1)
+
+
+_inject_numeric_testing_methods(UnsignedIntegerValueTestCase, False)
 
 
 class RealValueTestCase(_TestNumericValue, unittest.TestCase):
index d689973b3c94e93542dd7d4288e78f1b4ff08295..4619e6240bbecb868f44315f41ec6ff28353b212 100644 (file)
@@ -25,7 +25,7 @@
 #include <string.h>
 #include "tap/tap.h"
 
-#define NR_TESTS 147
+#define NR_TESTS 166
 
 static
 void test_null(void)
@@ -73,32 +73,63 @@ void test_bool(void)
 }
 
 static
-void test_integer(void)
+void test_unsigned_integer(void)
 {
-       int64_t value;
+       uint64_t value;
        bt_value *obj;
 
-       obj = bt_value_integer_create();
-       ok(obj && bt_value_is_integer(obj),
-               "bt_value_integer_create() returns an integer value object");
+       obj = bt_value_unsigned_integer_create();
+       ok(obj && bt_value_is_unsigned_integer(obj),
+               "bt_value_unsigned_integer_create() returns an unsigned integer value object");
 
        value = 1961;
-       value = bt_value_integer_get(obj);
-       ok(value == 0, "default integer value object value is 0");
+       value = bt_value_unsigned_integer_get(obj);
+       ok(value == 0, "default unsigned integer value object value is 0");
 
-       bt_value_integer_set(obj, -98765);
-       value = bt_value_integer_get(obj);
-       ok(value == -98765, "bt_private_integer_bool_set() works");
+       bt_value_unsigned_integer_set(obj, 98765);
+       value = bt_value_unsigned_integer_get(obj);
+       ok(value == 98765, "bt_value_unsigned_integer_bool_set() works");
 
        BT_VALUE_PUT_REF_AND_RESET(obj);
-       pass("putting an existing integer value object does not cause a crash")
+       pass("putting an existing unsigned integer value object does not cause a crash")
 
-       obj = bt_value_integer_create_init(321456987);
-       ok(obj && bt_value_is_integer(obj),
-               "bt_value_integer_create_init() returns an integer value object");
-       value = bt_value_integer_get(obj);
+       obj = bt_value_unsigned_integer_create_init(321456987);
+       ok(obj && bt_value_is_unsigned_integer(obj),
+               "bt_value_unsigned_integer_create_init() returns an unsigned integer value object");
+       value = bt_value_unsigned_integer_get(obj);
        ok(value == 321456987,
-               "bt_value_integer_create_init() sets the appropriate initial value");
+               "bt_value_unsigned_integer_create_init() sets the appropriate initial value");
+
+       BT_VALUE_PUT_REF_AND_RESET(obj);
+}
+
+static
+void test_signed_integer(void)
+{
+       int64_t value;
+       bt_value *obj;
+
+       obj = bt_value_signed_integer_create();
+       ok(obj && bt_value_is_signed_integer(obj),
+               "bt_value_signed_integer_create() returns a signed integer value object");
+
+       value = 1961;
+       value = bt_value_signed_integer_get(obj);
+       ok(value == 0, "default signed integer value object value is 0");
+
+       bt_value_signed_integer_set(obj, 98765);
+       value = bt_value_signed_integer_get(obj);
+       ok(value == 98765, "bt_value_signed_integer_bool_set() works");
+
+       BT_VALUE_PUT_REF_AND_RESET(obj);
+       pass("putting an existing signed integer value object does not cause a crash")
+
+       obj = bt_value_signed_integer_create_init(-321456987);
+       ok(obj && bt_value_is_signed_integer(obj),
+               "bt_value_signed_integer_create_init() returns a signed integer value object");
+       value = bt_value_signed_integer_get(obj);
+       ok(value == -321456987,
+               "bt_value_signed_integer_create_init() sets the appropriate initial value");
 
        BT_VALUE_PUT_REF_AND_RESET(obj);
 }
@@ -184,9 +215,12 @@ void test_array(void)
        ok(bt_value_array_is_empty(array_obj),
                "initial array value object size is 0");
 
-       obj = bt_value_integer_create_init(345);
+       obj = bt_value_unsigned_integer_create_init(345);
        ret = bt_value_array_append_element(array_obj, obj);
        BT_VALUE_PUT_REF_AND_RESET(obj);
+       obj = bt_value_signed_integer_create_init(-507);
+       ret |= bt_value_array_append_element(array_obj, obj);
+       BT_VALUE_PUT_REF_AND_RESET(obj);
        obj = bt_value_real_create_init(-17.45);
        ret |= bt_value_array_append_element(array_obj, obj);
        BT_VALUE_PUT_REF_AND_RESET(obj);
@@ -196,40 +230,46 @@ void test_array(void)
        ret |= bt_value_array_append_element(array_obj,
                bt_value_null);
        ok(!ret, "bt_value_array_append_element() succeeds");
-       ok(bt_value_array_get_size(array_obj) == 4,
+       ok(bt_value_array_get_size(array_obj) == 5,
                "appending an element to an array value object increment its size");
 
        obj = bt_value_array_borrow_element_by_index(array_obj, 0);
-       ok(obj && bt_value_is_integer(obj),
-               "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (integer)");
-       int_value = bt_value_integer_get(obj);
+       ok(obj && bt_value_is_unsigned_integer(obj),
+               "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (unsigned integer)");
+       int_value = bt_value_unsigned_integer_get(obj);
        ok(int_value == 345,
-               "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (integer)");
+               "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (unsigned integer)");
        obj = bt_value_array_borrow_element_by_index(array_obj, 1);
+       ok(obj && bt_value_is_signed_integer(obj),
+               "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (signed integer)");
+       int_value = bt_value_signed_integer_get(obj);
+       ok(int_value == -507,
+               "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (signed integer)");
+       obj = bt_value_array_borrow_element_by_index(array_obj, 2);
        ok(obj && bt_value_is_real(obj),
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (real number)");
        real_value = bt_value_real_get(obj);
        ok(real_value == -17.45,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (real number)");
-       obj = bt_value_array_borrow_element_by_index(array_obj, 2);
+       obj = bt_value_array_borrow_element_by_index(array_obj, 3);
        ok(obj && bt_value_is_bool(obj),
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (boolean)");
        bool_value = bt_value_bool_get(obj);
        ok(bool_value,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate value (boolean)");
-       obj = bt_value_array_borrow_element_by_index(array_obj, 3);
+       obj = bt_value_array_borrow_element_by_index(array_obj, 4);
        ok(obj == bt_value_null,
                "bt_value_array_borrow_element_by_index() returns an value object with the appropriate type (null)");
 
-       obj = bt_value_integer_create_init(1001);
+       obj = bt_value_signed_integer_create_init(1001);
        BT_ASSERT(obj);
        ok(!bt_value_array_set_element_by_index(array_obj, 2, obj),
                "bt_value_array_set_element_by_index() succeeds");
        BT_VALUE_PUT_REF_AND_RESET(obj);
        obj = bt_value_array_borrow_element_by_index(array_obj, 2);
-       ok(obj && bt_value_is_integer(obj),
+       ok(obj && bt_value_is_signed_integer(obj),
                "bt_value_array_set_element_by_index() inserts an value object with the appropriate type");
-       int_value = bt_value_integer_get(obj);
+       int_value = bt_value_signed_integer_get(obj);
        BT_ASSERT(!ret);
        ok(int_value == 1001,
                "bt_value_array_set_element_by_index() inserts an value object with the appropriate value");
@@ -237,9 +277,12 @@ void test_array(void)
        ret = bt_value_array_append_bool_element(array_obj,
                BT_FALSE);
        ok(!ret, "bt_value_array_append_bool_element() succeeds");
-       ret = bt_value_array_append_integer_element(array_obj,
+       ret = bt_value_array_append_unsigned_integer_element(array_obj,
                98765);
-       ok(!ret, "bt_value_array_append_integer_element() succeeds");
+       ok(!ret, "bt_value_array_append_unsigned_integer_element() succeeds");
+       ret = bt_value_array_append_signed_integer_element(array_obj,
+               -10101);
+       ok(!ret, "bt_value_array_append_signed_integer_element() succeeds");
        ret = bt_value_array_append_real_element(array_obj,
                2.49578);
        ok(!ret, "bt_value_array_append_real_element() succeeds");
@@ -251,41 +294,47 @@ void test_array(void)
        ret = bt_value_array_append_empty_map_element(array_obj);
        ok(!ret, "bt_value_array_append_empty_map_element() succeeds");
 
-       ok(bt_value_array_get_size(array_obj) == 10,
+       ok(bt_value_array_get_size(array_obj) == 12,
                "the bt_value_array_append_element_*() functions increment the array value object's size");
        ok(!bt_value_array_is_empty(array_obj),
                "map value object is not empty");
 
-       obj = bt_value_array_borrow_element_by_index(array_obj, 4);
+       obj = bt_value_array_borrow_element_by_index(array_obj, 5);
        ok(obj && bt_value_is_bool(obj),
                "bt_value_array_append_bool_element() appends a boolean value object");
        bool_value = bt_value_bool_get(obj);
        ok(!bool_value,
                "bt_value_array_append_bool_element() appends the appropriate value");
-       obj = bt_value_array_borrow_element_by_index(array_obj, 5);
-       ok(obj && bt_value_is_integer(obj),
-               "bt_value_array_append_integer_element() appends an integer value object");
-       int_value = bt_value_integer_get(obj);
-       ok(int_value == 98765,
-               "bt_value_array_append_integer_element() appends the appropriate value");
        obj = bt_value_array_borrow_element_by_index(array_obj, 6);
+       ok(obj && bt_value_is_unsigned_integer(obj),
+               "bt_value_array_append_unsigned_integer_element() appends an unsigned integer value object");
+       int_value = bt_value_unsigned_integer_get(obj);
+       ok(int_value == 98765,
+               "bt_value_array_append_unsigned_integer_element() appends the appropriate value");
+       obj = bt_value_array_borrow_element_by_index(array_obj, 7);
+       ok(obj && bt_value_is_signed_integer(obj),
+               "bt_value_array_append_signed_integer_element() appends a signed integer value object");
+       int_value = bt_value_signed_integer_get(obj);
+       ok(int_value == -10101,
+               "bt_value_array_append_signed_integer_element() appends the appropriate value");
+       obj = bt_value_array_borrow_element_by_index(array_obj, 8);
        ok(obj && bt_value_is_real(obj),
                "bt_value_array_append_real_element() appends a real number value object");
        real_value = bt_value_real_get(obj);
        ok(real_value == 2.49578,
                "bt_value_array_append_real_element() appends the appropriate value");
-       obj = bt_value_array_borrow_element_by_index(array_obj, 7);
+       obj = bt_value_array_borrow_element_by_index(array_obj, 9);
        ok(obj && bt_value_is_string(obj),
                "bt_value_array_append_string_element() appends a string value object");
        string_value = bt_value_string_get(obj);
        ok(!ret && string_value && !strcmp(string_value, "bt_value"),
                "bt_value_array_append_string_element() appends the appropriate value");
-       obj = bt_value_array_borrow_element_by_index(array_obj, 8);
+       obj = bt_value_array_borrow_element_by_index(array_obj, 10);
        ok(obj && bt_value_is_array(obj),
                "bt_value_array_append_empty_array_element() appends an array value object");
        ok(bt_value_array_is_empty(obj),
                "bt_value_array_append_empty_array_element() an empty array value object");
-       obj = bt_value_array_borrow_element_by_index(array_obj, 9);
+       obj = bt_value_array_borrow_element_by_index(array_obj, 11);
        ok(obj && bt_value_is_map(obj),
                "bt_value_array_append_empty_map_element() appends a map value object");
        ok(bt_value_map_is_empty(obj),
@@ -312,6 +361,7 @@ bt_bool test_map_foreach_cb_count(const char *key, bt_value *object,
 
 struct map_foreach_checklist {
        bt_bool bool1;
+       bt_bool uint;
        bt_bool int1;
        bt_bool real1;
        bt_bool null1;
@@ -344,15 +394,30 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                                fail("test_map_foreach_cb_check(): \"bt_bool\" value object has the wrong value");
                        }
                }
+       } else if (!strcmp(key, "uint")) {
+               if (checklist->uint) {
+                       fail("test_map_foreach_cb_check(): duplicate key \"uint\"");
+               } else {
+                       uint64_t val = 0;
+
+                       val = bt_value_unsigned_integer_get(object);
+
+                       if (val == 19457) {
+                               pass("test_map_foreach_cb_check(): \"uint\" value object has the right value");
+                               checklist->uint = BT_TRUE;
+                       } else {
+                               fail("test_map_foreach_cb_check(): \"uint\" value object has the wrong value");
+                       }
+               }
        } else if (!strcmp(key, "int")) {
                if (checklist->int1) {
                        fail("test_map_foreach_cb_check(): duplicate key \"int\"");
                } else {
                        int64_t val = 0;
 
-                       val = bt_value_integer_get(object);
+                       val = bt_value_signed_integer_get(object);
 
-                       if (val == 19457) {
+                       if (val == -12345) {
                                pass("test_map_foreach_cb_check(): \"int\" value object has the right value");
                                checklist->int1 = BT_TRUE;
                        } else {
@@ -402,7 +467,7 @@ bt_bool test_map_foreach_cb_check(const char *key, bt_value *object,
                } else {
                        int64_t val = 0;
 
-                       val = bt_value_integer_get(object);
+                       val = bt_value_signed_integer_get(object);
 
                        if (val == 98765) {
                                pass("test_map_foreach_cb_check(): \"int2\" value object has the right value");
@@ -485,8 +550,11 @@ void test_map(void)
        ok(bt_value_map_get_size(map_obj) == 0,
                "initial map value object size is 0");
 
-       obj = bt_value_integer_create_init(19457);
-       ret = bt_value_map_insert_entry(map_obj, "int", obj);
+       obj = bt_value_unsigned_integer_create_init(19457);
+       ret = bt_value_map_insert_entry(map_obj, "uint", obj);
+       BT_VALUE_PUT_REF_AND_RESET(obj);
+       obj = bt_value_signed_integer_create_init(-12345);
+       ret |= bt_value_map_insert_entry(map_obj, "int", obj);
        BT_VALUE_PUT_REF_AND_RESET(obj);
        obj = bt_value_real_create_init(5.444);
        ret |= bt_value_map_insert_entry(map_obj, "real", obj);
@@ -497,7 +565,7 @@ void test_map(void)
        ret |= bt_value_map_insert_entry(map_obj, "null",
                bt_value_null);
        ok(!ret, "bt_value_map_insert_entry() succeeds");
-       ok(bt_value_map_get_size(map_obj) == 4,
+       ok(bt_value_map_get_size(map_obj) == 5,
                "inserting an element into a map value object increment its size");
 
        obj = bt_value_bool_create_init(BT_TRUE);
@@ -513,12 +581,18 @@ void test_map(void)
        real_value = bt_value_real_get(obj);
        ok(real_value == 5.444,
                "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (real)");
-       obj = bt_value_map_borrow_entry_value(map_obj, "int");
-       ok(obj && bt_value_is_integer(obj),
-               "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (integer)");
-       int_value = bt_value_integer_get(obj);
+       obj = bt_value_map_borrow_entry_value(map_obj, "uint");
+       ok(obj && bt_value_is_unsigned_integer(obj),
+               "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (unsigned integer)");
+       int_value = bt_value_unsigned_integer_get(obj);
        ok(int_value == 19457,
-               "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (integer)");
+               "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (unsigned integer)");
+       obj = bt_value_map_borrow_entry_value(map_obj, "int");
+       ok(obj && bt_value_is_signed_integer(obj),
+               "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (signed integer)");
+       int_value = bt_value_signed_integer_get(obj);
+       ok(int_value == -12345,
+               "bt_value_map_borrow_entry_value() returns an value object with the appropriate value (signed integer)");
        obj = bt_value_map_borrow_entry_value(map_obj, "null");
        ok(obj && bt_value_is_null(obj),
                "bt_value_map_borrow_entry_value() returns an value object with the appropriate type (null)");
@@ -532,9 +606,9 @@ void test_map(void)
        ret = bt_value_map_insert_bool_entry(map_obj, "bool2",
                BT_TRUE);
        ok(!ret, "bt_value_map_insert_bool_entry() succeeds");
-       ret = bt_value_map_insert_integer_entry(map_obj, "int2",
+       ret = bt_value_map_insert_signed_integer_entry(map_obj, "int2",
                98765);
-       ok(!ret, "bt_value_map_insert_integer_entry() succeeds");
+       ok(!ret, "bt_value_map_insert_signed_integer_entry() succeeds");
        ret = bt_value_map_insert_real_entry(map_obj, "real2",
                -49.0001);
        ok(!ret, "bt_value_map_insert_real_entry() succeeds");
@@ -547,13 +621,15 @@ void test_map(void)
        ret = bt_value_map_insert_empty_map_entry(map_obj, "map2");
        ok(!ret, "bt_value_map_insert_empty_map_entry() succeeds");
 
-       ok(bt_value_map_get_size(map_obj) == 10,
+       ok(bt_value_map_get_size(map_obj) == 11,
                "the bt_value_map_insert*() functions increment the map value object's size");
 
        ok(!bt_value_map_has_entry(map_obj, "hello"),
                "map value object does not have key \"hello\"");
        ok(bt_value_map_has_entry(map_obj, "bt_bool"),
                "map value object has key \"bt_bool\"");
+       ok(bt_value_map_has_entry(map_obj, "uint"),
+               "map value object has key \"uint\"");
        ok(bt_value_map_has_entry(map_obj, "int"),
                "map value object has key \"int\"");
        ok(bt_value_map_has_entry(map_obj, "real"),
@@ -583,9 +659,9 @@ void test_map(void)
                &checklist);
        ok(ret == BT_VALUE_STATUS_OK,
                "bt_value_map_foreach_entry() succeeds with test_map_foreach_cb_check()");
-       ok(checklist.bool1 && checklist.int1 && checklist.real1 &&
-               checklist.null1 && checklist.bool2 && checklist.int2 &&
-               checklist.real2 && checklist.string2 &&
+       ok(checklist.bool1 && checklist.uint && checklist.int1 &&
+               checklist.real1 && checklist.null1 && checklist.bool2 &&
+               checklist.int2 && checklist.real2 && checklist.string2 &&
                checklist.array2 && checklist.map2,
                "bt_value_map_foreach_entry() iterates over all the map value object's elements");
 
@@ -598,7 +674,8 @@ void test_types(void)
 {
        test_null();
        test_bool();
-       test_integer();
+       test_unsigned_integer();
+       test_signed_integer();
        test_real();
        test_string();
        test_array();
@@ -639,25 +716,46 @@ void test_compare_bool(void)
 }
 
 static
-void test_compare_integer(void)
+void test_compare_unsigned_integer(void)
 {
        bt_value *int1 =
-               bt_value_integer_create_init(10);
+               bt_value_unsigned_integer_create_init(10);
        bt_value *int2 =
-               bt_value_integer_create_init(-23);
+               bt_value_unsigned_integer_create_init(23);
        bt_value *int3 =
-               bt_value_integer_create_init(10);
+               bt_value_unsigned_integer_create_init(10);
 
        BT_ASSERT(int1 && int2 && int3);
        ok(!bt_value_compare(bt_value_null,
                int1),
-               "cannot compare null value object and integer value object");
-       ok(!bt_value_compare(int1,
-                            int2),
-               "integer value objects are not equivalent (10 and -23)");
-       ok(bt_value_compare(int1,
-                           int3),
-               "integer value objects are equivalent (10 and 10)");
+               "cannot compare null value object and unsigned integer value object");
+       ok(!bt_value_compare(int1, int2),
+               "unsigned integer value objects are not equivalent (10 and 23)");
+       ok(bt_value_compare(int1, int3),
+               "unsigned integer value objects are equivalent (10 and 10)");
+
+       BT_VALUE_PUT_REF_AND_RESET(int1);
+       BT_VALUE_PUT_REF_AND_RESET(int2);
+       BT_VALUE_PUT_REF_AND_RESET(int3);
+}
+
+void test_compare_signed_integer(void)
+{
+       bt_value *int1 =
+               bt_value_signed_integer_create_init(10);
+       bt_value *int2 =
+               bt_value_signed_integer_create_init(-23);
+       bt_value *int3 =
+               bt_value_signed_integer_create_init(10);
+
+       BT_ASSERT(int1 && int2 && int3);
+       ok(!bt_value_compare(bt_value_null,
+               int1),
+               "cannot compare null value object and signed integer value object");
+       ok(!bt_value_compare(int1, int2),
+               "signed integer value objects are not equivalent (10 and -23)");
+       ok(bt_value_compare(int1, int3),
+               "signed integer value objects are equivalent (10 and 10)");
 
        BT_VALUE_PUT_REF_AND_RESET(int1);
        BT_VALUE_PUT_REF_AND_RESET(int2);
@@ -728,11 +826,10 @@ void test_compare_array(void)
 
        BT_ASSERT(array1 && array2 && array3);
 
-       ok(bt_value_compare(array1,
-                           array2),
+       ok(bt_value_compare(array1, array2),
                "empty array value objects are equivalent");
 
-       status = bt_value_array_append_integer_element(array1, 23);
+       status = bt_value_array_append_signed_integer_element(array1, 23);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_array_append_real_element(array1, 14.2);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
@@ -740,11 +837,11 @@ void test_compare_array(void)
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_array_append_real_element(array2, 14.2);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_integer_element(array2, 23);
+       status = bt_value_array_append_signed_integer_element(array2, 23);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_array_append_bool_element(array2, BT_FALSE);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_integer_element(array3, 23);
+       status = bt_value_array_append_signed_integer_element(array3, 23);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_array_append_real_element(array3, 14.2);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
@@ -784,7 +881,7 @@ void test_compare_map(void)
                "empty map value objects are equivalent");
 
 
-       status = bt_value_map_insert_integer_entry(map1, "one", 23);
+       status = bt_value_map_insert_signed_integer_entry(map1, "one", 23);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_map_insert_real_entry(map1, "two", 14.2);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
@@ -793,7 +890,7 @@ void test_compare_map(void)
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_map_insert_real_entry(map2, "one", 14.2);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_integer_entry(map2, "two", 23);
+       status = bt_value_map_insert_signed_integer_entry(map2, "two", 23);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_map_insert_bool_entry(map2, "three",
                BT_FALSE);
@@ -801,7 +898,7 @@ void test_compare_map(void)
        status = bt_value_map_insert_bool_entry(map3, "three",
                BT_FALSE);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_integer_entry(map3, "one", 23);
+       status = bt_value_map_insert_signed_integer_entry(map3, "one", 23);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_map_insert_real_entry(map3, "two", 14.2);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
@@ -829,7 +926,8 @@ void test_compare(void)
 {
        test_compare_null();
        test_compare_bool();
-       test_compare_integer();
+       test_compare_unsigned_integer();
+       test_compare_signed_integer();
        test_compare_real();
        test_compare_string();
        test_compare_array();
@@ -841,15 +939,16 @@ void test_copy(void)
 {
        /*
         * Here's the deal here. If we make sure that each value object
-        * of our deep copy has a different address than its source,
-        * and that bt_value_compare() returns BT_TRUE for the top-level
-        * value object, taking into account that we test the correctness of
-        * bt_value_compare() elsewhere, then the deep copy is a
-        * success.
+        * of our deep copy has a different address than its source, and
+        * that bt_value_compare() returns BT_TRUE for the top-level
+        * value object, taking into account that we test the
+        * correctness of bt_value_compare() elsewhere, then the deep
+        * copy is a success.
         */
        bt_value *null_copy_obj;
        bt_value *bool_obj, *bool_copy_obj;
-       bt_value *integer_obj, *integer_copy_obj;
+       bt_value *unsigned_integer_obj, *unsigned_integer_copy_obj;
+       bt_value *signed_integer_obj, *signed_integer_copy_obj;
        bt_value *real_obj, *real_copy_obj;
        bt_value *string_obj, *string_copy_obj;
        bt_value *array_obj, *array_copy_obj;
@@ -857,32 +956,29 @@ void test_copy(void)
        bt_value_status status;
 
        bool_obj = bt_value_bool_create_init(BT_TRUE);
-       integer_obj = bt_value_integer_create_init(23);
+       unsigned_integer_obj = bt_value_unsigned_integer_create_init(23);
+       signed_integer_obj = bt_value_signed_integer_create_init(-47);
        real_obj = bt_value_real_create_init(-3.1416);
        string_obj = bt_value_string_create_init("test");
        array_obj = bt_value_array_create();
        map_obj = bt_value_map_create();
 
-       BT_ASSERT(bool_obj && integer_obj && real_obj && string_obj &&
-               array_obj && map_obj);
+       BT_ASSERT(bool_obj && unsigned_integer_obj && signed_integer_obj &&
+               real_obj && string_obj && array_obj && map_obj);
 
-       status = bt_value_array_append_element(array_obj,
-               bool_obj);
+       status = bt_value_array_append_element(array_obj, bool_obj);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_element(array_obj,
-               integer_obj);
+       status = bt_value_array_append_element(array_obj, unsigned_integer_obj);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_element(array_obj,
-               real_obj);
+       status = bt_value_array_append_element(array_obj, signed_integer_obj);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_array_append_element(array_obj,
-               bt_value_null);
+       status = bt_value_array_append_element(array_obj, real_obj);
+       BT_ASSERT(status == BT_VALUE_STATUS_OK);
+       status = bt_value_array_append_element(array_obj, bt_value_null);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_entry(map_obj, "array",
-               array_obj);
+       status = bt_value_map_insert_entry(map_obj, "array", array_obj);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_entry(map_obj, "string",
-               string_obj);
+       status = bt_value_map_insert_entry(map_obj, "string", string_obj);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
 
        status = bt_value_copy(map_obj, &map_copy_obj);
@@ -902,27 +998,31 @@ void test_copy(void)
        bool_copy_obj = bt_value_array_borrow_element_by_index(
                array_copy_obj, 0);
        ok(bool_copy_obj != bool_obj,
-               "bt_value_copy() returns a different pointer (bt_bool)");
-       integer_copy_obj = bt_value_array_borrow_element_by_index(
+               "bt_value_copy() returns a different pointer (bool)");
+       unsigned_integer_copy_obj = bt_value_array_borrow_element_by_index(
                array_copy_obj, 1);
-       ok(integer_copy_obj != integer_obj,
-               "bt_value_copy() returns a different pointer (integer)");
-       real_copy_obj = bt_value_array_borrow_element_by_index(
+       ok(unsigned_integer_copy_obj != unsigned_integer_obj,
+               "bt_value_copy() returns a different pointer (unsigned integer)");
+       signed_integer_copy_obj = bt_value_array_borrow_element_by_index(
                array_copy_obj, 2);
+       ok(signed_integer_copy_obj != signed_integer_obj,
+               "bt_value_copy() returns a different pointer (signed integer)");
+       real_copy_obj = bt_value_array_borrow_element_by_index(
+               array_copy_obj, 3);
        ok(real_copy_obj != real_obj,
                "bt_value_copy() returns a different pointer (real)");
        null_copy_obj = bt_value_array_borrow_element_by_index(
-               array_copy_obj, 3);
+               array_copy_obj, 4);
        ok(null_copy_obj == bt_value_null,
                "bt_value_copy() returns the same pointer (null)");
 
-       ok(bt_value_compare(map_obj,
-                           map_copy_obj),
+       ok(bt_value_compare(map_obj, map_copy_obj),
                "source and destination value objects have the same content");
 
        BT_VALUE_PUT_REF_AND_RESET(map_copy_obj);
        BT_VALUE_PUT_REF_AND_RESET(bool_obj);
-       BT_VALUE_PUT_REF_AND_RESET(integer_obj);
+       BT_VALUE_PUT_REF_AND_RESET(unsigned_integer_obj);
+       BT_VALUE_PUT_REF_AND_RESET(signed_integer_obj);
        BT_VALUE_PUT_REF_AND_RESET(real_obj);
        BT_VALUE_PUT_REF_AND_RESET(string_obj);
        BT_VALUE_PUT_REF_AND_RESET(array_obj);
@@ -961,16 +1061,16 @@ void test_extend(void)
        status = bt_value_map_insert_bool_entry(base_map, "edit",
                BT_FALSE);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_integer_entry(base_map,
+       status = bt_value_map_insert_signed_integer_entry(base_map,
                "selection", 17);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_integer_entry(base_map, "find",
+       status = bt_value_map_insert_signed_integer_entry(base_map, "find",
                -34);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_map_insert_bool_entry(extension_map, "edit",
                BT_TRUE);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
-       status = bt_value_map_insert_integer_entry(extension_map,
+       status = bt_value_map_insert_signed_integer_entry(extension_map,
                "find", 101);
        BT_ASSERT(status == BT_VALUE_STATUS_OK);
        status = bt_value_map_insert_real_entry(extension_map,
index 505fe86a3e3439d64f10ba1739f6140dfbf183e4..08e57940701b6e551b5bfac5e5dee8a5e2c315ea 100644 (file)
@@ -173,7 +173,7 @@ static void test_sfs(const char *plugin_dir)
                plugin, "filter");
        ok(filter_comp_class,
                "bt_plugin_borrow_filter_component_class_by_name_const() finds a filter component class");
-       params = bt_value_integer_create_init(23);
+       params = bt_value_signed_integer_create_init(23);
        BT_ASSERT(params);
        ret = bt_query_executor_query(query_exec,
                bt_component_class_filter_as_component_class_const(filter_comp_class),
This page took 0.066998 seconds and 4 git commands to generate.