lib: bt_graph_create(): accept MIP version
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Sun, 11 Aug 2019 03:24:13 +0000 (23:24 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 13 Aug 2019 00:28:02 +0000 (20:28 -0400)
This patch makes bt_graph_create() accept the message interchange
protocol (MIP) version with which to configure the graph.

This MIP version will usually come from
bt_get_greatest_operative_mip_version() or bt_get_maximal_mip_version().

The components can access the configured MIP version with
bt_self_component_get_graph_mip_version().

As of this patch the only possible MIP version is 0. bt_graph_create()
does not accept a MIP version that is greater than
bt_get_maximal_mip_version() because almost all the library functions
need to know the configured MIP version to behave accordingly, should
the semantics change in the future.

In Python, Graph.__init__() accepts a `mip_version` parameter which
defaults to 0. A Python component can get the configured MIP version of
its operating graph with the `_UserComponent._graph_mip_version`
property.

All the sites where bt_graph_create() is called pass 0 to it. This is
correct for tests as we always control the component classes and
initialization parameters, so we know that 0 is always supported by
them. The locations where bt_get_greatest_operative_mip_version() must
be used are the CLI and `bt2.TraceCollectionMessageIterator`. Those
sites will be addressed by subsequent patches.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: I324a317922a8caa5557043ae02b97e58fc91d92d
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1878
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
14 files changed:
include/babeltrace2/graph/graph.h
include/babeltrace2/graph/self-component.h
src/bindings/python/bt2/bt2/component.py
src/bindings/python/bt2/bt2/graph.py
src/cli/babeltrace2.c
src/lib/graph/component.c
src/lib/graph/graph.c
src/lib/graph/graph.h
tests/bindings/python/bt2/test_component.py
tests/bindings/python/bt2/test_graph.py
tests/lib/plugin.c
tests/lib/test_graph_topo.c
tests/lib/test_simple_sink.c
tests/lib/test_trace_ir_ref.c

index 284eb0e8abc79b30efdeefdd5a08aa07d7ce7264..981fd6a4c126d865dc7a3e71282883ef442feb47 100644 (file)
@@ -117,7 +117,7 @@ typedef bt_graph_simple_sink_component_consume_func_status
 
 typedef void (*bt_graph_simple_sink_component_finalize_func)(void *data);
 
-extern bt_graph *bt_graph_create(void);
+extern bt_graph *bt_graph_create(uint64_t mip_version);
 
 typedef enum bt_graph_add_component_status {
        BT_GRAPH_ADD_COMPONENT_STATUS_OK                = __BT_FUNC_STATUS_OK,
index f85a50fc6889f8c483f6904cec227db70c4a2384..ba722d9813cfd95e6e87c5899b5cfa507e9250e1 100644 (file)
@@ -46,6 +46,9 @@ const bt_component *bt_self_component_as_component(
        return __BT_UPCAST(bt_component, self_component);
 }
 
+extern
+uint64_t bt_self_component_get_graph_mip_version(bt_self_component *self_component);
+
 extern void *bt_self_component_get_data(
                const bt_self_component *self_component);
 
index 2d0cd922a1a07730b830ca35c0aeecef5deaf881..a68da615f1b542f187cc0637c83f4b7f325d94f1 100644 (file)
@@ -677,6 +677,11 @@ class _UserComponent(metaclass=_UserComponentType):
     def addr(self):
         return int(self._bt_ptr)
 
+    @property
+    def _graph_mip_version(self):
+        ptr = self._bt_as_self_component_ptr(self._bt_ptr)
+        return native_bt.self_component_get_graph_mip_version(ptr)
+
     def __init__(self, params=None, obj=None):
         pass
 
index 3812788f0b4bc05a9e2f08adbf8f82f76c8f2498..6c9db7ec96a24b4e97d4b44c993fc2c2a6100514 100644 (file)
@@ -70,8 +70,13 @@ class Graph(object._SharedObject):
     _get_ref = staticmethod(native_bt.graph_get_ref)
     _put_ref = staticmethod(native_bt.graph_put_ref)
 
-    def __init__(self):
-        ptr = native_bt.graph_create()
+    def __init__(self, mip_version=0):
+        utils._check_uint64(mip_version)
+
+        if mip_version > bt2.get_maximal_mip_version():
+            raise ValueError('unknown MIP version {}'.format(mip_version))
+
+        ptr = native_bt.graph_create(mip_version)
 
         if ptr is None:
             raise bt2._MemoryError('cannot create graph object')
index 66743c975ef5166317e13b888af112a7dad2bec6..b67acd74cac7aa708292ccbde5eb0ddecef88286 100644 (file)
@@ -1745,7 +1745,7 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
                }
        }
 
-       ctx->graph = bt_graph_create();
+       ctx->graph = bt_graph_create(0);
        if (!ctx->graph) {
                goto error;
        }
index 11144fb42c400eb531b8fa8340f43ef3d0a1eaec..2aed6932ffad144d9ed69b24acaeca9ba3cfb5ff 100644 (file)
@@ -605,6 +605,15 @@ bt_logging_level bt_component_get_logging_level(
        return component->log_level;
 }
 
+uint64_t bt_self_component_get_graph_mip_version(
+               bt_self_component *self_component)
+{
+       struct bt_component *comp = (void *) self_component;
+
+       BT_ASSERT_PRE_NON_NULL(self_component, "Component");
+       return bt_component_borrow_graph(comp)->mip_version;
+}
+
 void bt_component_get_ref(const struct bt_component *component)
 {
        bt_object_get_ref(component);
index ebcd9db8954ec08a26cfeaa2f922b843b59916aa..70c42c6a3f007c646bbe5fe61de8b27492ab6680 100644 (file)
@@ -262,11 +262,15 @@ void notify_message_graph_is_destroyed(struct bt_message *msg)
        bt_message_unlink_graph(msg);
 }
 
