2 * SPDX-License-Identifier: GPL-2.0-only
4 * Copyright (C) 2024 EfficiOS, Inc.
7 #include <cpp-common/bt2/plugin.hpp>
9 #include <cpp-common/vendor/fmt/format.h>
11 #include <babeltrace2/babeltrace.h>
13 #include "cpp-common/bt2c/c-string-view.hpp"
19 void testFailOnLoadErrorTrue(const char * const pluginDir
)
24 bt2::findAllPluginsFromDir(pluginDir
, false, true);
26 } catch (const bt2::Error
& exc
) {
27 fmt::print("{}\n", exc
.what());
29 const auto error
= bt_current_thread_take_error();
32 * The last error cause must be the one which the initialization
33 * function of our plugin appended.
35 const auto cause
= bt_error_borrow_cause_by_index(error
, 0);
36 const bt2c::CStringView msg
{bt_error_cause_get_message(cause
)};
38 ok(msg
== "This is the error message", "Message of error cause 0 is expected");
39 bt_error_release(error
);
43 void testFailOnLoadErrorFalse(const char * const pluginDir
)
47 const auto plugins
= bt2::findAllPluginsFromDir(pluginDir
, false, false);
49 ok(!plugins
, "No plugin set returned");
54 int main(const int argc
, const char ** const argv
)
58 "Usage: {} INIT-FAIL-PLUGIN-DIR FAIL-ON-LOAD-ERROR\n"
60 "FAIL-ON-LOAD-ERROR must be `yes` or `no`\n",
65 const auto pluginDir
= argv
[1];
66 const bt2c::CStringView failOnLoadErrorStr
{argv
[2]};
68 if (failOnLoadErrorStr
== "yes") {
69 testFailOnLoadErrorTrue(pluginDir
);
70 } else if (failOnLoadErrorStr
== "no") {
71 testFailOnLoadErrorFalse(pluginDir
);
74 "ERROR: Invalid value `{}` for FAIL-ON-LOAD-ERROR (expecting `yes` or `no`).\n",