#include <babeltrace/ref.h>
#include <babeltrace/values.h>
#include <babeltrace/graph/component.h>
+#include <babeltrace/graph/graph.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include <glib.h>
-#include <linux/limits.h>
#include "tap/tap.h"
#include "common.h"
#define NON_EXISTING_PATH "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so"
/* Those symbols are written to by some test plugins */
-int test_plugin_init_called;
-int test_plugin_exit_called;
+static int check_env_var(const char *name)
+{
+ const char *val = getenv(name);
+
+ if (!val) {
+ return -1;
+ }
-static void reset_test_plugin_symbols(void)
+ return atoi(val);
+}
+
+static void reset_test_plugin_env_vars(void)
{
- test_plugin_init_called = 0;
- test_plugin_exit_called = 0;
+ g_setenv("BT_TEST_PLUGIN_INIT_CALLED", "0", 1);
+ g_setenv("BT_TEST_PLUGIN_EXIT_CALLED", "0", 1);
}
static char *get_test_plugin_path(const char *plugin_dir,
const char *plugin_name)
{
- GString *path = g_string_new(plugin_dir);
char *ret;
+ char *plugin_file_name;
+
+ if (asprintf(&plugin_file_name, "plugin-%s." G_MODULE_SUFFIX,
+ plugin_name) == -1) {
+ abort();
+ }
+
+ ret = g_build_filename(plugin_dir, plugin_file_name, NULL);
+ free(plugin_file_name);
- assert(path);
- g_string_append_printf(path, "/plugin-%s.so", plugin_name);
- ret = path->str;
- g_string_free(path, FALSE);
return ret;
}
{
struct bt_plugin_set *plugin_set;
+ diag("invalid plugin test below");
+
plugin_set = bt_plugin_create_all_from_file(NON_EXISTING_PATH);
ok(!plugin_set, "bt_plugin_create_all_from_file() fails with a non-existing file");
ok(!bt_plugin_create_all_from_file(NULL),
"bt_plugin_create_all_from_file() handles NULL correctly");
- ok(!bt_plugin_create_all_from_dir(NULL, false),
+ ok(!bt_plugin_create_all_from_dir(NULL, BT_FALSE),
"bt_plugin_create_all_from_dir() handles NULL correctly");
ok(!bt_plugin_get_name(NULL),
"bt_plugin_get_name() handles NULL correctly");
"bt_plugin_get_path() handles NULL correctly");
ok(bt_plugin_get_component_class_count(NULL) < 0,
"bt_plugin_get_component_class_count() handles NULL correctly");
- ok(!bt_plugin_get_component_class(NULL, 0),
- "bt_plugin_get_component_class() handles NULL correctly");
+ ok(!bt_plugin_get_component_class_by_index(NULL, 0),
+ "bt_plugin_get_component_class_by_index() handles NULL correctly");
ok(!bt_plugin_get_component_class_by_name_and_type(NULL, NULL, 0),
"bt_plugin_get_component_class_by_name_and_type() handles NULL correctly");
}
assert(minimal_path);
diag("minimal plugin test below");
- reset_test_plugin_symbols();
+ reset_test_plugin_env_vars();
plugin_set = bt_plugin_create_all_from_file(minimal_path);
ok(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1,
"bt_plugin_create_all_from_file() succeeds with a valid file");
- ok(test_plugin_init_called, "plugin's initialization function is called during bt_plugin_create_all_from_file()");
+ ok(check_env_var("BT_TEST_PLUGIN_INIT_CALLED") == 1,
+ "plugin's initialization function is called during bt_plugin_create_all_from_file()");
ok(bt_plugin_set_get_plugin_count(plugin_set) == 1,
"bt_plugin_create_all_from_file() returns the expected number of plugins");
plugin = bt_plugin_set_get_plugin(plugin_set, 0);
"bt_plugin_get_component_class_count() returns the expected value");
bt_put(plugin);
bt_put(plugin_set);
- ok(test_plugin_exit_called, "plugin's exit function is called when the plugin is destroyed");
+ ok(check_env_var("BT_TEST_PLUGIN_EXIT_CALLED") == 1,
+ "plugin's exit function is called when the plugin is destroyed");
free(minimal_path);
}
struct bt_value *results;
struct bt_value *object;
struct bt_value *res_params;
+ struct bt_graph *graph;
const char *object_str;
- int ret;
+ enum bt_value_status value_ret;
+ enum bt_graph_status graph_ret;
assert(sfs_path);
diag("sfs plugin test below");
assert(bt_value_is_array(results) && bt_value_array_size(results) == 2);
object = bt_value_array_get(results, 0);
assert(object && bt_value_is_string(object));
- ret = bt_value_string_get(object, &object_str);
- assert(ret == 0);
+ value_ret = bt_value_string_get(object, &object_str);
+ assert(value_ret == BT_VALUE_STATUS_OK);
ok(strcmp(object_str, "get-something") == 0,
"bt_component_class_query() receives the expected object name");
res_params = bt_value_array_get(results, 1);
diag("> putting the plugin object here");
BT_PUT(plugin);
- sink_component = bt_component_create(sink_comp_class, NULL, NULL);
- ok(sink_component, "bt_component_create() still works after the plugin object is destroyed");
+ graph = bt_graph_create();
+ assert(graph);
+ graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
+ NULL, &sink_component);
+ ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
+ "bt_graph_add_component() still works after the plugin object is destroyed");
BT_PUT(sink_component);
BT_PUT(source_comp_class);
- sink_component = bt_component_create(sink_comp_class, NULL, NULL);
- ok(sink_component, "bt_component_create() still works after the source component class object is destroyed");
+ bt_put(graph);
+ graph = bt_graph_create();
+ assert(graph);
+ graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
+ NULL, &sink_component);
+ ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
+ "bt_graph_add_component() still works after the source component class object is destroyed");
BT_PUT(sink_component);
BT_PUT(filter_comp_class);
- sink_component = bt_component_create(sink_comp_class, NULL, NULL);
- ok(sink_component, "bt_component_create() still works after the filter component class object is destroyed");
+ bt_put(graph);
+ graph = bt_graph_create();
+ assert(graph);
+ graph_ret = bt_graph_add_component(graph, sink_comp_class, "the-sink",
+ NULL, &sink_component);
+ ok(graph_ret == BT_GRAPH_STATUS_OK && sink_component,
+ "bt_graph_add_component() still works after the filter component class object is destroyed");
BT_PUT(sink_comp_class);
BT_PUT(sink_component);
free(sfs_path);
+ bt_put(graph);
bt_put(plugin_set);
bt_put(object);
bt_put(res_params);
diag("create from all test below");
- plugin_set = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, false);
+ plugin_set = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, BT_FALSE);
ok(!plugin_set,
"bt_plugin_create_all_from_dir() fails with an invalid path");
- plugin_set = bt_plugin_create_all_from_dir(plugin_dir, false);
+ plugin_set = bt_plugin_create_all_from_dir(plugin_dir, BT_FALSE);
ok(plugin_set, "bt_plugin_create_all_from_dir() succeeds with a valid path");
/* 2 or 4, if `.la` files are considered or not */
static void test_find(const char *plugin_dir)
{
+ int ret;
struct bt_plugin *plugin;
struct bt_component_class *comp_cls_sink;
struct bt_component_class *comp_cls_source;
"bt_plugin_find() handles NULL");
ok(!bt_plugin_find(NON_EXISTING_PATH),
"bt_plugin_find() returns NULL with an unknown plugin name");
- plugin_path = malloc(PATH_MAX * 5);
- assert(plugin_path);
- sprintf(plugin_path, "%s:/ec1d09e5-696c-442e-b1c3-f9c6cf7f5958:::%s:8db46494-a398-466a-9649-c765ae077629:",
+ ret = asprintf(&plugin_path, "%s" G_SEARCHPATH_SEPARATOR_S
+ G_DIR_SEPARATOR_S "ec1d09e5-696c-442e-b1c3-f9c6cf7f5958"
+ G_SEARCHPATH_SEPARATOR_S G_SEARCHPATH_SEPARATOR_S
+ G_SEARCHPATH_SEPARATOR_S "%s" G_SEARCHPATH_SEPARATOR_S
+ "8db46494-a398-466a-9649-c765ae077629"
+ G_SEARCHPATH_SEPARATOR_S,
NON_EXISTING_PATH, plugin_dir);
- setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
+ assert(ret > 0 && plugin_path);
+ g_setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
plugin = bt_plugin_find("test_minimal");
ok(plugin,
"bt_plugin_find() succeeds with a plugin name it can find");