1 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright (C) 2019 EfficiOS Inc.
11 _TEST_PLUGIN_PLUGINS_PATH
= os
.environ
["BT_PLUGINS_PATH"]
12 _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS
= {"cygwin": "dll", "mingw": "dll"}
15 class PluginSetTestCase(unittest
.TestCase
):
16 def test_create(self
):
17 pset
= bt2
.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH
)
18 self
.assertTrue(len(pset
) >= 3)
20 def test_getitem(self
):
21 pset
= bt2
.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH
)
22 self
.assertTrue(pset
[0].path
.startswith(_TEST_PLUGIN_PLUGINS_PATH
))
25 pset
= bt2
.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH
)
29 names
.add(plugin
.name
)
31 self
.assertTrue("ctf" in names
)
32 self
.assertTrue("utils" in names
)
33 self
.assertTrue("text" in names
)
36 class FindPluginsTestCase(unittest
.TestCase
):
37 def test_find_nonexistent_dir(self
):
38 with self
.assertRaises(ValueError):
39 bt2
.find_plugins_in_path(
40 "/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41"
43 def test_find_none_existing_dir(self
):
44 plugins
= bt2
.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH
, recurse
=False)
45 self
.assertIsNone(plugins
)
47 def test_find_dir(self
):
48 pset
= bt2
.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH
)
49 self
.assertTrue(len(pset
) >= 3)
51 def test_find_file(self
):
52 extension
= _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS
.get(
53 os
.environ
["BT_TESTS_OS_TYPE"], "so"
55 plugin_name
= "babeltrace-plugin-utils.{}".format(extension
)
56 path
= os
.path
.join(_TEST_PLUGIN_PLUGINS_PATH
, "utils", ".libs", plugin_name
)
57 pset
= bt2
.find_plugins_in_path(path
)
58 self
.assertTrue(len(pset
) == 1)
61 class FindPluginTestCase(unittest
.TestCase
):
62 def test_find_none(self
):
63 plugin
= bt2
.find_plugin(
64 "this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41"
66 self
.assertIsNone(plugin
)
68 def test_find_existing(self
):
69 plugin
= bt2
.find_plugin("ctf", find_in_user_dir
=False, find_in_sys_dir
=False)
70 self
.assertIsNotNone(plugin
)
73 class PluginTestCase(unittest
.TestCase
):
75 self
._plugin
= bt2
.find_plugin(
76 "ctf", find_in_user_dir
=False, find_in_sys_dir
=False
83 self
.assertEqual(self
._plugin
.name
, "ctf")
86 plugin_path
= os
.path
.abspath(os
.path
.normcase(self
._plugin
.path
))
87 plugin_path_env
= os
.path
.abspath(os
.path
.normcase(_TEST_PLUGIN_PLUGINS_PATH
))
88 self
.assertTrue(plugin_path
.startswith(plugin_path_env
))
90 def test_author(self
):
91 self
.assertEqual(self
._plugin
.author
, "EfficiOS <https://www.efficios.com/>")
93 def test_license(self
):
94 self
.assertEqual(self
._plugin
.license
, "MIT")
96 def test_description(self
):
97 self
.assertEqual(self
._plugin
.description
, "CTF input and output")
99 def test_version(self
):
100 self
.assertIsNone(self
._plugin
.version
)
102 def test_source_comp_classes_len(self
):
103 self
.assertEqual(len(self
._plugin
.source_component_classes
), 2)
105 def test_source_comp_classes_getitem(self
):
106 self
.assertEqual(self
._plugin
.source_component_classes
["fs"].name
, "fs")
108 def test_source_comp_classes_getitem_invalid(self
):
109 with self
.assertRaises(KeyError):
110 self
._plugin
.source_component_classes
["lol"]
112 def test_source_comp_classes_iter(self
):
115 for cc_name
, cc
in self
._plugin
.source_component_classes
.items():
116 plugins
[cc_name
] = cc
118 self
.assertTrue("fs" in plugins
)
119 self
.assertTrue("lttng-live" in plugins
)
120 self
.assertEqual(plugins
["fs"].name
, "fs")
121 self
.assertEqual(plugins
["lttng-live"].name
, "lttng-live")
123 def test_filter_comp_classes_len(self
):
124 plugin
= bt2
.find_plugin("utils", find_in_user_dir
=False, find_in_sys_dir
=False)
125 self
.assertEqual(len(plugin
.filter_component_classes
), 2)
127 def test_sink_comp_classes_len(self
):
128 self
.assertEqual(len(self
._plugin
.sink_component_classes
), 1)
131 if __name__
== "__main__":