Index: test/cctest/wasm/test-run-wasm-module.cc |
diff --git a/test/cctest/wasm/test-run-wasm-module.cc b/test/cctest/wasm/test-run-wasm-module.cc |
index 8449a52ff3bc0f7be4eea87b12795c7842d6a3f0..876e7b7d86966e6318fd9e85f7e7ac9416751e14 100644 |
--- a/test/cctest/wasm/test-run-wasm-module.cc |
+++ b/test/cctest/wasm/test-run-wasm-module.cc |
@@ -2,17 +2,11 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include <stdlib.h> |
-#include <string.h> |
- |
-#include "src/wasm/encoder.h" |
-#include "src/wasm/module-decoder.h" |
-#include "src/wasm/wasm-js.h" |
#include "src/wasm/wasm-macro-gen.h" |
#include "src/wasm/wasm-module.h" |
-#include "src/wasm/wasm-opcodes.h" |
#include "test/cctest/cctest.h" |
+#include "test/cctest/wasm/test-run-wasm-module-helper.h" |
#include "test/cctest/wasm/test-signatures.h" |
using namespace v8::base; |
@@ -20,32 +14,6 @@ using namespace v8::internal; |
using namespace v8::internal::compiler; |
using namespace v8::internal::wasm; |
-namespace { |
-void TestModule(Zone* zone, WasmModuleBuilder* builder, |
- int32_t expected_result) { |
- ZoneBuffer buffer(zone); |
- builder->WriteTo(buffer); |
- |
- Isolate* isolate = CcTest::InitIsolateOnce(); |
- HandleScope scope(isolate); |
- WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context()); |
- int32_t result = |
- testing::CompileAndRunWasmModule(isolate, buffer.begin(), buffer.end()); |
- CHECK_EQ(expected_result, result); |
-} |
- |
-void ExportAs(WasmFunctionBuilder* f, const char* name) { |
- f->SetExported(); |
- f->SetName(name, static_cast<int>(strlen(name))); |
-} |
- |
-void ExportAsMain(WasmFunctionBuilder* f) { |
- static const char kMainName[] = "main"; |
- ExportAs(f, kMainName); |
-} |
- |
-} // namespace |
- |
TEST(Run_WasmModule_Return114) { |
static const int32_t kReturnValue = 114; |
TestSignatures sigs; |
@@ -56,10 +24,10 @@ TEST(Run_WasmModule_Return114) { |
uint16_t f_index = builder->AddFunction(); |
WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
f->SetSignature(sigs.i_v()); |
- ExportAsMain(f); |
+ TestRunWasmModuleHelper::ExportAsMain(f); |
byte code[] = {WASM_I8(kReturnValue)}; |
f->EmitCode(code, sizeof(code)); |
- TestModule(&zone, builder, kReturnValue); |
+ TestRunWasmModuleHelper::TestModule(&zone, builder, kReturnValue); |
} |
TEST(Run_WasmModule_CallAdd) { |
@@ -81,10 +49,10 @@ TEST(Run_WasmModule_CallAdd) { |
f = builder->FunctionAt(f2_index); |
f->SetSignature(sigs.i_v()); |
- ExportAsMain(f); |
+ TestRunWasmModuleHelper::ExportAsMain(f); |
byte code2[] = {WASM_CALL_FUNCTION2(f1_index, WASM_I8(77), WASM_I8(22))}; |
f->EmitCode(code2, sizeof(code2)); |
- TestModule(&zone, builder, 99); |
+ TestRunWasmModuleHelper::TestModule(&zone, builder, 99); |
} |
TEST(Run_WasmModule_ReadLoadedDataSegment) { |
@@ -98,14 +66,14 @@ TEST(Run_WasmModule_ReadLoadedDataSegment) { |
WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
f->SetSignature(sigs.i_v()); |
- ExportAsMain(f); |
+ TestRunWasmModuleHelper::ExportAsMain(f); |
byte code[] = { |
WASM_LOAD_MEM(MachineType::Int32(), WASM_I8(kDataSegmentDest0))}; |
f->EmitCode(code, sizeof(code)); |
byte data[] = {0xaa, 0xbb, 0xcc, 0xdd}; |
builder->AddDataSegment(new (&zone) WasmDataSegmentEncoder( |
&zone, data, sizeof(data), kDataSegmentDest0)); |
- TestModule(&zone, builder, 0xddccbbaa); |
+ TestRunWasmModuleHelper::TestModule(&zone, builder, 0xddccbbaa); |
} |
TEST(Run_WasmModule_CheckMemoryIsZero) { |
@@ -120,7 +88,7 @@ TEST(Run_WasmModule_CheckMemoryIsZero) { |
f->SetSignature(sigs.i_v()); |
uint16_t localIndex = f->AddLocal(kAstI32); |
- ExportAsMain(f); |
+ TestRunWasmModuleHelper::ExportAsMain(f); |
byte code[] = {WASM_BLOCK( |
WASM_WHILE( |
WASM_I32_LTS(WASM_GET_LOCAL(localIndex), WASM_I32V_3(kCheckSize)), |
@@ -129,7 +97,7 @@ TEST(Run_WasmModule_CheckMemoryIsZero) { |
WASM_BRV(2, WASM_I8(-1)), WASM_INC_LOCAL_BY(localIndex, 4))), |
WASM_I8(11))}; |
f->EmitCode(code, sizeof(code)); |
- TestModule(&zone, builder, 11); |
+ TestRunWasmModuleHelper::TestModule(&zone, builder, 11); |
} |
TEST(Run_WasmModule_CallMain_recursive) { |
@@ -143,7 +111,7 @@ TEST(Run_WasmModule_CallMain_recursive) { |
f->SetSignature(sigs.i_v()); |
uint16_t localIndex = f->AddLocal(kAstI32); |
- ExportAsMain(f); |
+ TestRunWasmModuleHelper::ExportAsMain(f); |
byte code[] = {WASM_BLOCK( |
WASM_SET_LOCAL(localIndex, |
WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)), |
@@ -153,7 +121,7 @@ TEST(Run_WasmModule_CallMain_recursive) { |
WASM_BRV(1, WASM_CALL_FUNCTION0(0))), |
WASM_BRV(0, WASM_I8(55))))}; |
f->EmitCode(code, sizeof(code)); |
- TestModule(&zone, builder, 55); |
+ TestRunWasmModuleHelper::TestModule(&zone, builder, 55); |
} |
TEST(Run_WasmModule_Global) { |
@@ -173,12 +141,12 @@ TEST(Run_WasmModule_Global) { |
uint16_t f2_index = builder->AddFunction(); |
f = builder->FunctionAt(f2_index); |
f->SetSignature(sigs.i_v()); |
- ExportAsMain(f); |
+ TestRunWasmModuleHelper::ExportAsMain(f); |
byte code2[] = {WASM_SET_GLOBAL(global1, WASM_I32V_1(56)), |
WASM_SET_GLOBAL(global2, WASM_I32V_1(41)), |
WASM_RETURN1(WASM_CALL_FUNCTION0(f1_index))}; |
f->EmitCode(code2, sizeof(code2)); |
- TestModule(&zone, builder, 97); |
+ TestRunWasmModuleHelper::TestModule(&zone, builder, 97); |
} |
TEST(Run_WasmModule_Serialization) { |
@@ -195,7 +163,7 @@ TEST(Run_WasmModule_Serialization) { |
f->SetSignature(sigs.i_i()); |
byte code[] = {WASM_GET_LOCAL(0), kExprI32Const, 1, kExprI32Add}; |
f->EmitCode(code, sizeof(code)); |
- ExportAs(f, kFunctionName); |
+ TestRunWasmModuleHelper::ExportAs(f, kFunctionName); |
ZoneBuffer buffer(&zone); |
builder->WriteTo(buffer); |