Skip to content

Commit

Permalink
Review await test related to core cli plugin, bug still not solved.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Aug 30, 2022
1 parent 4b6ebf5 commit a58210d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 59 deletions.
2 changes: 1 addition & 1 deletion source/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -233,5 +233,5 @@ add_subdirectory(metacall_plugin_extension_test)
add_subdirectory(metacall_plugin_extension_local_test)
add_subdirectory(metacall_plugin_extension_destroy_order_test)
add_subdirectory(metacall_cli_core_plugin_test)
add_subdirectory(metacall_cli_core_plugin_await_test)
add_subdirectory(metacall_backtrace_plugin_test)
add_subdirectory(await_test)
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Check if this loader is enabled
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_LOADERS_PY OR NOT OPTION_BUILD_LOADERS_NODE)
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_EXT OR NOT OPTION_BUILD_LOADERS_NODE OR NOT OPTION_BUILD_PORTS OR NOT OPTION_BUILD_PORTS_NODE)
return()
endif()

Expand All @@ -8,7 +8,7 @@ endif()
#

# Target name
set(target await_test)
set(target metacall-cli-core-plugin-await-test)
message(STATUS "Test ${target}")

#
Expand All @@ -32,7 +32,7 @@ set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")

set(sources
${source_path}/main.cpp
${source_path}/await_test.cpp
${source_path}/metacall_cli_core_plugin_await_test.cpp
)

# Group source files
Expand Down Expand Up @@ -96,6 +96,7 @@ target_compile_definitions(${target}
PRIVATE
${DEFAULT_COMPILE_DEFINITIONS}

# Plugin path
METACALL_PLUGIN_PATH="${CMAKE_CURRENT_SOURCE_DIR}/plugins"
)

Expand Down Expand Up @@ -140,8 +141,9 @@ add_test(NAME ${target}
add_dependencies(${target}
ext_loader
node_loader
py_loader
plugin_extension
node_port
cli_core_plugin
)

#
Expand All @@ -157,4 +159,7 @@ include(TestEnvironmentVariables)
test_environment_variables(${target}
""
${TESTS_ENVIRONMENT_VARIABLES}

# NodeJS Port path
"METACALL_NODE_PORT_PATH=${CMAKE_SOURCE_DIR}/source/ports/node_port/index.js"
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const { metacall, metacall_load_from_file, metacall_inspect } = require('metacall')
const { metacall_load_from_file } = require(process.env['METACALL_NODE_PORT_PATH']);

function await__test(await_cb) {
metacall_load_from_file("node", ["scripts/nod.js"]);
hello_await = 'hello_boy_await(1,2)';
console.log(await_cb);

// TODO: This call generates a deadlock
await_cb(hello_await);

return 22;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@

namespace fs = std::filesystem;

class await_test : public testing::Test
class metacall_cli_core_plugin_await_test : public testing::Test
{
public:
};

TEST_F(await_test, DefaultConstructor)
TEST_F(metacall_cli_core_plugin_await_test, DefaultConstructor)
{
metacall_print_info();

Expand Down Expand Up @@ -60,56 +60,52 @@ TEST_F(await_test, DefaultConstructor)
metacall_value_destroy(args[1]);
metacall_value_destroy(result);

/* NodeJS */
#if defined(OPTION_BUILD_LOADERS_NODE)
{
/* Get core plugin path and handle in order to load cli plugins */
const char *plugin_path = metacall_plugin_path();
void *plugin_extension_handle = metacall_plugin_extension();
void *cli_plugin_handle = NULL;

if (plugin_path != NULL && plugin_extension_handle != NULL)
{
/* Define the cli plugin path as string (core plugin path plus cli) */
fs::path plugin_cli_path(plugin_path);
plugin_cli_path /= "cli";
std::string plugin_cli_path_str(plugin_cli_path.string());

/* Load cli plugins into plugin cli handle */
void *args[] = {
metacall_value_create_string(plugin_cli_path_str.c_str(), plugin_cli_path_str.length()),
metacall_value_create_ptr(&cli_plugin_handle)
};

void *ret = metacallhv_s(plugin_extension_handle, "plugin_load_from_path", args, sizeof(args) / sizeof(args[0]));

if (ret == NULL || (ret != NULL && metacall_value_to_int(ret) != 0))
{
std::cerr << "Failed to load CLI plugins from folder: " << plugin_cli_path_str << std::endl;
}

metacall_value_destroy(args[0]);
metacall_value_destroy(args[1]);
metacall_value_destroy(ret);
}

void *func = metacall_handle_function(cli_plugin_handle, "await");
if (func == NULL)
std::cerr << "function not in handle\n " << METACALL_PLUGIN_PATH << '\n';
void *args[] = {
metacall_value_create_function(func)
};
void *ret = metacallhv_s(handle, "await__test", args, 1);

EXPECT_NE((void *)NULL, (void *)ret);

EXPECT_EQ((enum metacall_value_id)METACALL_DOUBLE, (enum metacall_value_id)metacall_value_id(ret));

EXPECT_EQ((double)22, (long)metacall_value_to_double(ret));

metacall_value_destroy(ret);
}
#endif /* OPTION_BUILD_LOADERS_NODE */
/* Get core plugin path and handle in order to load cli plugins */
const char *plugin_path = metacall_plugin_path();
void *plugin_extension_handle = metacall_plugin_extension();
void *cli_plugin_handle = NULL;

ASSERT_NE((const char *)plugin_path, (const char *)NULL);
ASSERT_NE((void *)plugin_extension_handle, (void *)NULL);

/* Define the cli plugin path as string (core plugin path plus cli) */
fs::path plugin_cli_path(plugin_path);
plugin_cli_path /= "cli";
std::string plugin_cli_path_str(plugin_cli_path.string());

/* Load cli plugins into plugin cli handle */
void *args_cli[] = {
metacall_value_create_string(plugin_cli_path_str.c_str(), plugin_cli_path_str.length()),
metacall_value_create_ptr(&cli_plugin_handle)
};

result = metacallhv_s(plugin_extension_handle, "plugin_load_from_path", args_cli, sizeof(args_cli) / sizeof(args_cli[0]));

ASSERT_NE((void *)result, (void *)NULL);
ASSERT_EQ((int)0, (int)metacall_value_to_int(result));

metacall_value_destroy(args_cli[0]);
metacall_value_destroy(args_cli[1]);
metacall_value_destroy(result);

void *func = metacall_handle_function(cli_plugin_handle, "await");

ASSERT_NE((void *)func, (void *)NULL);

void *args_test[] = {
metacall_value_create_function(func)
};

result = metacallhv_s(handle, "await__test", args_test, 1);

EXPECT_NE((void *)NULL, (void *)result);

EXPECT_EQ((enum metacall_value_id)METACALL_DOUBLE, (enum metacall_value_id)metacall_value_id(result));

EXPECT_EQ((double)22, (long)metacall_value_to_double(result));

metacall_value_destroy(args_test[0]);
metacall_value_destroy(result);

/* Print inspect information */
{
Expand All @@ -125,7 +121,7 @@ TEST_F(await_test, DefaultConstructor)

EXPECT_GT((size_t)size, (size_t)0);

//std::cout << inspect_str << std::endl;
std::cout << inspect_str << std::endl;

metacall_allocator_free(allocator, inspect_str);

Expand Down

0 comments on commit a58210d

Please sign in to comment.