Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 2371833007: [wasm] Initial signal handler (Closed)
Patch Set: Addressing some of Jochen's feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stdint.h> 5 #include <stdint.h>
6 #include <stdlib.h> 6 #include <stdlib.h>
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "src/base/platform/elapsed-timer.h" 9 #include "src/base/platform/elapsed-timer.h"
10 #include "src/trap-handler/trap-handler.h"
10 #include "src/utils.h" 11 #include "src/utils.h"
11 #include "src/wasm/wasm-macro-gen.h" 12 #include "src/wasm/wasm-macro-gen.h"
12 13
13 #include "test/cctest/cctest.h" 14 #include "test/cctest/cctest.h"
14 #include "test/cctest/compiler/value-helper.h" 15 #include "test/cctest/compiler/value-helper.h"
15 #include "test/cctest/wasm/wasm-run-utils.h" 16 #include "test/cctest/wasm/wasm-run-utils.h"
16 #include "test/common/wasm/test-signatures.h" 17 #include "test/common/wasm/test-signatures.h"
17 18
18 using namespace v8::base; 19 using namespace v8::base;
19 using namespace v8::internal; 20 using namespace v8::internal;
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 WASM_I8(107)); 1077 WASM_I8(107));
1077 1078
1078 FOR_INT32_INPUTS(i) { 1079 FOR_INT32_INPUTS(i) {
1079 int32_t expected = *i; 1080 int32_t expected = *i;
1080 CHECK_EQ(107, r.Call(expected)); 1081 CHECK_EQ(107, r.Call(expected));
1081 CHECK_EQ(expected, r.module().ReadMemory(&memory[0])); 1082 CHECK_EQ(expected, r.module().ReadMemory(&memory[0]));
1082 } 1083 }
1083 } 1084 }
1084 1085
1085 WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) { 1086 WASM_EXEC_TEST_WITH_TRAP(LoadMaxUint32Offset) {
1087 if (trap_handler::EnableTrapHandler()) {
titzer 2017/01/09 09:26:56 I think this is because we'd need to put the trap
Eric Holk 2017/01/10 23:10:48 Done.
1088 // cctests don't register the handler data, so this test won't work
1089 // TODO(eholk): find out why and fix it.
1090 return;
1091 }
1086 WasmRunner<int32_t> r(execution_mode); 1092 WasmRunner<int32_t> r(execution_mode);
1087 r.module().AddMemoryElems<int32_t>(8); 1093 r.module().AddMemoryElems<int32_t>(8);
1088 1094
1089 BUILD(r, kExprI8Const, 0, // index 1095 BUILD(r, kExprI8Const, 0, // index
1090 static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf( 1096 static_cast<byte>(v8::internal::wasm::WasmOpcodes::LoadStoreOpcodeOf(
1091 MachineType::Int32(), false)), // -- 1097 MachineType::Int32(), false)), // --
1092 0, // alignment 1098 0, // alignment
1093 U32V_5(0xffffffff)); // offset 1099 U32V_5(0xffffffff)); // offset
1094 1100
1095 CHECK_TRAP32(r.Call()); 1101 CHECK_TRAP32(r.Call());
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 1473
1468 r.module().WriteMemory(&memory[0], 0x5e6f7a8b); 1474 r.module().WriteMemory(&memory[0], 0x5e6f7a8b);
1469 CHECK_EQ(0x5e6f7a8b, r.Call(0)); 1475 CHECK_EQ(0x5e6f7a8b, r.Call(0));
1470 1476
1471 r.module().WriteMemory(&memory[0], 0x7ca0b1c2); 1477 r.module().WriteMemory(&memory[0], 0x7ca0b1c2);
1472 CHECK_EQ(0x7ca0b1c2, r.Call(0)); 1478 CHECK_EQ(0x7ca0b1c2, r.Call(0));
1473 } 1479 }
1474 } 1480 }
1475 1481
1476 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) { 1482 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_oob) {
1483 if (trap_handler::EnableTrapHandler()) {
1484 // With trap handlers enabled, we need additional guard pages and such set
1485 // up. This path does not enable these, so we skip this test. The behavior
1486 // covered by this tests is also covered by mjsunit tests, such as
1487 // test/mjsunit/wasm/import-memory.js
1488 return;
1489 }
1477 WasmRunner<int32_t, uint32_t> r(execution_mode); 1490 WasmRunner<int32_t, uint32_t> r(execution_mode);
1478 int32_t* memory = r.module().AddMemoryElems<int32_t>(8); 1491 int32_t* memory = r.module().AddMemoryElems<int32_t>(8);
1479 r.module().RandomizeMemory(1111); 1492 r.module().RandomizeMemory(1111);
1480 1493
1481 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0))); 1494 BUILD(r, WASM_LOAD_MEM(MachineType::Int32(), WASM_GET_LOCAL(0)));
1482 1495
1483 r.module().WriteMemory(&memory[0], 88888888); 1496 r.module().WriteMemory(&memory[0], 88888888);
1484 CHECK_EQ(88888888, r.Call(0u)); 1497 CHECK_EQ(88888888, r.Call(0u));
1485 for (uint32_t offset = 29; offset < 40; ++offset) { 1498 for (uint32_t offset = 29; offset < 40; ++offset) {
1486 CHECK_TRAP(r.Call(offset)); 1499 CHECK_TRAP(r.Call(offset));
1487 } 1500 }
1488 1501
1489 for (uint32_t offset = 0x80000000; offset < 0x80000010; ++offset) { 1502 for (uint32_t offset = 0x80000000; offset < 0x80000010; ++offset) {
1490 CHECK_TRAP(r.Call(offset)); 1503 CHECK_TRAP(r.Call(offset));
1491 } 1504 }
1492 } 1505 }
1493 1506
1494 WASM_EXEC_TEST_WITH_TRAP(LoadMem_offset_oob) { 1507 WASM_EXEC_TEST_WITH_TRAP(LoadMem_offset_oob) {
1508 if (trap_handler::EnableTrapHandler()) {
1509 // With trap handlers enabled, we need additional guard pages and such set
1510 // up. This path does not enable these, so we skip this test. The behavior
1511 // covered by this tests is also covered by mjsunit tests, such as
1512 // test/mjsunit/wasm/import-memory.js
1513 return;
1514 }
1495 static const MachineType machineTypes[] = { 1515 static const MachineType machineTypes[] = {
1496 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), 1516 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
1497 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), 1517 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
1498 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), 1518 MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(),
1499 MachineType::Float64()}; 1519 MachineType::Float64()};
1500 1520
1501 for (size_t m = 0; m < arraysize(machineTypes); ++m) { 1521 for (size_t m = 0; m < arraysize(machineTypes); ++m) {
1502 WasmRunner<int32_t, uint32_t> r(execution_mode); 1522 WasmRunner<int32_t, uint32_t> r(execution_mode);
1503 r.module().AddMemoryElems<int32_t>(8); 1523 r.module().AddMemoryElems<int32_t>(8);
1504 r.module().RandomizeMemory(1116 + static_cast<int>(m)); 1524 r.module().RandomizeMemory(1116 + static_cast<int>(m));
(...skipping 29 matching lines...) Expand all
1534 r.module().WriteMemory(&memory[0], 11111111); 1554 r.module().WriteMemory(&memory[0], 11111111);
1535 r.module().WriteMemory(&memory[1], 22222222); 1555 r.module().WriteMemory(&memory[1], 22222222);
1536 r.module().WriteMemory(&memory[2], 33333333); 1556 r.module().WriteMemory(&memory[2], 33333333);
1537 r.module().WriteMemory(&memory[3], 44444444); 1557 r.module().WriteMemory(&memory[3], 44444444);
1538 CHECK_EQ(22222222, r.Call(0)); 1558 CHECK_EQ(22222222, r.Call(0));
1539 CHECK_EQ(33333333, r.Call(4)); 1559 CHECK_EQ(33333333, r.Call(4));
1540 CHECK_EQ(44444444, r.Call(8)); 1560 CHECK_EQ(44444444, r.Call(8));
1541 } 1561 }
1542 1562
1543 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) { 1563 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob_misaligned) {
1564 if (trap_handler::EnableTrapHandler()) {
1565 // With trap handlers enabled, we need additional guard pages and such set
1566 // up. This path does not enable these, so we skip this test. The behavior
1567 // covered by this tests is also covered by mjsunit tests, such as
1568 // test/mjsunit/wasm/import-memory.js
1569 return;
1570 }
1544 const int kMemSize = 12; 1571 const int kMemSize = 12;
1545 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable. 1572 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
1546 for (int offset = 0; offset < kMemSize + 5; ++offset) { 1573 for (int offset = 0; offset < kMemSize + 5; ++offset) {
1547 for (int index = 0; index < kMemSize + 5; ++index) { 1574 for (int index = 0; index < kMemSize + 5; ++index) {
1548 WasmRunner<int32_t> r(execution_mode); 1575 WasmRunner<int32_t> r(execution_mode);
1549 r.module().AddMemoryElems<byte>(kMemSize); 1576 r.module().AddMemoryElems<byte>(kMemSize);
1550 r.module().RandomizeMemory(); 1577 r.module().RandomizeMemory();
1551 1578
1552 BUILD(r, 1579 BUILD(r,
1553 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); 1580 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
1554 1581
1555 if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) { 1582 if ((offset + index) <= static_cast<int>((kMemSize - sizeof(int32_t)))) {
1556 CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call()); 1583 CHECK_EQ(r.module().raw_val_at<int32_t>(offset + index), r.Call());
1557 } else { 1584 } else {
1558 CHECK_TRAP(r.Call()); 1585 CHECK_TRAP(r.Call());
1559 } 1586 }
1560 } 1587 }
1561 } 1588 }
1562 } 1589 }
1563 1590
1564 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) { 1591 WASM_EXEC_TEST_WITH_TRAP(LoadMemI32_const_oob) {
1592 if (trap_handler::EnableTrapHandler()) {
1593 // With trap handlers enabled, we need additional guard pages and such set
1594 // up. This path does not enable these, so we skip this test. The behavior
1595 // covered by this tests is also covered by mjsunit tests, such as
1596 // test/mjsunit/wasm/import-memory.js
1597 return;
1598 }
1565 const int kMemSize = 24; 1599 const int kMemSize = 24;
1566 for (int offset = 0; offset < kMemSize + 5; offset += 4) { 1600 for (int offset = 0; offset < kMemSize + 5; offset += 4) {
1567 for (int index = 0; index < kMemSize + 5; index += 4) { 1601 for (int index = 0; index < kMemSize + 5; index += 4) {
1568 WasmRunner<int32_t> r(execution_mode); 1602 WasmRunner<int32_t> r(execution_mode);
1569 r.module().AddMemoryElems<byte>(kMemSize); 1603 r.module().AddMemoryElems<byte>(kMemSize);
1570 r.module().RandomizeMemory(); 1604 r.module().RandomizeMemory();
1571 1605
1572 BUILD(r, 1606 BUILD(r,
1573 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); 1607 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
1574 1608
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 r.module().WriteMemory(&memory[3], 99999999); 1649 r.module().WriteMemory(&memory[3], 99999999);
1616 CHECK_EQ(kWritten, r.Call(i * 4)); 1650 CHECK_EQ(kWritten, r.Call(i * 4));
1617 CHECK_EQ(66666666, r.module().ReadMemory(&memory[0])); 1651 CHECK_EQ(66666666, r.module().ReadMemory(&memory[0]));
1618 CHECK_EQ(i == 0 ? kWritten : 77777777, r.module().ReadMemory(&memory[1])); 1652 CHECK_EQ(i == 0 ? kWritten : 77777777, r.module().ReadMemory(&memory[1]));
1619 CHECK_EQ(i == 1 ? kWritten : 88888888, r.module().ReadMemory(&memory[2])); 1653 CHECK_EQ(i == 1 ? kWritten : 88888888, r.module().ReadMemory(&memory[2]));
1620 CHECK_EQ(i == 2 ? kWritten : 99999999, r.module().ReadMemory(&memory[3])); 1654 CHECK_EQ(i == 2 ? kWritten : 99999999, r.module().ReadMemory(&memory[3]));
1621 } 1655 }
1622 } 1656 }
1623 1657
1624 WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob) { 1658 WASM_EXEC_TEST_WITH_TRAP(StoreMem_offset_oob) {
1659 if (trap_handler::EnableTrapHandler()) {
1660 // With trap handlers enabled, we need additional guard pages and such set
1661 // up. This path does not enable these, so we skip this test. The behavior
1662 // covered by this tests is also covered by mjsunit tests, such as
1663 // test/mjsunit/wasm/import-memory.js
1664 return;
1665 }
1625 // 64-bit cases are handled in test-run-wasm-64.cc 1666 // 64-bit cases are handled in test-run-wasm-64.cc
1626 static const MachineType machineTypes[] = { 1667 static const MachineType machineTypes[] = {
1627 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), 1668 MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(),
1628 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), 1669 MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(),
1629 MachineType::Float32(), MachineType::Float64()}; 1670 MachineType::Float32(), MachineType::Float64()};
1630 1671
1631 for (size_t m = 0; m < arraysize(machineTypes); ++m) { 1672 for (size_t m = 0; m < arraysize(machineTypes); ++m) {
1632 WasmRunner<int32_t, uint32_t> r(execution_mode); 1673 WasmRunner<int32_t, uint32_t> r(execution_mode);
1633 byte* memory = r.module().AddMemoryElems<byte>(32); 1674 byte* memory = r.module().AddMemoryElems<byte>(32);
1634 1675
(...skipping 1252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2887 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP, 2928 BUILD(r, WASM_I32_REMS(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)), WASM_DROP,
2888 WASM_ZERO); 2929 WASM_ZERO);
2889 const int32_t kMin = std::numeric_limits<int32_t>::min(); 2930 const int32_t kMin = std::numeric_limits<int32_t>::min();
2890 CHECK_EQ(0, r.Call(133, 100)); 2931 CHECK_EQ(0, r.Call(133, 100));
2891 CHECK_EQ(0, r.Call(kMin, -1)); 2932 CHECK_EQ(0, r.Call(kMin, -1));
2892 CHECK_EQ(0, r.Call(0, 1)); 2933 CHECK_EQ(0, r.Call(0, 1));
2893 CHECK_TRAP(r.Call(100, 0)); 2934 CHECK_TRAP(r.Call(100, 0));
2894 CHECK_TRAP(r.Call(-1001, 0)); 2935 CHECK_TRAP(r.Call(-1001, 0));
2895 CHECK_TRAP(r.Call(kMin, 0)); 2936 CHECK_TRAP(r.Call(kMin, 0));
2896 } 2937 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698