Skip to content

Commit 09e8a55

Browse files
author
chaoqin-li1123
committed
fix wasm test
Signed-off-by: chaoqin-li1123 <[email protected]>
1 parent b0e88fe commit 09e8a55

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/wavm/wavm.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,10 @@ void getFunctionWavm(WasmVm *vm, std::string_view function_name,
397397
return;
398398
}
399399
if (!checkFunctionType(f, inferStdFunctionType(function))) {
400+
*function = nullptr;
400401
wavm->fail(FailState::UnableToInitializeCode,
401402
"Bad function signature for: " + std::string(function_name));
403+
return;
402404
}
403405
*function = [wavm, f, function_name](ContextBase *context, Args... args) -> R {
404406
WasmUntaggedValue values[] = {args...};
@@ -427,8 +429,10 @@ void getFunctionWavm(WasmVm *vm, std::string_view function_name,
427429
return;
428430
}
429431
if (!checkFunctionType(f, inferStdFunctionType(function))) {
432+
*function = nullptr;
430433
wavm->fail(FailState::UnableToInitializeCode,
431434
"Bad function signature for: " + std::string(function_name));
435+
return;
432436
}
433437
*function = [wavm, f, function_name](ContextBase *context, Args... args) {
434438
WasmUntaggedValue values[] = {args...};

test/BUILD

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ cc_library(
131131
hdrs = ["utility.h"],
132132
deps = [
133133
"//:lib",
134+
"//:wasmtime_lib",
135+
"//:wavm_lib",
134136
"@com_google_googletest//:gtest",
135137
],
136138
)

test/runtime_test.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ TEST_P(TestVM, BadExportFunction) {
145145
vm_->registerCallback(
146146
"env", "callback", &callback,
147147
&ConvertFunctionWordToUint32<decltype(callback), callback>::convertFunctionWordToUint32);
148+
vm_->registerCallback(
149+
"env", "callback2", &callback2,
150+
&ConvertFunctionWordToUint32<decltype(callback2), callback2>::convertFunctionWordToUint32);
148151
ASSERT_TRUE(vm_->link(""));
149152

150153
WasmCallVoid<0> run;

test/wasm_test.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,11 @@ TEST_P(TestVM, DifferentRootContextsFromDifferentPluginKeys) {
142142
// Read the minimal loadable binary.
143143
std::string source = readTestWasmFile("abi_export.wasm");
144144

145+
const std::string vm_key = "vm_key";
145146
// Create base Wasm via createWasm.
146147
std::shared_ptr<WasmHandleBase> base_wasm_handle =
147-
createWasm("vm_key", source, plugin1, wasm_handle_factory, wasm_handle_clone_factory, false);
148-
EXPECT_TRUE(getThreadLocalWasm(vm_id) == base_wasm_handle);
148+
createWasm(vm_key, source, plugin1, wasm_handle_factory, wasm_handle_clone_factory, false);
149+
base_wasm_handle->wasm()->start(plugin1);
149150
ContextBase *root_context1 = base_wasm_handle->wasm()->getRootContext(plugin1, false);
150151
EXPECT_TRUE(root_context1 != nullptr);
151152

@@ -155,7 +156,7 @@ TEST_P(TestVM, DifferentRootContextsFromDifferentPluginKeys) {
155156
EXPECT_TRUE(base_wasm_handle->wasm()->getRootContext(plugin2, false) == nullptr);
156157

157158
// Create context from a plugin2.
158-
base_wasm_handle->wasm()->createContext(plugin2);
159+
base_wasm_handle->wasm()->start(plugin2);
159160
ContextBase *root_context2 = base_wasm_handle->wasm()->getRootContext(plugin2, false);
160161
EXPECT_TRUE(root_context2 != nullptr);
161162

0 commit comments

Comments
 (0)