-struct bt_graph *bt_graph_create(void)
+struct bt_graph *bt_graph_create(uint64_t mip_version)
 {
        struct bt_graph *graph;
        int ret;
 
+       BT_ASSERT_PRE(mip_version <= bt_get_maximal_mip_version(),
+               "Unknown MIP version: mip-version=%" PRIu64 ", "
+               "max-mip-version=%" PRIu64,
+               mip_version, bt_get_maximal_mip_version());
        BT_LOGI_STR("Creating graph object.");
        graph = g_new0(struct bt_graph, 1);
        if (!graph) {
@@ -275,6 +279,7 @@ struct bt_graph *bt_graph_create(void)
        }
 
        bt_object_init_shared(&graph->base, destroy_graph);
+       graph->mip_version = mip_version;
        graph->connections = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_object_try_spec_release);
        if (!graph->connections) {
index 5cda8a1d69ce067da824a6fcdcb2ede250f4e8a7..72cf121b7b4a0f120e10ee720ad259fed378a8d1 100644 (file)
@@ -90,6 +90,8 @@ struct bt_graph {
        /* Queue of pointers (weak references) to sink bt_components. */
        GQueue *sinks_to_consume;
 
+       uint64_t mip_version;
+
        /*
         * Array of `struct bt_interrupter *`, each one owned by this.
         * If any interrupter is set, then this graph is deemed
index 59a9bc195b261cff5f4429681bd1fd5d9682cc57..65338c199b5946b5e7da0ce586dea54d281527d4 100644 (file)
@@ -50,6 +50,16 @@ class UserComponentTestCase(unittest.TestCase):
 
         comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
 
+    def test_graph_mip_version(self):
+        class MySink(bt2._UserSinkComponent):
+            def __init__(comp_self, params, obj):
+                self.assertEqual(comp_self._graph_mip_version, 0)
+
+            def _user_consume(self):
+                pass
+
+        comp = self._create_comp(MySink, 'yaes', bt2.LoggingLevel.INFO)
+
     def test_class(self):
         class MySink(bt2._UserSinkComponent):
             def __init__(comp_self, params, obj):
index 0c9d9279851ed2ae0f335767fee928f5cee66448..b719d9ca133e7b6956e7bbdb72a0bfc257f4ae01 100644 (file)
@@ -51,8 +51,19 @@ class GraphTestCase(unittest.TestCase):
     def tearDown(self):
         del self._graph
 
-    def test_create_empty(self):
-        graph = bt2.Graph()
+    def test_create_default(self):
+        bt2.Graph()
+
+    def test_create_known_mip_version(self):
+        bt2.Graph(0)
+
+    def test_create_invalid_mip_version_type(self):
+        with self.assertRaises(TypeError):
+            bt2.Graph('')
+
+    def test_create_unknown_mip_version(self):
+        with self.assertRaisesRegex(ValueError, 'unknown MIP version'):
+            bt2.Graph(1)
 
     def test_add_component_user_cls(self):
         class MySink(bt2._UserSinkComponent):
index 3b5c05fcc2f4a2fb91a9899300c72e155e2bdb3c..a5bbe0c761613a3c2ab7901c23dbe0ea039b7b20 100644 (file)
@@ -199,7 +199,7 @@ static void test_sfs(const char *plugin_dir)
        bt_component_class_sink_get_ref(sink_comp_class);
        diag("> putting the plugin set object here");
        BT_PLUGIN_SET_PUT_REF_AND_RESET(plugin_set);
-       graph = bt_graph_create();
+       graph = bt_graph_create(0);
        BT_ASSERT(graph);
        graph_ret = bt_graph_add_sink_component(graph, sink_comp_class,
                "the-sink", NULL, BT_LOGGING_LEVEL_NONE, &sink_component);
index 5efffde951a5254091072e451b3ef5b2cbfcd027..ae2da5aa72437074516ab215574ade6723de7734 100644 (file)
@@ -449,7 +449,7 @@ const bt_component_sink *create_sink(bt_graph *graph)
 static
 bt_graph *create_graph(void)
 {
-       bt_graph *graph = bt_graph_create();
+       bt_graph *graph = bt_graph_create(0);
        int ret;
 
        BT_ASSERT(graph);
index f0599bb837c947ba54792bed278da62a273c1f70..31e2b6f7bf157baa87dcda7ede16ccbf9d999b56 100644 (file)
@@ -94,7 +94,7 @@ bt_graph *create_graph_with_source(const bt_port_output **out_port)
        set_method_status = bt_component_class_source_set_init_method(
                src_comp_cls, src_init);
        BT_ASSERT(set_method_status == BT_COMPONENT_CLASS_SET_METHOD_STATUS_OK);
-       graph = bt_graph_create();
+       graph = bt_graph_create(0);
        BT_ASSERT(graph);
        add_comp_status = bt_graph_add_source_component(graph, src_comp_cls,
                "src", NULL, BT_LOGGING_LEVEL_NONE, &src_comp);
index 7eeef185a76b2261eab639ffce4cd806e074334b..33591800bc381a3085b49f5a38f568b8d773bff3 100644 (file)
@@ -436,7 +436,7 @@ static void test_example_scenario_in_graph(void)
        BT_ASSERT(comp_cls);
        ret = bt_component_class_source_set_init_method(comp_cls, src_init);
        BT_ASSERT(ret == 0);
-       graph = bt_graph_create();
+       graph = bt_graph_create(0);
        ret = bt_graph_add_source_component(graph, comp_cls, "src-comp",
                NULL, BT_LOGGING_LEVEL_NONE, NULL);
        BT_ASSERT(ret == 0);
This page took 0.030299 seconds and 4 git commands to generate.