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

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

Issue 1601843002: [wasm] Add test for non-misaligned OOB access. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/wasm/wasm-macro-gen.h" 9 #include "src/wasm/wasm-macro-gen.h"
10 10
(...skipping 1527 matching lines...) Expand 10 before | Expand all | Expand 10 after
1538 memory[0] = 11111111; 1538 memory[0] = 11111111;
1539 memory[1] = 22222222; 1539 memory[1] = 22222222;
1540 memory[2] = 33333333; 1540 memory[2] = 33333333;
1541 memory[3] = 44444444; 1541 memory[3] = 44444444;
1542 CHECK_EQ(22222222, r.Call(0)); 1542 CHECK_EQ(22222222, r.Call(0));
1543 CHECK_EQ(33333333, r.Call(4)); 1543 CHECK_EQ(33333333, r.Call(4));
1544 CHECK_EQ(44444444, r.Call(8)); 1544 CHECK_EQ(44444444, r.Call(8));
1545 } 1545 }
1546 1546
1547 1547
1548 // TODO(titzer): Fix for mips and re-enable.
1549 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64 1548 #if !V8_TARGET_ARCH_MIPS && !V8_TARGET_ARCH_MIPS64
1550 1549
1551 TEST(Run_Wasm_LoadMemI32_const_oob) { 1550 TEST(Run_Wasm_LoadMemI32_const_oob_misaligned) {
1551 // TODO(titzer): Fix misaligned accesses on MIPS and re-enable.
1552 TestingModule module; 1552 TestingModule module;
1553 const int kMemSize = 12; 1553 const int kMemSize = 12;
1554 module.AddMemoryElems<byte>(kMemSize); 1554 module.AddMemoryElems<byte>(kMemSize);
1555 1555
1556 for (int offset = 0; offset < kMemSize + 5; offset++) { 1556 for (int offset = 0; offset < kMemSize + 5; offset++) {
1557 for (int index = 0; index < kMemSize + 5; index++) { 1557 for (int index = 0; index < kMemSize + 5; index++) {
1558 WasmRunner<int32_t> r; 1558 WasmRunner<int32_t> r;
1559 r.env()->module = &module; 1559 r.env()->module = &module;
1560 module.RandomizeMemory(); 1560 module.RandomizeMemory();
1561 1561
1562 BUILD(r, 1562 BUILD(r,
1563 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index))); 1563 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
1564 1564
1565 if ((offset + index) <= (kMemSize - sizeof(int32_t))) { 1565 if ((offset + index) <= (kMemSize - sizeof(int32_t))) {
1566 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call()); 1566 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call());
1567 } else { 1567 } else {
1568 CHECK_TRAP(r.Call()); 1568 CHECK_TRAP(r.Call());
1569 } 1569 }
1570 } 1570 }
1571 } 1571 }
1572 } 1572 }
1573 1573
1574 #endif 1574 #endif
1575 1575
1576 1576
1577 TEST(Run_Wasm_LoadMemI32_const_oob) {
1578 TestingModule module;
1579 const int kMemSize = 24;
1580 module.AddMemoryElems<byte>(kMemSize);
1581
1582 for (int offset = 0; offset < kMemSize + 5; offset += 4) {
1583 for (int index = 0; index < kMemSize + 5; index += 4) {
1584 WasmRunner<int32_t> r;
1585 r.env()->module = &module;
1586 module.RandomizeMemory();
1587
1588 BUILD(r,
1589 WASM_LOAD_MEM_OFFSET(MachineType::Int32(), offset, WASM_I8(index)));
1590
1591 if ((offset + index) <= (kMemSize - sizeof(int32_t))) {
1592 CHECK_EQ(module.raw_val_at<int32_t>(offset + index), r.Call());
1593 } else {
1594 CHECK_TRAP(r.Call());
1595 }
1596 }
1597 }
1598 }
1599
1600
1577 TEST(Run_Wasm_StoreMemI32_offset) { 1601 TEST(Run_Wasm_StoreMemI32_offset) {
1578 WasmRunner<int32_t> r(MachineType::Int32()); 1602 WasmRunner<int32_t> r(MachineType::Int32());
1579 const int32_t kWritten = 0xaabbccdd; 1603 const int32_t kWritten = 0xaabbccdd;
1580 TestingModule module; 1604 TestingModule module;
1581 int32_t* memory = module.AddMemoryElems<int32_t>(4); 1605 int32_t* memory = module.AddMemoryElems<int32_t>(4);
1582 r.env()->module = &module; 1606 r.env()->module = &module;
1583 1607
1584 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0), 1608 BUILD(r, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 4, WASM_GET_LOCAL(0),
1585 WASM_I32(kWritten))); 1609 WASM_I32(kWritten)));
1586 1610
(...skipping 1658 matching lines...) Expand 10 before | Expand all | Expand 10 after
3245 TEST(Run_Wasm_F32CopySign) { 3269 TEST(Run_Wasm_F32CopySign) {
3246 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); 3270 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32());
3247 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 3271 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
3248 3272
3249 FOR_FLOAT32_INPUTS(i) { 3273 FOR_FLOAT32_INPUTS(i) {
3250 FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); } 3274 FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); }
3251 } 3275 }
3252 } 3276 }
3253 3277
3254 #endif 3278 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698