2 # Copyright (C) 2019 EfficiOS Inc.
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
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.
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.
25 _TEST_PLUGIN_PLUGINS_PATH
= os
.environ
['TEST_PLUGIN_PLUGINS_PATH']
28 class PluginSetTestCase(unittest
.TestCase
):
29 def test_create(self
):
30 pset
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
)
31 self
.assertTrue(len(pset
) >= 3)
33 def test_getitem(self
):
34 pset
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
)
35 self
.assertTrue(pset
[0].path
.startswith(_TEST_PLUGIN_PLUGINS_PATH
))
38 pset
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
)
42 names
.add(plugin
.name
)
44 self
.assertTrue('ctf' in names
)
45 self
.assertTrue('utils' in names
)
46 self
.assertTrue('text' in names
)
49 class FindPluginsTestCase(unittest
.TestCase
):
50 def test_find_nonexistent_dir(self
):
51 with self
.assertRaises(bt2
.Error
):
52 bt2
.find_plugins('/this/does/not/exist/246703df-cb85-46d5-8406-5e8dc4a88b41')
54 def test_find_none_existing_dir(self
):
55 plugins
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
, recurse
=False)
56 self
.assertIsNone(plugins
)
58 def test_find_dir(self
):
59 pset
= bt2
.find_plugins(_TEST_PLUGIN_PLUGINS_PATH
)
60 self
.assertTrue(len(pset
) >= 3)
62 def test_find_file(self
):
63 path
= os
.path
.join(_TEST_PLUGIN_PLUGINS_PATH
, 'utils', '.libs', 'babeltrace-plugin-utils.so')
64 pset
= bt2
.find_plugins(path
)
65 self
.assertTrue(len(pset
) == 1)
68 class FindPluginTestCase(unittest
.TestCase
):
69 def test_find_none(self
):
70 plugin
= bt2
.find_plugin('this-does-not-exist-246703df-cb85-46d5-8406-5e8dc4a88b41')
71 self
.assertIsNone(plugin
)
73 def test_find_existing(self
):
74 plugin
= bt2
.find_plugin('ctf')
75 self
.assertIsInstance(plugin
, bt2
.plugin
._Plugin
)
78 class PluginTestCase(unittest
.TestCase
):
80 self
._plugin
= bt2
.find_plugin('ctf')
86 self
.assertEqual(self
._plugin
.name
, 'ctf')
89 plugin_path
= os
.path
.normcase(self
._plugin
.path
)
90 plugin_path_env
= os
.path
.normcase(_TEST_PLUGIN_PLUGINS_PATH
)
91 self
.assertTrue(plugin_path
.startswith(plugin_path_env
))
93 def test_author(self
):
94 self
.assertTrue('Philippe Proulx' in self
._plugin
.author
)
96 def test_license(self
):
97 self
.assertTrue('MIT' in self
._plugin
.license
)
99 def test_description(self
):
100 self
.assertTrue('CTF source and sink support' in self
._plugin
.description
)
102 def test_version(self
):
103 self
.assertIsNone(self
._plugin
.version
)
105 def test_source_comp_classes_len(self
):
106 self
.assertEqual(len(self
._plugin
.source_component_classes
), 2)
108 def test_source_comp_classes_getitem(self
):
109 self
.assertEqual(self
._plugin
.source_component_classes
['fs'].name
, 'fs')
111 def test_source_comp_classes_getitem_invalid(self
):
112 with self
.assertRaises(KeyError):
113 self
._plugin
.source_component_classes
['lol']
115 def test_source_comp_classes_iter(self
):
118 for cc_name
, cc
in self
._plugin
.source_component_classes
.items():
119 plugins
[cc_name
] = cc
121 self
.assertTrue('fs' in plugins
)
122 self
.assertTrue('lttng-live' in plugins
)
123 self
.assertEqual(plugins
['fs'].name
, 'fs')
124 self
.assertEqual(plugins
['lttng-live'].name
, 'lttng-live')
126 def test_filter_comp_classes_len(self
):
127 plugin
= bt2
.find_plugin('utils')
128 self
.assertEqual(len(plugin
.filter_component_classes
), 2)
130 def test_sink_comp_classes_len(self
):
131 self
.assertEqual(len(self
._plugin
.sink_component_classes
), 1)