Skip to content

Commit 0b3aeda

Browse files
committed
Renamed wasm tests, improve event loop closing algorithm from node loader, trying to solve a broken index in git related to java scripts folder (Fibonnaci).
1 parent 5bee813 commit 0b3aeda

File tree

12 files changed

+257
-33
lines changed

12 files changed

+257
-33
lines changed

source/loaders/node_loader/source/node_loader_impl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4707,8 +4707,11 @@ void node_loader_impl_walk_async_handles_count(uv_handle_t *handle, void *arg)
47074707

47084708
if (uv_is_active(handle) && !uv_is_closing(handle))
47094709
{
4710-
// TODO: Improve counter for timers and timeouts, in order to close the event loop properly
4711-
if (!(handle->type == UV_TIMER && !uv_has_ref(handle)))
4710+
// NOTE: I am not sure if this check for timers is correct, at least for versions
4711+
// previous from v11.0.0. Now the node loader seems to be working for versions >=v12.
4712+
// If there is any other error when closing, improve counter for timers and timeouts.
4713+
// Signals have been added because they do not prevent the event loop from closing.
4714+
if (/*(!(handle->type == UV_TIMER && !uv_has_ref(handle))) ||*/ handle->type != UV_SIGNAL)
47124715
{
47134716
(*async_count)++;
47144717
}

source/scripts/java/fibonacci/source/fibonacci.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

source/tests/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ add_subdirectory(metacall_handle_get_test)
122122
add_subdirectory(metacall_test)
123123
add_subdirectory(metacall_node_test)
124124
add_subdirectory(metacall_node_event_loop_test)
125+
add_subdirectory(metacall_node_event_loop_signal_test)
125126
#add_subdirectory(metacall_node_default_export_test) # TODO: This is a feature in order to export by default all functions if there is no module.exports (bootstrap.js)
126127
add_subdirectory(metacall_node_call_test)
127128
add_subdirectory(metacall_node_inline_test)
@@ -200,5 +201,5 @@ add_subdirectory(metacall_ruby_test)
200201
add_subdirectory(metacall_cs_test)
201202
add_subdirectory(metacall_julia_test)
202203
add_subdirectory(metacall_java_test)
203-
add_subdirectory(wasm_loader_test)
204-
add_subdirectory(wasm_python_port_test)
204+
add_subdirectory(metacall_wasm_loader_test)
205+
add_subdirectory(metacall_wasm_python_port_test)
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
# Check if this loader is enabled
2+
if(NOT OPTION_BUILD_LOADERS OR NOT OPTION_BUILD_LOADERS_NODE)
3+
return()
4+
endif()
5+
6+
#
7+
# Executable name and options
8+
#
9+
10+
# Target name
11+
set(target metacall-node-event-loop-signal-test)
12+
message(STATUS "Test ${target}")
13+
14+
#
15+
# Compiler warnings
16+
#
17+
18+
include(Warnings)
19+
20+
#
21+
# Compiler security
22+
#
23+
24+
include(SecurityFlags)
25+
26+
#
27+
# Sources
28+
#
29+
30+
set(include_path "${CMAKE_CURRENT_SOURCE_DIR}/include/${target}")
31+
set(source_path "${CMAKE_CURRENT_SOURCE_DIR}/source")
32+
33+
set(sources
34+
${source_path}/main.cpp
35+
${source_path}/metacall_node_event_loop_signal_test.cpp
36+
)
37+
38+
# Group source files
39+
set(header_group "Header Files (API)")
40+
set(source_group "Source Files")
41+
source_group_by_path(${include_path} "\\\\.h$|\\\\.hpp$"
42+
${header_group} ${headers})
43+
source_group_by_path(${source_path} "\\\\.cpp$|\\\\.c$|\\\\.h$|\\\\.hpp$"
44+
${source_group} ${sources})
45+
46+
#
47+
# Create executable
48+
#
49+
50+
# Build executable
51+
add_executable(${target}
52+
${sources}
53+
)
54+
55+
# Create namespaced alias
56+
add_executable(${META_PROJECT_NAME}::${target} ALIAS ${target})
57+
58+
#
59+
# Project options
60+
#
61+
62+
set_target_properties(${target}
63+
PROPERTIES
64+
${DEFAULT_PROJECT_OPTIONS}
65+
FOLDER "${IDE_FOLDER}"
66+
)
67+
68+
#
69+
# Include directories
70+
#
71+
72+
target_include_directories(${target}
73+
PRIVATE
74+
${DEFAULT_INCLUDE_DIRECTORIES}
75+
${PROJECT_BINARY_DIR}/source/include
76+
)
77+
78+
#
79+
# Libraries
80+
#
81+
82+
target_link_libraries(${target}
83+
PRIVATE
84+
${DEFAULT_LIBRARIES}
85+
86+
GTest
87+
88+
${META_PROJECT_NAME}::metacall
89+
)
90+
91+
#
92+
# Compile definitions
93+
#
94+
95+
target_compile_definitions(${target}
96+
PRIVATE
97+
${DEFAULT_COMPILE_DEFINITIONS}
98+
)
99+
100+
#
101+
# Compile options
102+
#
103+
104+
target_compile_options(${target}
105+
PRIVATE
106+
${DEFAULT_COMPILE_OPTIONS}
107+
)
108+
109+
#
110+
# Linker options
111+
#
112+
113+
target_link_libraries(${target}
114+
PRIVATE
115+
${DEFAULT_LINKER_OPTIONS}
116+
)
117+
118+
#
119+
# Define test
120+
#
121+
122+
add_test(NAME ${target}
123+
COMMAND $<TARGET_FILE:${target}>
124+
)
125+
126+
#
127+
# Define dependencies
128+
#
129+
130+
add_dependencies(${target}
131+
node_loader
132+
)
133+
134+
#
135+
# Define test properties
136+
#
137+
138+
set_property(TEST ${target}
139+
PROPERTY LABELS ${target}
140+
)
141+
142+
include(TestEnvironmentVariables)
143+
144+
test_environment_variables(${target}
145+
""
146+
${TESTS_ENVIRONMENT_VARIABLES}
147+
)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* MetaCall Library by Parra Studios
3+
* A library for providing a foreign function interface calls.
4+
*
5+
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include <gtest/gtest.h>
22+
23+
int main(int argc, char *argv[])
24+
{
25+
::testing::InitGoogleTest(&argc, argv);
26+
27+
return RUN_ALL_TESTS();
28+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* MetaCall Library by Parra Studios
3+
* A library for providing a foreign function interface calls.
4+
*
5+
* Copyright (C) 2016 - 2021 Vicente Eduardo Ferrer Garcia <[email protected]>
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*
19+
*/
20+
21+
#include <gtest/gtest.h>
22+
23+
#include <metacall/metacall.h>
24+
#include <metacall/metacall_loaders.h>
25+
#include <metacall/metacall_value.h>
26+
27+
class metacall_node_event_loop_signal_test : public testing::Test
28+
{
29+
public:
30+
};
31+
32+
TEST_F(metacall_node_event_loop_signal_test, DefaultConstructor)
33+
{
34+
metacall_print_info();
35+
36+
metacall_log_null();
37+
38+
ASSERT_EQ((int)0, (int)metacall_initialize());
39+
40+
/* NodeJS */
41+
#if defined(OPTION_BUILD_LOADERS_NODE)
42+
{
43+
// This test verifies that signals do not prevent event loop from exiting
44+
const char buffer[] =
45+
"process.on('SIGINT', () => { console.log('SIGINT') });\n";
46+
47+
void *handle = NULL;
48+
49+
EXPECT_EQ((int)0, (int)metacall_load_from_memory("node", buffer, sizeof(buffer), &handle));
50+
51+
EXPECT_NE((void *)NULL, (void *)handle);
52+
53+
EXPECT_EQ((int)0, (int)metacall_clear(handle));
54+
}
55+
#endif /* OPTION_BUILD_LOADERS_NODE */
56+
57+
EXPECT_EQ((int)0, (int)metacall_destroy());
58+
}

source/tests/wasm_loader_test/CMakeLists.txt renamed to source/tests/metacall_wasm_loader_test/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ endif()
88
#
99

1010
# Target name
11-
set(target wasm-loader-test)
11+
set(target metacall-wasm-loader-test)
1212
message(STATUS "Test ${target}")
1313

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

3333
set(sources
3434
${source_path}/main.cpp
35-
${source_path}/wasm_loader_test.cpp
35+
${source_path}/metacall_wasm_loader_test.cpp
3636
)
3737

3838
# Group source files

source/tests/wasm_loader_test/source/wasm_loader_test.cpp renamed to source/tests/metacall_wasm_loader_test/source/metacall_wasm_loader_test.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <metacall/metacall.h>
2323
#include <metacall/metacall_value.h>
2424

25-
class wasm_loader_test : public testing::Test
25+
class metacall_wasm_loader_test : public testing::Test
2626
{
2727
protected:
2828
void SetUp() override
@@ -56,7 +56,7 @@ void TestFunction(void *handle, const char *name, const std::vector<enum metacal
5656
ASSERT_EQ(expected_return_type, return_type);
5757
}
5858

59-
TEST_F(wasm_loader_test, InitializeAndDestroy)
59+
TEST_F(metacall_wasm_loader_test, InitializeAndDestroy)
6060
{
6161
// This is extremely hacky and causes an error when loading the buffer,
6262
// since it is invalid. However, it is currently impossible to initialize a
@@ -72,7 +72,7 @@ TEST_F(wasm_loader_test, InitializeAndDestroy)
7272
ASSERT_EQ(0, metacall_destroy());
7373
}
7474

75-
TEST_F(wasm_loader_test, LoadBinaryFromMemory)
75+
TEST_F(metacall_wasm_loader_test, LoadBinaryFromMemory)
7676
{
7777
// See https://webassembly.github.io/spec/core/binary/modules.html#binary-module
7878
const char empty_module[] = {
@@ -85,7 +85,7 @@ TEST_F(wasm_loader_test, LoadBinaryFromMemory)
8585
ASSERT_NE(0, metacall_load_from_memory("wasm", invalid_module, sizeof(invalid_module), NULL));
8686
}
8787

88-
TEST_F(wasm_loader_test, LoadTextFromMemory)
88+
TEST_F(metacall_wasm_loader_test, LoadTextFromMemory)
8989
{
9090
const char *empty_module = "(module)";
9191
ASSERT_EQ(0, metacall_load_from_memory("wasm", empty_module, strlen(empty_module), NULL));
@@ -95,7 +95,7 @@ TEST_F(wasm_loader_test, LoadTextFromMemory)
9595
}
9696

9797
#if defined(BUILD_SCRIPT_TESTS)
98-
TEST_F(wasm_loader_test, LoadFromFile)
98+
TEST_F(metacall_wasm_loader_test, LoadFromFile)
9999
{
100100
const char *empty_module_filename = "empty_module.wat";
101101
const char *invalid_module_filename = "invalid_module.wat";
@@ -104,13 +104,13 @@ TEST_F(wasm_loader_test, LoadFromFile)
104104
ASSERT_NE(0, metacall_load_from_file("wasm", &invalid_module_filename, 1, NULL));
105105
}
106106

107-
TEST_F(wasm_loader_test, LoadFromPackage)
107+
TEST_F(metacall_wasm_loader_test, LoadFromPackage)
108108
{
109109
ASSERT_EQ(0, metacall_load_from_package("wasm", "empty_module.wasm", NULL));
110110
ASSERT_NE(0, metacall_load_from_package("wasm", "invalid_module.wasm", NULL));
111111
}
112112

113-
TEST_F(wasm_loader_test, DiscoverFunctions)
113+
TEST_F(metacall_wasm_loader_test, DiscoverFunctions)
114114
{
115115
const char *functions_module_filename = "functions.wat";
116116
void *handle;
@@ -128,7 +128,7 @@ TEST_F(wasm_loader_test, DiscoverFunctions)
128128
TestFunction(handle, "i32_f32_i64_f64_ret_i32_f32_i64_f64", { METACALL_INT, METACALL_FLOAT, METACALL_LONG, METACALL_DOUBLE }, METACALL_ARRAY);
129129
}
130130

131-
TEST_F(wasm_loader_test, CallFunctions)
131+
TEST_F(metacall_wasm_loader_test, CallFunctions)
132132
{
133133
const char *functions_module_filename = "functions.wat";
134134

@@ -181,7 +181,7 @@ TEST_F(wasm_loader_test, CallFunctions)
181181
ASSERT_EQ(NULL, ret);
182182
}
183183

184-
TEST_F(wasm_loader_test, LinkModules)
184+
TEST_F(metacall_wasm_loader_test, LinkModules)
185185
{
186186
const char *modules[] = {
187187
"exports1.wat",
@@ -202,7 +202,7 @@ TEST_F(wasm_loader_test, LinkModules)
202202
metacall_value_destroy(ret);
203203
}
204204

205-
TEST_F(wasm_loader_test, InvalidLinkModules)
205+
TEST_F(metacall_wasm_loader_test, InvalidLinkModules)
206206
{
207207
const char *modules[] = {
208208
"exports1.wat",

0 commit comments

Comments
 (0)