4 * CTF IR Reference Count test
6 * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; under version 2 of the License.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <babeltrace/plugin/plugin.h>
23 #include <babeltrace/ref.h>
24 #include <babeltrace/values.h>
34 #define NON_EXISTING_PATH "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so"
36 /* Those symbols are written to by some test plugins */
37 int test_plugin_init_called
;
38 int test_plugin_exit_called
;
40 static void reset_test_plugin_symbols(void)
42 test_plugin_init_called
= 0;
43 test_plugin_exit_called
= 0;
46 static char *get_test_plugin_path(const char *plugin_dir
,
47 const char *plugin_name
)
49 GString
*path
= g_string_new(plugin_dir
);
53 g_string_append_printf(path
, "/plugin-%s.so", plugin_name
);
55 g_string_free(path
, FALSE
);
59 static void test_invalid(const char *plugin_dir
)
61 struct bt_plugin
**plugins
;
63 plugins
= bt_plugin_create_all_from_file(NON_EXISTING_PATH
);
64 ok(!plugins
, "bt_plugin_create_all_from_file() fails with a non-existing file");
66 plugins
= bt_plugin_create_all_from_file(plugin_dir
);
67 ok(!plugins
, "bt_plugin_create_all_from_file() fails with a directory");
69 ok(!bt_plugin_create_all_from_file(NULL
),
70 "bt_plugin_create_all_from_file() handles NULL correctly");
71 ok(!bt_plugin_create_all_from_dir(NULL
, false),
72 "bt_plugin_create_all_from_dir() handles NULL correctly");
73 ok(!bt_plugin_get_name(NULL
),
74 "bt_plugin_get_name() handles NULL correctly");
75 ok(!bt_plugin_get_description(NULL
),
76 "bt_plugin_get_description() handles NULL correctly");
77 ok(!bt_plugin_get_author(NULL
),
78 "bt_plugin_get_author() handles NULL correctly");
79 ok(!bt_plugin_get_license(NULL
),
80 "bt_plugin_get_license() handles NULL correctly");
81 ok(!bt_plugin_get_path(NULL
),
82 "bt_plugin_get_path() handles NULL correctly");
83 ok(bt_plugin_get_component_class_count(NULL
) < 0,
84 "bt_plugin_get_component_class_count() handles NULL correctly");
85 ok(!bt_plugin_get_component_class(NULL
, 0),
86 "bt_plugin_get_component_class() handles NULL correctly");
87 ok(!bt_plugin_get_component_class_by_name_and_type(NULL
, NULL
, 0),
88 "bt_plugin_get_component_class_by_name_and_type() handles NULL correctly");
91 static void test_minimal(const char *plugin_dir
)
93 struct bt_plugin
**plugins
;
94 struct bt_plugin
*plugin
;
95 char *minimal_path
= get_test_plugin_path(plugin_dir
, "minimal");
98 diag("minimal plugin test below");
100 reset_test_plugin_symbols();
101 plugins
= bt_plugin_create_all_from_file(minimal_path
);
102 ok(plugins
&& plugins
[0], "bt_plugin_create_all_from_file() succeeds with a valid file");
103 ok(test_plugin_init_called
, "plugin's initialization function is called during bt_plugin_create_all_from_file()");
104 ok(plugins
&& plugins
[0] && !plugins
[1],
105 "bt_plugin_create_all_from_file() returns the expected number of plugins");
107 ok(strcmp(bt_plugin_get_name(plugin
), "test_minimal") == 0,
108 "bt_plugin_get_name() returns the expected name");
109 ok(strcmp(bt_plugin_get_description(plugin
),
110 "Minimal Babeltrace plugin with no component classes") == 0,
111 "bt_plugin_get_description() returns the expected description");
112 ok(strcmp(bt_plugin_get_author(plugin
), "Janine Sutto") == 0,
113 "bt_plugin_get_author() returns the expected author");
114 ok(strcmp(bt_plugin_get_license(plugin
), "Beerware") == 0,
115 "bt_plugin_get_license() returns the expected license");
116 ok(strcmp(bt_plugin_get_path(plugin
), minimal_path
) == 0,
117 "bt_plugin_get_path() returns the expected path");
118 ok(bt_plugin_get_component_class_count(plugin
) == 0,
119 "bt_plugin_get_component_class_count() returns the expected value");
121 ok(test_plugin_exit_called
, "plugin's exit function is called when the plugin is destroyed");
127 static void test_sfs(const char *plugin_dir
)
129 struct bt_plugin
**plugins
;
130 struct bt_plugin
*plugin
;
131 struct bt_component_class
*sink_comp_class
;
132 struct bt_component_class
*source_comp_class
;
133 struct bt_component_class
*filter_comp_class
;
134 struct bt_component
*sink_component
;
135 char *sfs_path
= get_test_plugin_path(plugin_dir
, "sfs");
138 diag("sfs plugin test below");
140 plugins
= bt_plugin_create_all_from_file(sfs_path
);
141 assert(plugins
&& plugins
[0]);
143 ok(bt_plugin_get_component_class_count(plugin
) == 3,
144 "bt_plugin_get_component_class_count() returns the expected value");
146 source_comp_class
= bt_plugin_get_component_class_by_name_and_type(
147 plugin
, "source", BT_COMPONENT_TYPE_SOURCE
);
148 ok(source_comp_class
,
149 "bt_plugin_get_component_class_by_name_and_type() finds a source component class");
151 sink_comp_class
= bt_plugin_get_component_class_by_name_and_type(
152 plugin
, "sink", BT_COMPONENT_TYPE_SINK
);
155 "bt_plugin_get_component_class_by_name_and_type() finds a sink component class");
156 filter_comp_class
= bt_plugin_get_component_class_by_name_and_type(
157 plugin
, "filter", BT_COMPONENT_TYPE_FILTER
);
159 ok(filter_comp_class
,
160 "bt_plugin_get_component_class_by_name_and_type() finds a filter component class");
161 ok(!bt_plugin_get_component_class_by_name_and_type(plugin
, "filter",
162 BT_COMPONENT_TYPE_SOURCE
),
163 "bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type");
165 diag("> putting the plugin object here");
167 sink_component
= bt_component_create(sink_comp_class
, NULL
, bt_value_null
);
168 ok(sink_component
, "bt_component_create() still works after the plugin object is destroyed");
169 BT_PUT(sink_component
);
170 BT_PUT(source_comp_class
);
171 sink_component
= bt_component_create(sink_comp_class
, NULL
, bt_value_null
);
172 ok(sink_component
, "bt_component_create() still works after the source component class object is destroyed");
173 BT_PUT(sink_component
);
174 BT_PUT(filter_comp_class
);
175 sink_component
= bt_component_create(sink_comp_class
, NULL
, bt_value_null
);
176 ok(sink_component
, "bt_component_create() still works after the filter component class object is destroyed");
177 BT_PUT(sink_comp_class
);
178 BT_PUT(sink_component
);
184 static void test_create_all_from_dir(const char *plugin_dir
)
186 struct bt_plugin
**plugins
;
187 struct bt_plugin
*plugin
;
190 diag("create from all test below");
192 plugins
= bt_plugin_create_all_from_dir(NON_EXISTING_PATH
, false);
194 "bt_plugin_create_all_from_dir() fails with an invalid path");
196 plugins
= bt_plugin_create_all_from_dir(plugin_dir
, false);
197 ok(plugins
, "bt_plugin_create_all_from_dir() succeeds with a valid path");
200 while ((plugin
= plugins
[i
])) {
205 /* 2 or 4, if `.la` files are considered or not */
206 ok(i
== 2 || i
== 4, "bt_plugin_create_all_from_dir() returns the expected number of plugin objects");
211 int main(int argc
, char **argv
)
214 const char *plugin_dir
;
217 puts("Usage: test_plugin plugin_directory");
222 plugin_dir
= argv
[1];
223 plan_tests(NR_TESTS
);
224 test_invalid(plugin_dir
);
225 test_minimal(plugin_dir
);
226 test_sfs(plugin_dir
);
227 test_create_all_from_dir(plugin_dir
);
This page took 0.035857 seconds and 6 git commands to generate.