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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 class InterruptThread : public v8::base::Thread { | 412 class InterruptThread : public v8::base::Thread { |
413 public: | 413 public: |
414 explicit InterruptThread(Isolate* isolate, int32_t* memory) | 414 explicit InterruptThread(Isolate* isolate, int32_t* memory) |
415 : Thread(Options("TestInterruptLoop")), | 415 : Thread(Options("TestInterruptLoop")), |
416 isolate_(isolate), | 416 isolate_(isolate), |
417 memory_(memory) {} | 417 memory_(memory) {} |
418 | 418 |
419 static void OnInterrupt(v8::Isolate* isolate, void* data) { | 419 static void OnInterrupt(v8::Isolate* isolate, void* data) { |
420 int32_t* m = reinterpret_cast<int32_t*>(data); | 420 int32_t* m = reinterpret_cast<int32_t*>(data); |
421 // Set the interrupt location to 0 to break the loop in {TestInterruptLoop}. | 421 // Set the interrupt location to 0 to break the loop in {TestInterruptLoop}. |
422 m[interrupt_location_] = interrupt_value_; | 422 int32_t* ptr = &m[interrupt_location_]; |
| 423 WriteLittleEndianValue<int32_t>(ptr, interrupt_value_); |
423 } | 424 } |
424 | 425 |
425 virtual void Run() { | 426 virtual void Run() { |
426 // Wait for the main thread to write the signal value. | 427 // Wait for the main thread to write the signal value. |
427 while (memory_[0] != signal_value_) { | 428 int32_t val = 0; |
428 } | 429 do { |
| 430 val = memory_[0]; |
| 431 val = ReadLittleEndianValue<int32_t>(&val); |
| 432 } while (val != signal_value_); |
429 isolate_->RequestInterrupt(&OnInterrupt, const_cast<int32_t*>(memory_)); | 433 isolate_->RequestInterrupt(&OnInterrupt, const_cast<int32_t*>(memory_)); |
430 } | 434 } |
431 | 435 |
432 Isolate* isolate_; | 436 Isolate* isolate_; |
433 volatile int32_t* memory_; | 437 volatile int32_t* memory_; |
434 static const int32_t interrupt_location_ = 10; | 438 static const int32_t interrupt_location_ = 10; |
435 static const int32_t interrupt_value_ = 154; | 439 static const int32_t interrupt_value_ = 154; |
436 static const int32_t signal_value_ = 1221; | 440 static const int32_t signal_value_ = 1221; |
437 }; | 441 }; |
438 | 442 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 | 486 |
483 MaybeHandle<JSArrayBuffer> maybe_memory = | 487 MaybeHandle<JSArrayBuffer> maybe_memory = |
484 GetInstanceMemory(isolate, instance); | 488 GetInstanceMemory(isolate, instance); |
485 Handle<JSArrayBuffer> memory = maybe_memory.ToHandleChecked(); | 489 Handle<JSArrayBuffer> memory = maybe_memory.ToHandleChecked(); |
486 int32_t* memory_array = reinterpret_cast<int32_t*>(memory->backing_store()); | 490 int32_t* memory_array = reinterpret_cast<int32_t*>(memory->backing_store()); |
487 | 491 |
488 InterruptThread thread(isolate, memory_array); | 492 InterruptThread thread(isolate, memory_array); |
489 thread.Start(); | 493 thread.Start(); |
490 testing::RunWasmModuleForTesting(isolate, instance, 0, nullptr, | 494 testing::RunWasmModuleForTesting(isolate, instance, 0, nullptr, |
491 ModuleOrigin::kWasmOrigin); | 495 ModuleOrigin::kWasmOrigin); |
| 496 int32_t val = memory_array[InterruptThread::interrupt_location_]; |
492 CHECK_EQ(InterruptThread::interrupt_value_, | 497 CHECK_EQ(InterruptThread::interrupt_value_, |
493 memory_array[InterruptThread::interrupt_location_]); | 498 ReadLittleEndianValue<int32_t>(&val)); |
494 } | 499 } |
495 | 500 |
496 TEST(Run_WasmModule_GrowMemoryInIf) { | 501 TEST(Run_WasmModule_GrowMemoryInIf) { |
497 TestSignatures sigs; | 502 TestSignatures sigs; |
498 v8::internal::AccountingAllocator allocator; | 503 v8::internal::AccountingAllocator allocator; |
499 Zone zone(&allocator, ZONE_NAME); | 504 Zone zone(&allocator, ZONE_NAME); |
500 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 505 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
501 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); | 506 WasmFunctionBuilder* f = builder->AddFunction(sigs.i_v()); |
502 ExportAsMain(f); | 507 ExportAsMain(f); |
503 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), | 508 byte code[] = {WASM_IF_ELSE_I(WASM_I32V(0), WASM_GROW_MEMORY(WASM_I32V(1)), |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 | 717 |
713 TEST(Run_WasmModule_Global_f32) { | 718 TEST(Run_WasmModule_Global_f32) { |
714 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); | 719 RunWasmModuleGlobalInitTest<float>(kAstF32, -983.9f); |
715 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); | 720 RunWasmModuleGlobalInitTest<float>(kAstF32, 1122.99f); |
716 } | 721 } |
717 | 722 |
718 TEST(Run_WasmModule_Global_f64) { | 723 TEST(Run_WasmModule_Global_f64) { |
719 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); | 724 RunWasmModuleGlobalInitTest<double>(kAstF64, -833.9); |
720 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); | 725 RunWasmModuleGlobalInitTest<double>(kAstF64, 86374.25); |
721 } | 726 } |
OLD | NEW |