#include <babeltrace/plugin/plugin.h>
#include <babeltrace/ref.h>
#include <babeltrace/values.h>
+#include <babeltrace/graph/component.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "tap/tap.h"
#include "common.h"
-#define NR_TESTS 44
+#define NR_TESTS 58
#define NON_EXISTING_PATH "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so"
/* Those symbols are written to by some test plugins */
static void test_invalid(const char *plugin_dir)
{
- struct bt_plugin **plugins;
+ struct bt_plugin_set *plugin_set;
- plugins = bt_plugin_create_all_from_file(NON_EXISTING_PATH);
- ok(!plugins, "bt_plugin_create_all_from_file() fails with a non-existing file");
+ 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");
- plugins = bt_plugin_create_all_from_file(plugin_dir);
- ok(!plugins, "bt_plugin_create_all_from_file() fails with a directory");
+ plugin_set = bt_plugin_create_all_from_file(plugin_dir);
+ ok(!plugin_set, "bt_plugin_create_all_from_file() fails with a directory");
ok(!bt_plugin_create_all_from_file(NULL),
"bt_plugin_create_all_from_file() handles NULL correctly");
static void test_minimal(const char *plugin_dir)
{
- struct bt_plugin **plugins;
+ struct bt_plugin_set *plugin_set;
struct bt_plugin *plugin;
char *minimal_path = get_test_plugin_path(plugin_dir, "minimal");
diag("minimal plugin test below");
reset_test_plugin_symbols();
- plugins = bt_plugin_create_all_from_file(minimal_path);
- ok(plugins && plugins[0], "bt_plugin_create_all_from_file() succeeds with a valid file");
+ 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(plugins && plugins[0] && !plugins[1],
+ ok(bt_plugin_set_get_plugin_count(plugin_set) == 1,
"bt_plugin_create_all_from_file() returns the expected number of plugins");
- plugin = plugins[0];
+ plugin = bt_plugin_set_get_plugin(plugin_set, 0);
ok(strcmp(bt_plugin_get_name(plugin), "test_minimal") == 0,
"bt_plugin_get_name() returns the expected name");
ok(strcmp(bt_plugin_get_description(plugin),
"bt_plugin_get_path() returns the expected path");
ok(bt_plugin_get_component_class_count(plugin) == 0,
"bt_plugin_get_component_class_count() returns the expected value");
- BT_PUT(plugin);
+ bt_put(plugin);
+ bt_put(plugin_set);
ok(test_plugin_exit_called, "plugin's exit function is called when the plugin is destroyed");
free(minimal_path);
- free(plugins);
}
static void test_sfs(const char *plugin_dir)
{
- struct bt_plugin **plugins;
+ struct bt_plugin_set *plugin_set;
struct bt_plugin *plugin;
struct bt_component_class *sink_comp_class;
struct bt_component_class *source_comp_class;
char *sfs_path = get_test_plugin_path(plugin_dir, "sfs");
unsigned int major, minor, patch;
const char *extra;
+ struct bt_value *params;
+ struct bt_value *results;
+ struct bt_value *object;
+ struct bt_value *res_params;
+ const char *object_str;
+ int ret;
assert(sfs_path);
diag("sfs plugin test below");
- plugins = bt_plugin_create_all_from_file(sfs_path);
- assert(plugins && plugins[0]);
- plugin = plugins[0];
+ plugin_set = bt_plugin_create_all_from_file(sfs_path);
+ assert(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1);
+ plugin = bt_plugin_set_get_plugin(plugin_set, 0);
ok(bt_plugin_get_version(plugin, &major, &minor, &patch, &extra) ==
BT_PLUGIN_STATUS_OK,
"bt_plugin_get_version() succeeds when there's a version");
sink_comp_class = bt_plugin_get_component_class_by_name_and_type(
plugin, "sink", BT_COMPONENT_CLASS_TYPE_SINK);
-
ok(sink_comp_class,
"bt_plugin_get_component_class_by_name_and_type() finds a sink component class");
+ ok(strcmp(bt_component_class_get_help(sink_comp_class),
+ "Bacon ipsum dolor amet strip steak cupim pastrami venison shoulder.\n"
+ "Prosciutto beef ribs flank meatloaf pancetta brisket kielbasa drumstick\n"
+ "venison tenderloin cow tail. Beef short loin shoulder meatball, sirloin\n"
+ "ground round brisket salami cupim pork bresaola turkey bacon boudin.\n") == 0,
+ "bt_component_class_get_help() returns the expected help text");
+
filter_comp_class = bt_plugin_get_component_class_by_name_and_type(
plugin, "filter", BT_COMPONENT_CLASS_TYPE_FILTER);
-
ok(filter_comp_class,
"bt_plugin_get_component_class_by_name_and_type() finds a filter component class");
ok(!bt_plugin_get_component_class_by_name_and_type(plugin, "filter",
BT_COMPONENT_CLASS_TYPE_SOURCE),
"bt_plugin_get_component_class_by_name_and_type() does not find a component class given the wrong type");
+ params = bt_value_integer_create_init(23);
+ assert(params);
+ ok (!bt_component_class_query(NULL, "get-something", params),
+ "bt_component_class_query() handles NULL (component class)");
+ ok (!bt_component_class_query(filter_comp_class, NULL, params),
+ "bt_component_class_query() handles NULL (object)");
+ ok (!bt_component_class_query(filter_comp_class, "get-something", NULL),
+ "bt_component_class_query() handles NULL (parameters)");
+ results = bt_component_class_query(filter_comp_class,
+ "get-something", params);
+ ok(results, "bt_component_class_query() succeeds");
+ 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);
+ ok(strcmp(object_str, "get-something") == 0,
+ "bt_component_class_query() receives the expected object name");
+ res_params = bt_value_array_get(results, 1);
+ ok(res_params == params,
+ "bt_component_class_query() receives the expected parameters");
diag("> putting the plugin object here");
BT_PUT(plugin);
- sink_component = bt_component_create(sink_comp_class, NULL, bt_value_null);
+ sink_component = bt_component_create(sink_comp_class, NULL, NULL);
ok(sink_component, "bt_component_create() 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, bt_value_null);
+ 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(sink_component);
BT_PUT(filter_comp_class);
- sink_component = bt_component_create(sink_comp_class, NULL, bt_value_null);
+ 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(sink_comp_class);
BT_PUT(sink_component);
free(sfs_path);
- free(plugins);
+ bt_put(plugin_set);
+ bt_put(object);
+ bt_put(res_params);
+ bt_put(results);
+ bt_put(params);
}
static void test_create_all_from_dir(const char *plugin_dir)
{
- struct bt_plugin **plugins;
- struct bt_plugin *plugin;
- int i;
+ struct bt_plugin_set *plugin_set;
diag("create from all test below");
- plugins = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, false);
- ok(!plugins,
+ plugin_set = bt_plugin_create_all_from_dir(NON_EXISTING_PATH, false);
+ ok(!plugin_set,
"bt_plugin_create_all_from_dir() fails with an invalid path");
- plugins = bt_plugin_create_all_from_dir(plugin_dir, false);
- ok(plugins, "bt_plugin_create_all_from_dir() succeeds with a valid path");
-
- i = 0;
- while ((plugin = plugins[i])) {
- BT_PUT(plugin);
- i++;
- }
+ plugin_set = bt_plugin_create_all_from_dir(plugin_dir, 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 */
- ok(i == 2 || i == 4, "bt_plugin_create_all_from_dir() returns the expected number of plugin objects");
+ ok(bt_plugin_set_get_plugin_count(plugin_set) == 2 ||
+ bt_plugin_set_get_plugin_count(plugin_set) == 4,
+ "bt_plugin_create_all_from_dir() returns the expected number of plugin objects");
- free(plugins);
+ bt_put(plugin_set);
}
-static void test_create_from_name(const char *plugin_dir)
+static void test_find(const char *plugin_dir)
{
struct bt_plugin *plugin;
+ struct bt_component_class *comp_cls_sink;
+ struct bt_component_class *comp_cls_source;
char *plugin_path;
- ok(!bt_plugin_create_from_name(NULL),
- "bt_plugin_create_from_name() handles NULL");
- ok(!bt_plugin_create_from_name(NON_EXISTING_PATH),
- "bt_plugin_create_from_name() returns NULL with an unknown plugin name");
+ ok(!bt_plugin_find(NULL),
+ "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:",
NON_EXISTING_PATH, plugin_dir);
setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
- plugin = bt_plugin_create_from_name("test_minimal");
+ plugin = bt_plugin_find("test_minimal");
ok(plugin,
- "bt_plugin_create_from_name() succeeds with a plugin name it can find");
+ "bt_plugin_find() succeeds with a plugin name it can find");
ok(strcmp(bt_plugin_get_author(plugin), "Janine Sutto") == 0,
- "bt_plugin_create_from_name() finds the correct plugin for a given name");
+ "bt_plugin_find() finds the correct plugin for a given name");
BT_PUT(plugin);
+ comp_cls_sink = bt_plugin_find_component_class(NULL, "sink",
+ BT_COMPONENT_CLASS_TYPE_SINK);
+ ok(!comp_cls_sink, "bt_plugin_find_component_class() handles NULL (plugin name)");
+ comp_cls_sink = bt_plugin_find_component_class("test_sfs", NULL,
+ BT_COMPONENT_CLASS_TYPE_SINK);
+ ok(!comp_cls_sink, "bt_plugin_find_component_class() handles NULL (component class name)");
+ comp_cls_sink = bt_plugin_find_component_class("test_sfs", "sink2",
+ BT_COMPONENT_CLASS_TYPE_SINK);
+ ok(!comp_cls_sink, "bt_plugin_find_component_class() fails with an unknown component class name");
+ comp_cls_sink = bt_plugin_find_component_class("test_sfs", "sink",
+ BT_COMPONENT_CLASS_TYPE_SINK);
+ ok(comp_cls_sink, "bt_plugin_find_component_class() succeeds with valid parameters");
+ ok(strcmp(bt_component_class_get_name(comp_cls_sink), "sink") == 0,
+ "bt_plugin_find_component_class() returns the appropriate component class (sink)");
+ comp_cls_source = bt_plugin_find_component_class("test_sfs", "source",
+ BT_COMPONENT_CLASS_TYPE_SOURCE);
+ ok(comp_cls_sink, "bt_plugin_find_component_class() succeeds with another component class name (same plugin)");
+ ok(strcmp(bt_component_class_get_name(comp_cls_source), "source") == 0,
+ "bt_plugin_find_component_class() returns the appropriate component class (source)");
+ BT_PUT(comp_cls_sink);
+ BT_PUT(comp_cls_source);
free(plugin_path);
}
test_minimal(plugin_dir);
test_sfs(plugin_dir);
test_create_all_from_dir(plugin_dir);
- test_create_from_name(plugin_dir);
+ test_find(plugin_dir);
ret = exit_status();
end:
return ret;