From 8d8b141db4c46135a35be19e4a1c192f6a36d67b Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Wed, 18 Sep 2019 16:12:00 -0400 Subject: [PATCH] lib: pass config object to message iterator init method, add can seek forward property This patch introduces a new bt_self_message_iterator_configuration object that is passed to message iterator init methods. The purpose of this object is to hold options the message iterator can set at init time but not later. To verify that the user does not save a pointer to this object and try to use it later, the object is frozen right after the init method returns. The object contains one option that we know we'll need, `can_seek_forward`. The corresponding functions to set it (on the config object) and read it (from the self component port input message iterator object) are also provided. But because this patch already contains a lot of boilerplate, the code that actually uses that option will come in a following patch. The Python bindings provide a simple wrapper around this new object. Change-Id: Ibcd0df842fd154d3bafe3869b56f70aa3a72ceab Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/2064 Tested-by: jenkins --- .../graph/component-class-filter.h | 1 + .../graph/component-class-source.h | 1 + ...lf-component-port-input-message-iterator.h | 4 + .../babeltrace2/graph/self-message-iterator.h | 4 + include/babeltrace2/types.h | 1 + .../python/bt2/bt2/message_iterator.py | 26 +++++- .../bt2/bt2/native_bt_component_class.i.h | 35 ++++++-- src/lib/graph/iterator.c | 25 +++++- src/lib/graph/message/iterator.h | 6 ++ src/plugins/ctf/fs-src/fs.c | 1 + src/plugins/ctf/fs-src/fs.h | 1 + src/plugins/ctf/lttng-live/lttng-live.c | 1 + src/plugins/ctf/lttng-live/lttng-live.h | 1 + .../lttng-utils/debug-info/debug-info.c | 1 + .../lttng-utils/debug-info/debug-info.h | 1 + src/plugins/text/dmesg/dmesg.c | 1 + src/plugins/text/dmesg/dmesg.h | 1 + src/plugins/utils/muxer/muxer.c | 1 + src/plugins/utils/muxer/muxer.h | 1 + src/plugins/utils/trimmer/trimmer.c | 1 + src/plugins/utils/trimmer/trimmer.h | 1 + tests/bindings/python/bt2/test_clock_class.py | 2 +- tests/bindings/python/bt2/test_event.py | 2 +- tests/bindings/python/bt2/test_event_class.py | 2 +- tests/bindings/python/bt2/test_field.py | 2 +- tests/bindings/python/bt2/test_field_class.py | 2 +- tests/bindings/python/bt2/test_graph.py | 2 +- tests/bindings/python/bt2/test_message.py | 2 +- .../python/bt2/test_message_iterator.py | 88 ++++++++++++++++--- tests/bindings/python/bt2/utils.py | 2 +- .../grouping/bt_plugin_test.py | 2 +- .../params-log-level/bt_plugin_test.py | 2 +- .../flt.utils.muxer/bt_plugin_muxer_test.py | 2 +- .../bt_plugin_trimmer_test.py | 2 +- tests/lib/test-plugin-plugins/sfs.c | 2 + 35 files changed, 194 insertions(+), 35 deletions(-) diff --git a/include/babeltrace2/graph/component-class-filter.h b/include/babeltrace2/graph/component-class-filter.h index b95e18fc..1907fc0f 100644 --- a/include/babeltrace2/graph/component-class-filter.h +++ b/include/babeltrace2/graph/component-class-filter.h @@ -56,6 +56,7 @@ typedef void (*bt_component_class_filter_finalize_method)( typedef bt_component_class_message_iterator_init_method_status (*bt_component_class_filter_message_iterator_init_method)( bt_self_message_iterator *message_iterator, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_component, bt_self_component_port_output *port); diff --git a/include/babeltrace2/graph/component-class-source.h b/include/babeltrace2/graph/component-class-source.h index e5234403..5d7c4161 100644 --- a/include/babeltrace2/graph/component-class-source.h +++ b/include/babeltrace2/graph/component-class-source.h @@ -56,6 +56,7 @@ typedef void (*bt_component_class_source_finalize_method)( typedef bt_component_class_message_iterator_init_method_status (*bt_component_class_source_message_iterator_init_method)( bt_self_message_iterator *message_iterator, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_component, bt_self_component_port_output *port); diff --git a/include/babeltrace2/graph/self-component-port-input-message-iterator.h b/include/babeltrace2/graph/self-component-port-input-message-iterator.h index c83bd8db..a0c8c54e 100644 --- a/include/babeltrace2/graph/self-component-port-input-message-iterator.h +++ b/include/babeltrace2/graph/self-component-port-input-message-iterator.h @@ -96,6 +96,10 @@ extern bt_message_iterator_seek_beginning_status bt_self_component_port_input_message_iterator_seek_beginning( bt_self_component_port_input_message_iterator *iterator); +extern bt_bool +bt_self_component_port_input_message_iterator_can_seek_forward( + bt_self_component_port_input_message_iterator *iterator); + extern void bt_self_component_port_input_message_iterator_get_ref( const bt_self_component_port_input_message_iterator *self_component_port_input_message_iterator); diff --git a/include/babeltrace2/graph/self-message-iterator.h b/include/babeltrace2/graph/self-message-iterator.h index ad528e49..9aaa2767 100644 --- a/include/babeltrace2/graph/self-message-iterator.h +++ b/include/babeltrace2/graph/self-message-iterator.h @@ -51,6 +51,10 @@ extern void bt_self_message_iterator_set_data( extern void *bt_self_message_iterator_get_data( const bt_self_message_iterator *message_iterator); +extern void bt_self_message_iterator_configuration_set_can_seek_forward( + bt_self_message_iterator_configuration *config, + bt_bool can_seek_forward); + #ifdef __cplusplus } #endif diff --git a/include/babeltrace2/types.h b/include/babeltrace2/types.h index d9b883ac..fe74a81a 100644 --- a/include/babeltrace2/types.h +++ b/include/babeltrace2/types.h @@ -148,6 +148,7 @@ typedef struct bt_self_component_sink_configuration bt_self_component_sink_confi typedef struct bt_self_component_source bt_self_component_source; typedef struct bt_self_component_source_configuration bt_self_component_source_configuration; typedef struct bt_self_message_iterator bt_self_message_iterator; +typedef struct bt_self_message_iterator_configuration bt_self_message_iterator_configuration; typedef struct bt_self_plugin bt_self_plugin; typedef struct bt_stream bt_stream; typedef struct bt_stream_class bt_stream_class; diff --git a/src/bindings/python/bt2/bt2/message_iterator.py b/src/bindings/python/bt2/bt2/message_iterator.py index f57699f6..3b46c6da 100644 --- a/src/bindings/python/bt2/bt2/message_iterator.py +++ b/src/bindings/python/bt2/bt2/message_iterator.py @@ -110,6 +110,25 @@ class _UserComponentInputPortMessageIterator(object._SharedObject, _MessageItera status, 'message iterator cannot seek given ns from origin' ) + @property + def can_seek_forward(self): + return native_bt.self_component_port_input_message_iterator_can_seek_forward( + self._ptr + ) + + +class _MessageIteratorConfiguration: + def __init__(self, ptr): + self._ptr = ptr + + def can_seek_forward(self, value): + utils._check_bool(value) + native_bt.self_message_iterator_configuration_set_can_seek_forward( + self._ptr, value + ) + + can_seek_forward = property(fset=can_seek_forward) + # This is extended by the user to implement component classes in Python. It # is created for a given output port when an input port message iterator is @@ -134,13 +153,14 @@ class _UserMessageIterator(_MessageIterator): self._bt_ptr = ptr return self - def _bt_init_from_native(self, self_output_port_ptr): + def _bt_init_from_native(self, config_ptr, self_output_port_ptr): self_output_port = bt2_port._create_self_from_ptr_and_get_ref( self_output_port_ptr, native_bt.PORT_TYPE_OUTPUT ) - self.__init__(self_output_port) + config = _MessageIteratorConfiguration(config_ptr) + self.__init__(config, self_output_port) - def __init__(self, output_port): + def __init__(self, config, self_output_port): pass @property diff --git a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h index b97193d3..15ad4290 100644 --- a/src/bindings/python/bt2/bt2/native_bt_component_class.i.h +++ b/src/bindings/python/bt2/bt2/native_bt_component_class.i.h @@ -935,6 +935,7 @@ static bt_component_class_message_iterator_init_method_status component_class_message_iterator_init( bt_self_message_iterator *self_message_iterator, + bt_self_message_iterator_configuration *config, bt_self_component *self_component, bt_self_component_port_output *self_component_port_output) { @@ -942,6 +943,7 @@ component_class_message_iterator_init( PyObject *py_comp_cls = NULL; PyObject *py_iter_cls = NULL; PyObject *py_iter_ptr = NULL; + PyObject *py_config_ptr = NULL; PyObject *py_component_port_output_ptr = NULL; PyObject *py_init_method_result = NULL; PyObject *py_iter = NULL; @@ -996,15 +998,27 @@ component_class_message_iterator_init( /* * Initialize object: * - * py_iter.__init__(self_output_port) + * py_iter.__init__(config, self_output_port) * - * through the _init_for_native helper static method. + * through the _init_from_native helper static method. * * At this point, py_iter._ptr is set, so this initialization * function has access to self._component (which gives it the * user Python component object from which the iterator was * created). */ + py_config_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(config), + SWIGTYPE_p_bt_self_message_iterator_configuration, 0); + if (!py_config_ptr) { + const char *err = "Failed to create a SWIG pointer object"; + + BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_component, + "%s", err); + BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_MESSAGE_ITERATOR( + self_message_iterator, err); + goto error; + } + py_component_port_output_ptr = SWIG_NewPointerObj( SWIG_as_voidptr(self_component_port_output), SWIGTYPE_p_bt_self_component_port_output, 0); @@ -1019,7 +1033,8 @@ component_class_message_iterator_init( } py_init_method_result = PyObject_CallMethod(py_iter, - "_bt_init_from_native", "O", py_component_port_output_ptr); + "_bt_init_from_native", "OO", py_config_ptr, + py_component_port_output_ptr); if (!py_init_method_result) { BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, log_level, self_component, "User's __init__() method failed:"); @@ -1074,24 +1089,30 @@ static bt_component_class_message_iterator_init_method_status component_class_source_message_iterator_init( bt_self_message_iterator *self_message_iterator, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_component_source, bt_self_component_port_output *self_component_port_output) { - bt_self_component *self_component = bt_self_component_source_as_self_component(self_component_source); + bt_self_component *self_component = + bt_self_component_source_as_self_component(self_component_source); - return component_class_message_iterator_init(self_message_iterator, self_component, self_component_port_output); + return component_class_message_iterator_init(self_message_iterator, + config, self_component, self_component_port_output); } static bt_component_class_message_iterator_init_method_status component_class_filter_message_iterator_init( bt_self_message_iterator *self_message_iterator, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_component_filter, bt_self_component_port_output *self_component_port_output) { - bt_self_component *self_component = bt_self_component_filter_as_self_component(self_component_filter); + bt_self_component *self_component = + bt_self_component_filter_as_self_component(self_component_filter); - return component_class_message_iterator_init(self_message_iterator, self_component, self_component_port_output); + return component_class_message_iterator_init(self_message_iterator, + config, self_component, self_component_port_output); } static diff --git a/src/lib/graph/iterator.c b/src/lib/graph/iterator.c index 983f5c10..8af6166a 100644 --- a/src/lib/graph/iterator.c +++ b/src/lib/graph/iterator.c @@ -299,7 +299,7 @@ int create_self_component_input_port_message_iterator( struct bt_self_component_port_input_message_iterator **message_iterator) { typedef enum bt_component_class_message_iterator_init_method_status (*init_method_t)( - void *, void *, void *); + void *, void *, void *, void *); init_method_t init_method = NULL; struct bt_self_component_port_input_message_iterator *iterator = @@ -472,7 +472,7 @@ int create_self_component_input_port_message_iterator( enum bt_component_class_message_iterator_init_method_status iter_status; BT_LIB_LOGD("Calling user's initialization method: %!+i", iterator); - iter_status = init_method(iterator, upstream_comp, + iter_status = init_method(iterator, &iterator->config, upstream_comp, upstream_port); BT_LOGD("User method returned: status=%s", bt_common_func_status_string(iter_status)); @@ -485,6 +485,8 @@ int create_self_component_input_port_message_iterator( status = iter_status; goto error; } + + iterator->config.frozen = true; } if (downstream_msg_iter) { @@ -561,6 +563,16 @@ void bt_self_message_iterator_set_data( "%!+i, user-data-addr=%p", iterator, data); } +void bt_self_message_iterator_configuration_set_can_seek_forward( + bt_self_message_iterator_configuration *config, + bt_bool can_seek_forward) +{ + BT_ASSERT_PRE_NON_NULL(config, "Message iterator configuration"); + BT_ASSERT_PRE_DEV_HOT(config, "Message iterator configuration", ""); + + config->can_seek_forward = can_seek_forward; +} + /* * Validate that the default clock snapshot in `msg` doesn't make us go back in * time. @@ -1150,6 +1162,15 @@ bt_self_component_port_input_message_iterator_seek_beginning( return status; } +bt_bool +bt_self_component_port_input_message_iterator_can_seek_forward( + bt_self_component_port_input_message_iterator *iterator) +{ + BT_ASSERT_PRE_NON_NULL(iterator, "Message iterator"); + + return iterator->config.can_seek_forward; +} + /* * Structure used to record the state of a given stream during the fast-forward * phase of an auto-seek. diff --git a/src/lib/graph/message/iterator.h b/src/lib/graph/message/iterator.h index 8014d1fa..412fe904 100644 --- a/src/lib/graph/message/iterator.h +++ b/src/lib/graph/message/iterator.h @@ -85,6 +85,11 @@ typedef enum bt_component_class_message_iterator_can_seek_beginning_method_statu (*bt_self_component_port_input_message_iterator_can_seek_beginning_method)( void *, bt_bool *); +struct bt_self_message_iterator_configuration { + bool frozen; + bool can_seek_forward; +}; + struct bt_self_component_port_input_message_iterator { struct bt_object base; GPtrArray *msgs; @@ -92,6 +97,7 @@ struct bt_self_component_port_input_message_iterator { struct bt_port *upstream_port; /* Weak */ struct bt_connection *connection; /* Weak */ struct bt_graph *graph; /* Weak */ + struct bt_self_message_iterator_configuration config; /* * Array of diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index 83df6dbe..2149b89c 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -250,6 +250,7 @@ void ctf_fs_iterator_finalize(bt_self_message_iterator *it) BT_HIDDEN bt_component_class_message_iterator_init_method_status ctf_fs_iterator_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_comp_src, bt_self_component_port_output *self_port) { diff --git a/src/plugins/ctf/fs-src/fs.h b/src/plugins/ctf/fs-src/fs.h index e48c1469..5f8c4128 100644 --- a/src/plugins/ctf/fs-src/fs.h +++ b/src/plugins/ctf/fs-src/fs.h @@ -215,6 +215,7 @@ bt_component_class_query_method_status ctf_fs_query( BT_HIDDEN bt_component_class_message_iterator_init_method_status ctf_fs_iterator_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_comp, bt_self_component_port_output *self_port); diff --git a/src/plugins/ctf/lttng-live/lttng-live.c b/src/plugins/ctf/lttng-live/lttng-live.c index a79d02b1..6336ffe5 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.c +++ b/src/plugins/ctf/lttng-live/lttng-live.c @@ -1445,6 +1445,7 @@ no_session: BT_HIDDEN bt_component_class_message_iterator_init_method_status lttng_live_msg_iter_init( bt_self_message_iterator *self_msg_it, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_comp_src, bt_self_component_port_output *self_port) { diff --git a/src/plugins/ctf/lttng-live/lttng-live.h b/src/plugins/ctf/lttng-live/lttng-live.h index 57de598b..0c86a687 100644 --- a/src/plugins/ctf/lttng-live/lttng-live.h +++ b/src/plugins/ctf/lttng-live/lttng-live.h @@ -280,6 +280,7 @@ bt_component_class_message_iterator_next_method_status lttng_live_msg_iter_next( bt_component_class_message_iterator_init_method_status lttng_live_msg_iter_init( bt_self_message_iterator *self_msg_it, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_comp, bt_self_component_port_output *self_port); diff --git a/src/plugins/lttng-utils/debug-info/debug-info.c b/src/plugins/lttng-utils/debug-info/debug-info.c index c481f8bf..fa2a492e 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.c +++ b/src/plugins/lttng-utils/debug-info/debug-info.c @@ -1958,6 +1958,7 @@ end: BT_HIDDEN bt_component_class_message_iterator_init_method_status debug_info_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp_flt, bt_self_component_port_output *self_port) { diff --git a/src/plugins/lttng-utils/debug-info/debug-info.h b/src/plugins/lttng-utils/debug-info/debug-info.h index 1c2d106b..f39f3bb3 100644 --- a/src/plugins/lttng-utils/debug-info/debug-info.h +++ b/src/plugins/lttng-utils/debug-info/debug-info.h @@ -46,6 +46,7 @@ void debug_info_comp_finalize(bt_self_component_filter *self_comp); BT_HIDDEN bt_component_class_message_iterator_init_method_status debug_info_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp, bt_self_component_port_output *self_port); diff --git a/src/plugins/text/dmesg/dmesg.c b/src/plugins/text/dmesg/dmesg.c index 9f22ac86..3ef752c0 100644 --- a/src/plugins/text/dmesg/dmesg.c +++ b/src/plugins/text/dmesg/dmesg.c @@ -659,6 +659,7 @@ void destroy_dmesg_msg_iter(struct dmesg_msg_iter *dmesg_msg_iter) BT_HIDDEN bt_component_class_message_iterator_init_method_status dmesg_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_comp, bt_self_component_port_output *self_port) { diff --git a/src/plugins/text/dmesg/dmesg.h b/src/plugins/text/dmesg/dmesg.h index f74b3b26..e997b5e1 100644 --- a/src/plugins/text/dmesg/dmesg.h +++ b/src/plugins/text/dmesg/dmesg.h @@ -39,6 +39,7 @@ void dmesg_finalize(bt_self_component_source *self_comp); BT_HIDDEN bt_component_class_message_iterator_init_method_status dmesg_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_comp, bt_self_component_port_output *self_port); diff --git a/src/plugins/utils/muxer/muxer.c b/src/plugins/utils/muxer/muxer.c index 7404e1e4..8571b275 100644 --- a/src/plugins/utils/muxer/muxer.c +++ b/src/plugins/utils/muxer/muxer.c @@ -1214,6 +1214,7 @@ end: BT_HIDDEN bt_component_class_message_iterator_init_method_status muxer_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp, bt_self_component_port_output *port) { diff --git a/src/plugins/utils/muxer/muxer.h b/src/plugins/utils/muxer/muxer.h index 8c3f7f48..d5eef7ef 100644 --- a/src/plugins/utils/muxer/muxer.h +++ b/src/plugins/utils/muxer/muxer.h @@ -40,6 +40,7 @@ void muxer_finalize(bt_self_component_filter *self_comp); BT_HIDDEN bt_component_class_message_iterator_init_method_status muxer_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp, bt_self_component_port_output *self_port); diff --git a/src/plugins/utils/trimmer/trimmer.c b/src/plugins/utils/trimmer/trimmer.c index 92fad09b..4e89581f 100644 --- a/src/plugins/utils/trimmer/trimmer.c +++ b/src/plugins/utils/trimmer/trimmer.c @@ -664,6 +664,7 @@ void destroy_trimmer_iterator_stream_state( BT_HIDDEN bt_component_class_message_iterator_init_method_status trimmer_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp, bt_self_component_port_output *port) { diff --git a/src/plugins/utils/trimmer/trimmer.h b/src/plugins/utils/trimmer/trimmer.h index 34d45efa..7bf5aaa4 100644 --- a/src/plugins/utils/trimmer/trimmer.h +++ b/src/plugins/utils/trimmer/trimmer.h @@ -43,6 +43,7 @@ bt_component_class_init_method_status trimmer_init( BT_HIDDEN bt_component_class_message_iterator_init_method_status trimmer_msg_iter_init( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp, bt_self_component_port_output *port); diff --git a/tests/bindings/python/bt2/test_clock_class.py b/tests/bindings/python/bt2/test_clock_class.py index 26571bd4..c4b34bd2 100644 --- a/tests/bindings/python/bt2/test_clock_class.py +++ b/tests/bindings/python/bt2/test_clock_class.py @@ -247,7 +247,7 @@ class ClockSnapshotTestCase(unittest.TestCase): self._cc = _cc class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): self._at = 0 def __next__(self): diff --git a/tests/bindings/python/bt2/test_event.py b/tests/bindings/python/bt2/test_event.py index b6b17ade..4288fd91 100644 --- a/tests/bindings/python/bt2/test_event.py +++ b/tests/bindings/python/bt2/test_event.py @@ -39,7 +39,7 @@ class EventTestCase(unittest.TestCase): with_packet=False, ): class MyIter(bt2._UserMessageIterator): - def __init__(self, self_output_port): + def __init__(self, config, self_output_port): self._at = 0 self._msgs = [self._create_stream_beginning_message(test_obj.stream)] diff --git a/tests/bindings/python/bt2/test_event_class.py b/tests/bindings/python/bt2/test_event_class.py index 6a6eb4cb..47606b0e 100644 --- a/tests/bindings/python/bt2/test_event_class.py +++ b/tests/bindings/python/bt2/test_event_class.py @@ -34,7 +34,7 @@ def _create_const_event_class(tc, stream_class): ) class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): trace = tc() stream = trace.create_stream(stream_class) diff --git a/tests/bindings/python/bt2/test_field.py b/tests/bindings/python/bt2/test_field.py index 6271b770..47755f2f 100644 --- a/tests/bindings/python/bt2/test_field.py +++ b/tests/bindings/python/bt2/test_field.py @@ -73,7 +73,7 @@ def _create_const_field(tc, field_class, field_value_setter_fn): field_name = 'const field' class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): nonlocal field_class nonlocal field_value_setter_fn stream = _create_stream(tc, [(field_name, field_class)]) diff --git a/tests/bindings/python/bt2/test_field_class.py b/tests/bindings/python/bt2/test_field_class.py index 3a383fdd..01c1a46a 100644 --- a/tests/bindings/python/bt2/test_field_class.py +++ b/tests/bindings/python/bt2/test_field_class.py @@ -41,7 +41,7 @@ def _create_const_field_class(tc, field_class, value_setter_fn): field_name = 'const field' class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): nonlocal field_class nonlocal value_setter_fn stream = _create_stream(tc, [(field_name, field_class)]) diff --git a/tests/bindings/python/bt2/test_graph.py b/tests/bindings/python/bt2/test_graph.py index 347f8803..744f6429 100644 --- a/tests/bindings/python/bt2/test_graph.py +++ b/tests/bindings/python/bt2/test_graph.py @@ -21,7 +21,7 @@ import bt2 class _MyIter(bt2._UserMessageIterator): - def __init__(self, self_output_port): + def __init__(self, config, self_output_port): self._build_meta() self._at = 0 diff --git a/tests/bindings/python/bt2/test_message.py b/tests/bindings/python/bt2/test_message.py index e58e5245..012c851f 100644 --- a/tests/bindings/python/bt2/test_message.py +++ b/tests/bindings/python/bt2/test_message.py @@ -34,7 +34,7 @@ from bt2 import trace_class as bt2_trace_class class AllMessagesTestCase(unittest.TestCase): def setUp(self): class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): self._at = 0 self._with_stream_msgs_clock_snapshots = self_port_output.user_data.get( 'with_stream_msgs_clock_snapshots', False diff --git a/tests/bindings/python/bt2/test_message_iterator.py b/tests/bindings/python/bt2/test_message_iterator.py index 39d80888..b331e4a4 100644 --- a/tests/bindings/python/bt2/test_message_iterator.py +++ b/tests/bindings/python/bt2/test_message_iterator.py @@ -21,6 +21,7 @@ import bt2 import sys from utils import TestOutputPortMessageIterator from bt2 import port as bt2_port +from bt2 import message_iterator as bt2_message_iterator class SimpleSink(bt2._UserSinkComponent): @@ -61,7 +62,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): the_output_port_from_iter = None class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): nonlocal initialized nonlocal the_output_port_from_iter initialized = True @@ -83,7 +84,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): def test_create_from_message_iterator(self): class MySourceIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): nonlocal src_iter_initialized src_iter_initialized = True @@ -92,7 +93,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): self._add_output_port('out') class MyFilterIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): nonlocal flt_iter_initialized flt_iter_initialized = True self._up_iter = self._create_input_port_message_iterator( @@ -120,7 +121,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): # and _UserMessageIterator._create_input_port_message_iterator, as they # are both used in the graph. class MySourceIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): raise ValueError('Very bad error') class MySource(bt2._UserSourceComponent, message_iterator_class=MySourceIter): @@ -128,7 +129,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): self._add_output_port('out') class MyFilterIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): # This is expected to raise because of the error in # MySourceIter.__init__. self._create_input_port_message_iterator( @@ -169,9 +170,74 @@ class UserMessageIteratorTestCase(unittest.TestCase): del graph self.assertTrue(finalized) + def test_config_parameter(self): + class MyIter(bt2._UserMessageIterator): + def __init__(self, config, port): + nonlocal config_type + config_type = type(config) + + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): + def __init__(self, config, params, obj): + self._add_output_port('out') + + config_type = None + graph = _create_graph(MySource, SimpleSink) + graph.run() + self.assertIs(config_type, bt2_message_iterator._MessageIteratorConfiguration) + + def _test_config_can_seek_forward(self, set_can_seek_forward): + class MyIter(bt2._UserMessageIterator): + def __init__(self, config, port): + if set_can_seek_forward: + config.can_seek_forward = True + + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): + def __init__(self, config, params, obj): + self._add_output_port('out') + + class MySink(bt2._UserSinkComponent): + def __init__(self, config, params, obj): + self._add_input_port('in') + + def _user_graph_is_configured(self): + self._msg_iter = self._create_input_port_message_iterator( + self._input_ports['in'] + ) + + def _user_consume(self): + nonlocal can_seek_forward + can_seek_forward = self._msg_iter.can_seek_forward + + can_seek_forward = None + graph = _create_graph(MySource, MySink) + graph.run_once() + self.assertIs(can_seek_forward, set_can_seek_forward) + + def test_config_can_seek_forward_default(self): + self._test_config_can_seek_forward(False) + + def test_config_can_seek_forward(self): + self._test_config_can_seek_forward(True) + + def test_config_can_seek_forward_wrong_type(self): + class MyIter(bt2._UserMessageIterator): + def __init__(self, config, port): + config.can_seek_forward = 1 + + class MySource(bt2._UserSourceComponent, message_iterator_class=MyIter): + def __init__(self, config, params, obj): + self._add_output_port('out') + + graph = _create_graph(MySource, SimpleSink) + with self.assertRaises(bt2._Error) as ctx: + graph.run() + + root_cause = ctx.exception[0] + self.assertIn("TypeError: 'int' is not a 'bool' object", root_cause.message) + def test_component(self): class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): nonlocal salut salut = self._component._salut @@ -187,7 +253,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): def test_port(self): class MyIter(bt2._UserMessageIterator): - def __init__(self_iter, self_port_output): + def __init__(self_iter, config, self_port_output): nonlocal called called = True port = self_iter._port @@ -206,7 +272,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): def test_addr(self): class MyIter(bt2._UserMessageIterator): - def __init__(self, self_port_output): + def __init__(self, config, self_port_output): nonlocal addr addr = self.addr @@ -224,7 +290,7 @@ class UserMessageIteratorTestCase(unittest.TestCase): # and can be re-used. def test_reuse_message(self): class MyIter(bt2._UserMessageIterator): - def __init__(self, port): + def __init__(self, config, port): tc, sc, ec = port.user_data trace = tc() stream = trace.create_stream(sc) @@ -322,7 +388,7 @@ def _setup_seek_test( user_can_seek_ns_from_origin=None, ): class MySourceIter(bt2._UserMessageIterator): - def __init__(self, port): + def __init__(self, config, port): tc, sc, ec = port.user_data trace = tc() stream = trace.create_stream(sc) @@ -367,7 +433,7 @@ def _setup_seek_test( self._add_output_port('out', (tc, sc, ec)) class MyFilterIter(bt2._UserMessageIterator): - def __init__(self, port): + def __init__(self, config, port): self._upstream_iter = self._create_input_port_message_iterator( self._component._input_ports['in'] ) diff --git a/tests/bindings/python/bt2/utils.py b/tests/bindings/python/bt2/utils.py index f0ddbff4..a7ea3cde 100644 --- a/tests/bindings/python/bt2/utils.py +++ b/tests/bindings/python/bt2/utils.py @@ -65,7 +65,7 @@ def _get_all_message_types(with_packet=True): _msgs = None class MyIter(bt2._UserMessageIterator): - def __init__(self, self_output_port): + def __init__(self, config, self_output_port): nonlocal _msgs self._at = 0 diff --git a/tests/data/auto-source-discovery/grouping/bt_plugin_test.py b/tests/data/auto-source-discovery/grouping/bt_plugin_test.py index dd4d5a4b..18c396eb 100644 --- a/tests/data/auto-source-discovery/grouping/bt_plugin_test.py +++ b/tests/data/auto-source-discovery/grouping/bt_plugin_test.py @@ -8,7 +8,7 @@ import os class TestIter(bt2._UserMessageIterator): - def __init__(self, output_port): + def __init__(self, config, output_port): inputs = output_port.user_data['inputs'] sc = output_port.user_data['sc'] tc = sc.trace_class diff --git a/tests/data/auto-source-discovery/params-log-level/bt_plugin_test.py b/tests/data/auto-source-discovery/params-log-level/bt_plugin_test.py index c39db50f..ddbf9771 100644 --- a/tests/data/auto-source-discovery/params-log-level/bt_plugin_test.py +++ b/tests/data/auto-source-discovery/params-log-level/bt_plugin_test.py @@ -12,7 +12,7 @@ import os class TestIter(bt2._UserMessageIterator): - def __init__(self, output_port): + def __init__(self, config, output_port): params = output_port.user_data['params'] obj = output_port.user_data['obj'] diff --git a/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py b/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py index b81c26db..c263d203 100644 --- a/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py +++ b/tests/data/plugins/flt.utils.muxer/bt_plugin_muxer_test.py @@ -2,7 +2,7 @@ import bt2 class TheIteratorOfConfusion(bt2._UserMessageIterator): - def __init__(self, port): + def __init__(self, config, port): self._at = 0 test_name = port.user_data[0] TEST_CASES[test_name].create_msgs(self, port.user_data[1:]) diff --git a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py index 3a37b329..9f337356 100644 --- a/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py +++ b/tests/data/plugins/flt.utils.trimmer/bt_plugin_trimmer_test.py @@ -2,7 +2,7 @@ import bt2 class TheIteratorOfAllEvil(bt2._UserMessageIterator): - def __init__(self, port): + def __init__(self, config, port): tc, sc, ec1, ec2, params = port.user_data trace = tc() stream = trace.create_stream(sc) diff --git a/tests/lib/test-plugin-plugins/sfs.c b/tests/lib/test-plugin-plugins/sfs.c index 93ca7110..229d0ede 100644 --- a/tests/lib/test-plugin-plugins/sfs.c +++ b/tests/lib/test-plugin-plugins/sfs.c @@ -27,6 +27,7 @@ static bt_component_class_sink_consume_method_status sink_consume( static bt_component_class_message_iterator_init_method_status src_dummy_iterator_init_method( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_source *self_comp, bt_self_component_port_output *self_port) { @@ -36,6 +37,7 @@ src_dummy_iterator_init_method( static bt_component_class_message_iterator_init_method_status flt_dummy_iterator_init_method( bt_self_message_iterator *self_msg_iter, + bt_self_message_iterator_configuration *config, bt_self_component_filter *self_comp, bt_self_component_port_output *self_port) { -- 2.34.1