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/snapshot/code-serializer.h" | 8 #include "src/snapshot/code-serializer.h" |
9 #include "src/version.h" | 9 #include "src/version.h" |
10 #include "src/wasm/module-decoder.h" | 10 #include "src/wasm/module-decoder.h" |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 | 223 |
224 v8::WasmCompiledModule::CallerOwnedBuffer wire_bytes = { | 224 v8::WasmCompiledModule::CallerOwnedBuffer wire_bytes = { |
225 const_cast<const uint8_t*>(bytes), bytes_size}; | 225 const_cast<const uint8_t*>(bytes), bytes_size}; |
226 | 226 |
227 v8::WasmCompiledModule::CallerOwnedBuffer serialized_bytes = { | 227 v8::WasmCompiledModule::CallerOwnedBuffer serialized_bytes = { |
228 data.first.get(), data.second}; | 228 data.first.get(), data.second}; |
229 v8::Isolate::CreateParams create_params; | 229 v8::Isolate::CreateParams create_params; |
230 create_params.array_buffer_allocator = | 230 create_params.array_buffer_allocator = |
231 CcTest::InitIsolateOnce()->array_buffer_allocator(); | 231 CcTest::InitIsolateOnce()->array_buffer_allocator(); |
232 | 232 |
233 for (int i = 0; i < 3; ++i) { | 233 for (int i = 0; i < 4; ++i) { |
bradnelson
2016/10/17 20:38:04
The numeric counting is getting hard to follow her
Mircea Trofin
2016/10/18 04:34:13
Currently, TEST_F isn't available to cctest. I ref
| |
234 v8::Isolate* v8_isolate = v8::Isolate::New(create_params); | 234 v8::Isolate* v8_isolate = v8::Isolate::New(create_params); |
235 if (i == 1) { | 235 if (i == 1) { |
236 // Invalidate the header by providing a mismatched version | 236 // Invalidate the header by providing a mismatched version |
237 uint32_t* buffer = reinterpret_cast<uint32_t*>( | 237 uint32_t* buffer = reinterpret_cast<uint32_t*>( |
238 const_cast<uint8_t*>(serialized_bytes.first)); | 238 const_cast<uint8_t*>(serialized_bytes.first)); |
239 buffer[SerializedCodeData::kVersionHashOffset] = Version::Hash() + 1; | 239 buffer[SerializedCodeData::kVersionHashOffset] = Version::Hash() + 1; |
240 } | 240 } |
241 | 241 |
242 if (i == 2) { | 242 if (i == 2) { |
243 // Provide no serialized data to force recompilation. | 243 // Provide no serialized data to force recompilation. |
244 serialized_bytes.first = nullptr; | 244 serialized_bytes.first = nullptr; |
245 serialized_bytes.second = 0; | 245 serialized_bytes.second = 0; |
246 } | 246 } |
247 if (i == 3) { | |
248 // Not even the wire bytes are valid. Clear half of them. | |
249 memset(const_cast<uint8_t*>(wire_bytes.first), '\0', | |
250 wire_bytes.second / 2); | |
251 } | |
247 { | 252 { |
248 v8::Isolate::Scope isolate_scope(v8_isolate); | 253 v8::Isolate::Scope isolate_scope(v8_isolate); |
249 v8::HandleScope new_scope(v8_isolate); | 254 v8::HandleScope new_scope(v8_isolate); |
250 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate); | 255 v8::Local<v8::Context> new_ctx = v8::Context::New(v8_isolate); |
251 new_ctx->Enter(); | 256 new_ctx->Enter(); |
252 isolate = reinterpret_cast<Isolate*>(v8_isolate); | 257 isolate = reinterpret_cast<Isolate*>(v8_isolate); |
253 testing::SetupIsolateForWasmModule(isolate); | 258 testing::SetupIsolateForWasmModule(isolate); |
254 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = | 259 v8::MaybeLocal<v8::WasmCompiledModule> deserialized = |
255 v8::WasmCompiledModule::DeserializeOrCompile( | 260 v8::WasmCompiledModule::DeserializeOrCompile( |
256 v8_isolate, serialized_bytes, wire_bytes); | 261 v8_isolate, serialized_bytes, wire_bytes); |
257 v8::Local<v8::WasmCompiledModule> compiled_module; | 262 if (i == 3) { |
258 CHECK(deserialized.ToLocal(&compiled_module)); | 263 CHECK(deserialized.IsEmpty()); |
259 Handle<JSObject> module_object = | 264 } else { |
260 Handle<JSObject>::cast(v8::Utils::OpenHandle(*compiled_module)); | 265 v8::Local<v8::WasmCompiledModule> deserialized_module; |
261 Handle<JSObject> instance = | 266 CHECK(deserialized.ToLocal(&deserialized_module)); |
262 WasmModule::Instantiate(isolate, &thrower, module_object, | 267 Handle<JSObject> module_object = |
263 Handle<JSReceiver>::null(), | 268 Handle<JSObject>::cast(v8::Utils::OpenHandle(*deserialized_module)); |
264 Handle<JSArrayBuffer>::null()) | 269 { |
265 .ToHandleChecked(); | 270 DisallowHeapAllocation assume_no_gc; |
266 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)}; | 271 Handle<WasmCompiledModule> compiled_part( |
267 int32_t result = testing::CallWasmFunctionForTesting( | 272 WasmCompiledModule::cast(module_object->GetInternalField(0)), |
268 isolate, instance, &thrower, kFunctionName, 1, params, | 273 isolate); |
269 ModuleOrigin::kWasmOrigin); | 274 CHECK_EQ(memcmp(compiled_part->module_bytes()->GetCharsAddress(), |
270 CHECK(result == 42); | 275 wire_bytes.first, wire_bytes.second), |
276 0); | |
277 } | |
278 Handle<JSObject> instance = | |
279 WasmModule::Instantiate(isolate, &thrower, module_object, | |
280 Handle<JSReceiver>::null(), | |
281 Handle<JSArrayBuffer>::null()) | |
282 .ToHandleChecked(); | |
283 Handle<Object> params[1] = {Handle<Object>(Smi::FromInt(41), isolate)}; | |
284 int32_t result = testing::CallWasmFunctionForTesting( | |
285 isolate, instance, &thrower, kFunctionName, 1, params, | |
286 ModuleOrigin::kWasmOrigin); | |
287 CHECK(result == 42); | |
288 } | |
271 new_ctx->Exit(); | 289 new_ctx->Exit(); |
272 } | 290 } |
273 v8_isolate->Dispose(); | 291 v8_isolate->Dispose(); |
274 } | 292 } |
275 } | 293 } |
276 | 294 |
277 TEST(MemorySize) { | 295 TEST(MemorySize) { |
278 // Initial memory size is 16, see wasm-module-builder.cc | 296 // Initial memory size is 16, see wasm-module-builder.cc |
279 static const int kExpectedValue = 16; | 297 static const int kExpectedValue = 16; |
280 TestSignatures sigs; | 298 TestSignatures sigs; |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 | 637 |
620 TEST(Run_WasmModule_Global_f32) { | 638 TEST(Run_WasmModule_Global_f32) { |
621 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); | 639 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); |
622 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); | 640 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); |
623 } | 641 } |
624 | 642 |
625 TEST(Run_WasmModule_Global_f64) { | 643 TEST(Run_WasmModule_Global_f64) { |
626 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); | 644 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); |
627 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); | 645 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); |
628 } | 646 } |
OLD | NEW |