CTF IR -> Trace IR
[babeltrace.git] / tests / lib / test_plugin.c
index 1fb3c6ddbd1c9d1478586712db0c9984eaefa54f..2cba95476ea7cfd06b917dfe3d65a6b96ca1de8c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * test_plugin.c
  *
- * CTF IR Reference Count test
+ * Trace IR Reference Count test
  *
  * Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
  *
 #include <babeltrace/values.h>
 #include <babeltrace/graph/component.h>
 #include <babeltrace/graph/graph.h>
+#include <babeltrace/graph/query-executor.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
 #include <glib.h>
 #include "tap/tap.h"
 #include "common.h"
@@ -56,13 +57,17 @@ static void reset_test_plugin_env_vars(void)
 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;
 }
 
@@ -70,6 +75,8 @@ static void test_invalid(const char *plugin_dir)
 {
        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");
 
@@ -107,7 +114,7 @@ static void test_minimal(const char *plugin_dir)
        struct bt_plugin *plugin;
        char *minimal_path = get_test_plugin_path(plugin_dir, "minimal");
 
-       assert(minimal_path);
+       BT_ASSERT(minimal_path);
        diag("minimal plugin test below");
 
        reset_test_plugin_env_vars();
@@ -160,13 +167,17 @@ static void test_sfs(const char *plugin_dir)
        struct bt_value *res_params;
        struct bt_graph *graph;
        const char *object_str;
+       enum bt_value_status value_ret;
+       enum bt_graph_status graph_ret;
+       struct bt_query_executor *query_exec = bt_query_executor_create();
        int ret;
 
-       assert(sfs_path);
+       BT_ASSERT(query_exec);
+       BT_ASSERT(sfs_path);
        diag("sfs plugin test below");
 
        plugin_set = bt_plugin_create_all_from_file(sfs_path);
-       assert(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1);
+       BT_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,
@@ -206,21 +217,24 @@ static void test_sfs(const char *plugin_dir)
                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);
+       BT_ASSERT(params);
+       ret = bt_query_executor_query(NULL, filter_comp_class, "object",
+               params, &results);
+       ok (ret, "bt_query_executor_query() handles NULL (query executor)");
+       ret = bt_query_executor_query(query_exec, NULL, "object",
+               params, &results);
+       ok (ret, "bt_query_executor_query() handles NULL (component class)");
+       ret = bt_query_executor_query(query_exec, filter_comp_class, NULL,
+               params, &results);
+       ok (ret, "bt_query_executor_query() handles NULL (object)");
+       ret = bt_query_executor_query(query_exec, filter_comp_class,
+               "get-something", params, &results);
+       ok(ret == 0 && results, "bt_query_executor_query() succeeds");
+       BT_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);
+       BT_ASSERT(object && bt_value_is_string(object));
+       value_ret = bt_value_string_get(object, &object_str);
+       BT_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);
@@ -230,28 +244,28 @@ static void test_sfs(const char *plugin_dir)
        diag("> putting the plugin object here");
        BT_PUT(plugin);
        graph = bt_graph_create();
-       assert(graph);
-       ret = bt_graph_add_component(graph, sink_comp_class, "the-sink", NULL,
-               &sink_component);
-       ok(ret == 0 && sink_component,
+       BT_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);
        bt_put(graph);
        graph = bt_graph_create();
-       assert(graph);
-       ret = bt_graph_add_component(graph, sink_comp_class, "the-sink", NULL,
-               &sink_component);
-       ok(ret == 0 && sink_component,
+       BT_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);
        bt_put(graph);
        graph = bt_graph_create();
-       assert(graph);
-       ret = bt_graph_add_component(graph, sink_comp_class, "the-sink", NULL,
-               &sink_component);
-       ok(ret == 0 && sink_component,
+       BT_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);
@@ -263,6 +277,7 @@ static void test_sfs(const char *plugin_dir)
        bt_put(res_params);
        bt_put(results);
        bt_put(params);
+       bt_put(query_exec);
 }
 
 static void test_create_all_from_dir(const char *plugin_dir)
@@ -298,9 +313,14 @@ static void test_find(const char *plugin_dir)
                "bt_plugin_find() handles NULL");
        ok(!bt_plugin_find(NON_EXISTING_PATH),
                "bt_plugin_find() returns NULL with an unknown plugin name");
-       ret = asprintf(&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);
-       assert(ret > 0 && plugin_path);
+       BT_ASSERT(ret > 0 && plugin_path);
        g_setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
        plugin = bt_plugin_find("test_minimal");
        ok(plugin,
This page took 0.027249 seconds and 4 git commands to generate.