Commit | Line | Data |
---|---|---|
32d2d479 MJ |
1 | # |
2 | # Copyright (C) 2019 EfficiOS Inc. | |
3 | # | |
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; only version 2 | |
7 | # of the License. | |
8 | # | |
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
13 | # | |
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | # | |
18 | ||
f6a5e476 | 19 | import unittest |
f6a5e476 | 20 | import bt2 |
f6a5e476 PP |
21 | import os |
22 | ||
23 | ||
abdabab5 | 24 | _TEST_PLUGIN_PLUGINS_PATH = os.environ['BT_PLUGINS_PATH'] |
a06a8e63 | 25 | _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS = {'cygwin': 'dll', 'mingw': 'dll'} |
f6a5e476 PP |
26 | |
27 | ||
28 | class PluginSetTestCase(unittest.TestCase): | |
29 | def test_create(self): | |
7d8f15e6 | 30 | pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH) |
f6a5e476 PP |
31 | self.assertTrue(len(pset) >= 3) |
32 | ||
33 | def test_getitem(self): | |
7d8f15e6 | 34 | pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH) |
f6a5e476 PP |
35 | self.assertTrue(pset[0].path.startswith(_TEST_PLUGIN_PLUGINS_PATH)) |
36 | ||
37 | def test_iter(self): | |
7d8f15e6 | 38 | pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH) |
f6a5e476 PP |
39 | names = set() |
40 | ||
41 | for plugin in pset: | |
42 | names.add(plugin.name) | |
43 | ||
44 | self.assertTrue('ctf' in names) | |
45 | self.assertTrue('utils' in names) | |
46 | self.assertTrue('text' in names) | |
47 | ||
48 | ||
49 | class FindPluginsTestCase(unittest.TestCase): | |
01f50d54 | 50 | def test_find_nonexistent_dir(self): |
3b2be708 | 51 | with self.assertRaises(ValueError): |
7d8f15e6 | 52 | bt2.find_plugins_in_path( |
61d96b89 FD |
53 | '/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41' |
54 | ) | |
01f50d54 PP |
55 | |
56 | def test_find_none_existing_dir(self): | |
7d8f15e6 | 57 | plugins = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH, recurse=False) |
01f50d54 | 58 | self.assertIsNone(plugins) |
f6a5e476 PP |
59 | |
60 | def test_find_dir(self): | |
7d8f15e6 | 61 | pset = bt2.find_plugins_in_path(_TEST_PLUGIN_PLUGINS_PATH) |
f6a5e476 PP |
62 | self.assertTrue(len(pset) >= 3) |
63 | ||
bb93d641 | 64 | def test_find_file(self): |
61d96b89 FD |
65 | extension = _TEST_PLUGIN_PLUGIN_EXTENSION_BY_OS.get( |
66 | os.environ['BT_OS_TYPE'], 'so' | |
67 | ) | |
a06a8e63 JR |
68 | plugin_name = 'babeltrace-plugin-utils.{}'.format(extension) |
69 | path = os.path.join(_TEST_PLUGIN_PLUGINS_PATH, 'utils', '.libs', plugin_name) | |
7d8f15e6 | 70 | pset = bt2.find_plugins_in_path(path) |
bb93d641 SM |
71 | self.assertTrue(len(pset) == 1) |
72 | ||
f6a5e476 PP |
73 | |
74 | class FindPluginTestCase(unittest.TestCase): | |
75 | def test_find_none(self): | |
61d96b89 FD |
76 | plugin = bt2.find_plugin( |
77 | 'this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41' | |
78 | ) | |
f6a5e476 PP |
79 | self.assertIsNone(plugin) |
80 | ||
81 | def test_find_existing(self): | |
7d8f15e6 | 82 | plugin = bt2.find_plugin('ctf', find_in_user_dir=False, find_in_sys_dir=False) |
36153ada | 83 | self.assertIsNotNone(plugin) |
f6a5e476 PP |
84 | |
85 | ||
86 | class PluginTestCase(unittest.TestCase): | |
87 | def setUp(self): | |
46d1ee16 PP |
88 | self._plugin = bt2.find_plugin( |
89 | 'ctf', find_in_user_dir=False, find_in_sys_dir=False | |
90 | ) | |
f6a5e476 PP |
91 | |
92 | def tearDown(self): | |
93 | del self._plugin | |
94 | ||
95 | def test_name(self): | |
96 | self.assertEqual(self._plugin.name, 'ctf') | |
97 | ||
98 | def test_path(self): | |
a85355e7 JR |
99 | plugin_path = os.path.abspath(os.path.normcase(self._plugin.path)) |
100 | plugin_path_env = os.path.abspath(os.path.normcase(_TEST_PLUGIN_PLUGINS_PATH)) | |
0592c0fe | 101 | self.assertTrue(plugin_path.startswith(plugin_path_env)) |
f6a5e476 PP |
102 | |
103 | def test_author(self): | |
aa3a5520 | 104 | self.assertEqual(self._plugin.author, 'EfficiOS <https://www.efficios.com/>') |
f6a5e476 PP |
105 | |
106 | def test_license(self): | |
aa3a5520 | 107 | self.assertEqual(self._plugin.license, 'MIT') |
f6a5e476 PP |
108 | |
109 | def test_description(self): | |
aa3a5520 | 110 | self.assertEqual(self._plugin.description, 'CTF input and output') |
f6a5e476 PP |
111 | |
112 | def test_version(self): | |
113 | self.assertIsNone(self._plugin.version) | |
114 | ||
115 | def test_source_comp_classes_len(self): | |
116 | self.assertEqual(len(self._plugin.source_component_classes), 2) | |
117 | ||
118 | def test_source_comp_classes_getitem(self): | |
119 | self.assertEqual(self._plugin.source_component_classes['fs'].name, 'fs') | |
120 | ||
121 | def test_source_comp_classes_getitem_invalid(self): | |
122 | with self.assertRaises(KeyError): | |
123 | self._plugin.source_component_classes['lol'] | |
124 | ||
125 | def test_source_comp_classes_iter(self): | |
126 | plugins = {} | |
127 | ||
128 | for cc_name, cc in self._plugin.source_component_classes.items(): | |
129 | plugins[cc_name] = cc | |
130 | ||
131 | self.assertTrue('fs' in plugins) | |
132 | self.assertTrue('lttng-live' in plugins) | |
133 | self.assertEqual(plugins['fs'].name, 'fs') | |
134 | self.assertEqual(plugins['lttng-live'].name, 'lttng-live') | |
135 | ||
136 | def test_filter_comp_classes_len(self): | |
46d1ee16 | 137 | plugin = bt2.find_plugin('utils', find_in_user_dir=False, find_in_sys_dir=False) |
f6a5e476 PP |
138 | self.assertEqual(len(plugin.filter_component_classes), 2) |
139 | ||
140 | def test_sink_comp_classes_len(self): | |
141 | self.assertEqual(len(self._plugin.sink_component_classes), 1) | |
3db06b1d SM |
142 | |
143 | ||
144 | if __name__ == '__main__': | |
145 | unittest.main() |