OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <stdlib.h> | 5 #include <stdlib.h> |
6 #include <string.h> | 6 #include <string.h> |
7 | 7 |
8 #include "src/wasm/encoder.h" | 8 #include "src/wasm/encoder.h" |
9 #include "src/wasm/module-decoder.h" | 9 #include "src/wasm/module-decoder.h" |
10 #include "src/wasm/wasm-js.h" | 10 #include "src/wasm/wasm-js.h" |
11 #include "src/wasm/wasm-macro-gen.h" | 11 #include "src/wasm/wasm-macro-gen.h" |
12 #include "src/wasm/wasm-module.h" | 12 #include "src/wasm/wasm-module.h" |
13 #include "src/wasm/wasm-opcodes.h" | 13 #include "src/wasm/wasm-opcodes.h" |
14 | 14 |
15 #include "test/cctest/cctest.h" | 15 #include "test/cctest/cctest.h" |
16 #include "test/cctest/wasm/test-signatures.h" | 16 #include "test/cctest/wasm/test-signatures.h" |
| 17 #include "test/cctest/wasm/wasm-module-runner.h" |
17 | 18 |
18 using namespace v8::base; | 19 using namespace v8::base; |
19 using namespace v8::internal; | 20 using namespace v8::internal; |
20 using namespace v8::internal::compiler; | 21 using namespace v8::internal::compiler; |
21 using namespace v8::internal::wasm; | 22 using namespace v8::internal::wasm; |
22 | 23 |
23 namespace { | 24 namespace { |
24 void TestModule(Zone* zone, WasmModuleBuilder* builder, | 25 void TestModule(Zone* zone, WasmModuleBuilder* builder, |
25 int32_t expected_result) { | 26 int32_t expected_result) { |
26 ZoneBuffer buffer(zone); | 27 ZoneBuffer buffer(zone); |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 Handle<JSObject> module_object = | 250 Handle<JSObject> module_object = |
250 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); | 251 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); |
251 Handle<FixedArray> compiled_part = | 252 Handle<FixedArray> compiled_part = |
252 handle(FixedArray::cast(module_object->GetInternalField(0))); | 253 handle(FixedArray::cast(module_object->GetInternalField(0))); |
253 Handle<JSObject> instance = | 254 Handle<JSObject> instance = |
254 WasmModule::Instantiate(isolate, compiled_part, | 255 WasmModule::Instantiate(isolate, compiled_part, |
255 Handle<JSReceiver>::null(), | 256 Handle<JSReceiver>::null(), |
256 Handle<JSArrayBuffer>::null()) | 257 Handle<JSArrayBuffer>::null()) |
257 .ToHandleChecked(); | 258 .ToHandleChecked(); |
258 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)}; | 259 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)}; |
259 int32_t result = testing::CallFunction(isolate, instance, &thrower, | 260 int32_t result = testing::CallWasmFunctionForTesting( |
260 kFunctionName, 1, params); | 261 isolate, instance, thrower, kFunctionName, 1, params); |
261 CHECK(result == 42); | 262 CHECK(result == 42); |
262 new_ctx->Exit(); | 263 new_ctx->Exit(); |
263 } | 264 } |
264 } | 265 } |
265 | 266 |
266 TEST(Run_WasmModule_MemSize_GrowMem) { | 267 TEST(Run_WasmModule_MemSize_GrowMem) { |
267 static const int kPageSize = 0x10000; | 268 static const int kPageSize = 0x10000; |
268 // Initial memory size = 16 + GrowMemory(10) | 269 // Initial memory size = 16 + GrowMemory(10) |
269 static const int kExpectedValue = kPageSize * 26; | 270 static const int kExpectedValue = kPageSize * 26; |
270 TestSignatures sigs; | 271 TestSignatures sigs; |
(...skipping 17 matching lines...) Expand all Loading... |
288 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 289 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
289 uint16_t f_index = builder->AddFunction(); | 290 uint16_t f_index = builder->AddFunction(); |
290 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 291 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
291 f->SetSignature(sigs.i_v()); | 292 f->SetSignature(sigs.i_v()); |
292 ExportAsMain(f); | 293 ExportAsMain(f); |
293 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), | 294 byte code[] = {WASM_IF_ELSE(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), |
294 WASM_I32V(12))}; | 295 WASM_I32V(12))}; |
295 f->EmitCode(code, sizeof(code)); | 296 f->EmitCode(code, sizeof(code)); |
296 TestModule(&zone, builder, 12); | 297 TestModule(&zone, builder, 12); |
297 } | 298 } |
OLD | NEW |