From fdd3a2da18afef5ca32ba181a8b6ebbff173df02 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Fri, 3 May 2019 15:14:18 -0400 Subject: [PATCH] lib: add unsigned and signed integer value API 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 Change-Id: Ic96ef9e1e16883cb5c59844c6ba5a060936efdb0 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1257 Tested-by: jenkins --- bindings/python/bt2/bt2/__init__.py.in | 1 + bindings/python/bt2/bt2/native_bt_value.i | 66 ++-- bindings/python/bt2/bt2/value.py | 39 ++- cli/babeltrace-cfg-cli-args.c | 35 +- cli/babeltrace.c | 21 +- doc/man/common-cmd-params-format.txt | 4 +- include/babeltrace/common-internal.h | 6 +- include/babeltrace/value-const.h | 33 +- include/babeltrace/value-internal.h | 5 +- include/babeltrace/value.h | 23 +- lib/lib-logging.c | 13 +- lib/trace-ir/trace-class.c | 2 +- lib/value.c | 207 ++++++++--- plugins/ctf/fs-sink/fs-sink-trace.c | 22 +- .../ctf/fs-sink/translate-ctf-ir-to-tsdl.c | 4 +- .../fs-sink/translate-trace-ir-to-ctf-ir.c | 2 +- plugins/ctf/fs-src/fs.c | 8 +- plugins/ctf/fs-src/query.c | 12 +- plugins/ctf/lttng-live/viewer-connection.c | 20 +- .../debug-info/trace-ir-metadata-copy.c | 5 +- plugins/text/pretty/print.c | 2 +- plugins/utils/counter/Makefile.am | 6 +- plugins/utils/counter/counter.c | 30 +- plugins/utils/counter/logging.c | 27 ++ plugins/utils/counter/logging.h | 31 ++ plugins/utils/trimmer/trimmer.c | 4 +- tests/bindings/python/bt2/test_value.py | 154 ++++++--- tests/lib/test_bt_values.c | 324 ++++++++++++------ tests/lib/test_plugin.c | 2 +- 29 files changed, 749 insertions(+), 359 deletions(-) create mode 100644 plugins/utils/counter/logging.c create mode 100644 plugins/utils/counter/logging.h diff --git a/bindings/python/bt2/bt2/__init__.py.in b/bindings/python/bt2/bt2/__init__.py.in index d064dc59..8c79b088 100644 --- a/bindings/python/bt2/bt2/__init__.py.in +++ b/bindings/python/bt2/bt2/__init__.py.in @@ -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): diff --git a/bindings/python/bt2/bt2/native_bt_value.i b/bindings/python/bt2/bt2/native_bt_value.i index 6d1aeff9..1ecd21e3 100644 --- a/bindings/python/bt2/bt2/native_bt_value.i +++ b/bindings/python/bt2/bt2/native_bt_value.i @@ -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( diff --git a/bindings/python/bt2/bt2/value.py b/bindings/python/bt2/bt2/value.py index 1a5612da..5beccbcd 100644 --- a/bindings/python/bt2/bt2/value.py +++ b/bindings/python/bt2/bt2/value.py @@ -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, diff --git a/cli/babeltrace-cfg-cli-args.c b/cli/babeltrace-cfg-cli-args.c index dfce55bd..05193d3b 100644 --- a/cli/babeltrace-cfg-cli-args.c +++ b/cli/babeltrace-cfg-cli-args.c @@ -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"); diff --git a/cli/babeltrace.c b/cli/babeltrace.c index a0de86f7..39b1f3c2 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -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: " diff --git a/doc/man/common-cmd-params-format.txt b/doc/man/common-cmd-params-format.txt index efceab47..4acce3d7 100644 --- a/doc/man/common-cmd-params-format.txt +++ b/doc/man/common-cmd-params-format.txt @@ -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]' diff --git a/include/babeltrace/common-internal.h b/include/babeltrace/common-internal.h index 19594fe3..4290f0bd 100644 --- a/include/babeltrace/common-internal.h +++ b/include/babeltrace/common-internal.h @@ -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: diff --git a/include/babeltrace/value-const.h b/include/babeltrace/value-const.h index e5ff39da..63368085 100644 --- a/include/babeltrace/value-const.h +++ b/include/babeltrace/value-const.h @@ -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); diff --git a/include/babeltrace/value-internal.h b/include/babeltrace/value-internal.h index dd3fb7d9..0e50e2de 100644 --- a/include/babeltrace/value-internal.h +++ b/include/babeltrace/value-internal.h @@ -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 { diff --git a/include/babeltrace/value.h b/include/babeltrace/value.h index 89c4c64e..0425b6b4 100644 --- a/include/babeltrace/value.h +++ b/include/babeltrace/value.h @@ -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( diff --git a/lib/lib-logging.c b/lib/lib-logging.c index 7e897fa3..657363ed 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -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: diff --git a/lib/trace-ir/trace-class.c b/lib/trace-ir/trace-class.c index 3aa398fb..64a057b5 100644 --- a/lib/trace-ir/trace-class.c +++ b/lib/trace-ir/trace-class.c @@ -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; diff --git a/lib/value.c b/lib/value.c index 6e33ae7b..bf07dc8c 100644 --- a/lib/value.c +++ b/lib/value.c @@ -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); diff --git a/plugins/ctf/fs-sink/fs-sink-trace.c b/plugins/ctf/fs-sink/fs-sink-trace.c index c6989ccc..f0178774 100644 --- a/plugins/ctf/fs-sink/fs-sink-trace.c +++ b/plugins/ctf/fs-sink/fs-sink-trace.c @@ -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, diff --git a/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c b/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c index efc02b30..c148caea 100644 --- a/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c +++ b/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c @@ -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)); diff --git a/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c b/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c index 699b3a5b..69c20c61 100644 --- a/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c +++ b/plugins/ctf/fs-sink/translate-trace-ir-to-ctf-ir.c @@ -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: diff --git a/plugins/ctf/fs-src/fs.c b/plugins/ctf/fs-src/fs.c index 6672071f..7d2fb08b 100644 --- a/plugins/ctf/fs-src/fs.c +++ b/plugins/ctf/fs-src/fs.c @@ -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); } diff --git a/plugins/ctf/fs-src/query.c b/plugins/ctf/fs-src/query.c index d632d42d..e7746f45 100644 --- a/plugins/ctf/fs-src/query.c +++ b/plugins/ctf/fs-src/query.c @@ -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; diff --git a/plugins/ctf/lttng-live/viewer-connection.c b/plugins/ctf/lttng-live/viewer-connection.c index b37db12e..ec9dba29 100644 --- a/plugins/ctf/lttng-live/viewer-connection.c +++ b/plugins/ctf/lttng-live/viewer-connection.c @@ -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; diff --git a/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c b/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c index 7e9b81e2..bdcc18ca 100644 --- a/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c +++ b/plugins/lttng-utils/debug-info/trace-ir-metadata-copy.c @@ -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( diff --git a/plugins/text/pretty/print.c b/plugins/text/pretty/print.c index 0d69b9bc..95189d5e 100644 --- a/plugins/text/pretty/print.c +++ b/plugins/text/pretty/print.c @@ -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; diff --git a/plugins/utils/counter/Makefile.am b/plugins/utils/counter/Makefile.am index 10cf5505..789df186 100644 --- a/plugins/utils/counter/Makefile.am +++ b/plugins/utils/counter/Makefile.am @@ -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 diff --git a/plugins/utils/counter/counter.c b/plugins/utils/counter/counter.c index 97bed28d..fea90c33 100644 --- a/plugins/utils/counter/counter.c +++ b/plugins/utils/counter/counter.c @@ -20,6 +20,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "PLUGIN-UTILS-COUNTER-FLT" +#include "logging.h" + #include #include #include @@ -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 index 00000000..ff3e9c20 --- /dev/null +++ b/plugins/utils/counter/logging.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2017 Philippe Proulx + * + * 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 + +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 index 00000000..3c9dd65a --- /dev/null +++ b/plugins/utils/counter/logging.h @@ -0,0 +1,31 @@ +#ifndef PLUGINS_UTILS_MUXER_LOGGING_H +#define PLUGINS_UTILS_MUXER_LOGGING_H + +/* + * Copyright (c) 2017 Philippe Proulx + * + * 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 + +BT_LOG_LEVEL_EXTERN_SYMBOL(bt_plugin_utils_muxer_log_level); + +#endif /* PLUGINS_UTILS_MUXER_LOGGING_H */ diff --git a/plugins/utils/trimmer/trimmer.c b/plugins/utils/trimmer/trimmer.c index ddf95b9d..d9407bfd 100644 --- a/plugins/utils/trimmer/trimmer.c +++ b/plugins/utils/trimmer/trimmer.c @@ -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 diff --git a/tests/bindings/python/bt2/test_value.py b/tests/bindings/python/bt2/test_value.py index 6628e045..d0e5c38a 100644 --- a/tests/bindings/python/bt2/test_value.py +++ b/tests/bindings/python/bt2/test_value.py @@ -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): diff --git a/tests/lib/test_bt_values.c b/tests/lib/test_bt_values.c index d689973b..4619e624 100644 --- a/tests/lib/test_bt_values.c +++ b/tests/lib/test_bt_values.c @@ -25,7 +25,7 @@ #include #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, diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index 505fe86a..08e57940 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -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), -- 2.34.1