コード例 #1
0
    def test_iter(self):
        pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
        names = set()

        for plugin in pset:
            names.add(plugin.name)

        self.assertTrue('ctf' in names)
        self.assertTrue('utils' in names)
        self.assertTrue('text' in names)
コード例 #2
0
 def test_python_plugin_provider(self):
     pset = bt2.find_plugins(os.environ['PYTHON_PLUGIN_PROVIDER_TEST_PLUGIN_PATH'])
     self.assertEqual(len(pset), 1)
     plugin = pset[0]
     self.assertEqual(plugin.name, 'sparkling')
     self.assertEqual(plugin.author, 'Philippe Proulx')
     self.assertEqual(plugin.description, 'A delicious plugin.')
     self.assertEqual(plugin.version.major, 1)
     self.assertEqual(plugin.version.minor, 2)
     self.assertEqual(plugin.version.patch, 3)
     self.assertEqual(plugin.version.extra, 'EXTRA')
     self.assertEqual(plugin.license, 'MIT')
     self.assertEqual(len(plugin.source_component_classes), 1)
     self.assertEqual(len(plugin.filter_component_classes), 1)
     self.assertEqual(len(plugin.sink_component_classes), 1)
     self.assertEqual(plugin.source_component_classes['MySource'].name, 'MySource')
     self.assertEqual(plugin.filter_component_classes['MyFilter'].name, 'MyFilter')
     self.assertEqual(plugin.sink_component_classes['MySink'].name, 'MySink')
コード例 #3
0
 def test_python_plugin_provider(self):
     path = os.environ['PYTHON_PLUGIN_PROVIDER_TEST_PLUGIN_PATH']
     pset = bt2.find_plugins(path)
     self.assertEqual(len(pset), 1)
     plugin = pset[0]
     self.assertEqual(plugin.name, 'sparkling')
     self.assertEqual(plugin.author, 'Philippe Proulx')
     self.assertEqual(plugin.description, 'A delicious plugin.')
     self.assertEqual(plugin.version.major, 1)
     self.assertEqual(plugin.version.minor, 2)
     self.assertEqual(plugin.version.patch, 3)
     self.assertEqual(plugin.version.extra, 'EXTRA')
     self.assertEqual(plugin.license, 'MIT')
     self.assertEqual(len(plugin.source_component_classes), 1)
     self.assertEqual(len(plugin.filter_component_classes), 1)
     self.assertEqual(len(plugin.sink_component_classes), 1)
     self.assertEqual(plugin.source_component_classes['MySource'].name,
                      'MySource')
     self.assertEqual(plugin.filter_component_classes['MyFilter'].name,
                      'MyFilter')
     self.assertEqual(plugin.sink_component_classes['MySink'].name,
                      'MySink')
コード例 #4
0
def _auto_discover_source_component_specs(auto_source_comp_specs, plugin_set):
    # Transform a list of `AutoSourceComponentSpec` in a list of `ComponentSpec`
    # using the automatic source discovery mechanism.
    inputs = bt2.ArrayValue([spec.input for spec in auto_source_comp_specs])

    if plugin_set is None:
        plugin_set = bt2.find_plugins()
    else:
        utils._check_type(plugin_set, bt2_plugin._PluginSet)

    res_ptr = native_bt.bt2_auto_discover_source_components(
        inputs._ptr, plugin_set._ptr)

    if res_ptr is None:
        raise bt2._MemoryError('cannot auto discover source components')

    res = bt2_value._create_from_ptr(res_ptr)

    assert type(res) == bt2.MapValue
    assert 'status' in res

    status = res['status']
    utils._handle_func_status(status, 'cannot auto-discover source components')

    comp_specs = []
    comp_specs_raw = res['results']
    assert type(comp_specs_raw) == bt2.ArrayValue

    used_input_indices = set()

    for comp_spec_raw in comp_specs_raw:
        assert type(comp_spec_raw) == bt2.ArrayValue
        assert len(comp_spec_raw) == 4

        plugin_name = comp_spec_raw[0]
        assert type(plugin_name) == bt2.StringValue
        plugin_name = str(plugin_name)

        class_name = comp_spec_raw[1]
        assert type(class_name) == bt2.StringValue
        class_name = str(class_name)

        comp_inputs = comp_spec_raw[2]
        assert type(comp_inputs) == bt2.ArrayValue

        comp_orig_indices = comp_spec_raw[3]
        assert type(comp_orig_indices)

        params = bt2.MapValue()
        logging_level = bt2.LoggingLevel.NONE
        obj = None

        # Compute `params` for this component by piling up params given to all
        # AutoSourceComponentSpec objects that contributed in the instantiation
        # of this component.
        #
        # The effective log level for a component is the last one specified
        # across the AutoSourceComponentSpec that contributed in its
        # instantiation.
        for idx in comp_orig_indices:
            orig_spec = auto_source_comp_specs[idx]

            if orig_spec.params is not None:
                params.update(orig_spec.params)

            if orig_spec.logging_level is not None:
                logging_level = orig_spec.logging_level

            if orig_spec.obj is not AutoSourceComponentSpec._no_obj:
                obj = orig_spec.obj

            used_input_indices.add(int(idx))

        params['inputs'] = comp_inputs

        comp_specs.append(
            ComponentSpec.from_named_plugin_and_component_class(
                plugin_name,
                class_name,
                params=params,
                obj=obj,
                logging_level=logging_level,
            ))

    if len(used_input_indices) != len(inputs):
        unused_input_indices = set(range(len(inputs))) - used_input_indices
        unused_input_indices = sorted(unused_input_indices)
        unused_inputs = [str(inputs[x]) for x in unused_input_indices]

        msg = (
            'Some auto source component specs did not produce any component: '
            + ', '.join(unused_inputs))
        raise RuntimeError(msg)

    return comp_specs
コード例 #5
0
 def test_find_dir(self):
     pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
     self.assertTrue(len(pset) >= 3)
コード例 #6
0
 def test_find_none(self):
     pset = bt2.find_plugins('/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41')
     self.assertIsNone(pset)
コード例 #7
0
 def test_getitem(self):
     pset = bt2.find_plugins(_TEST_PLUGIN_PLUGINS_PATH)
     self.assertTrue(pset[0].path.startswith(_TEST_PLUGIN_PLUGINS_PATH))
コード例 #8
0
 def test_find_file(self):
     path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', 'babeltrace-plugin-utils.so')
     pset = bt2.find_plugins(path)
     self.assertTrue(len(pset) == 1)