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

Side by Side Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 2540133002: [wasm] Remove raw byte pointers from WasmModule (Closed)
Patch Set: Address comments Created 4 years 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 | « test/fuzzer/wasm-code.cc ('k') | 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 "test/unittests/test-utils.h" 5 #include "test/unittests/test-utils.h"
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/common/wasm/test-signatures.h" 9 #include "test/common/wasm/test-signatures.h"
10 10
(...skipping 1261 matching lines...) Expand 10 before | Expand all | Expand 10 after
1272 } 1272 }
1273 } 1273 }
1274 } 1274 }
1275 } 1275 }
1276 1276
1277 namespace { 1277 namespace {
1278 // A helper for tests that require a module environment for functions and 1278 // A helper for tests that require a module environment for functions and
1279 // globals. 1279 // globals.
1280 class TestModuleEnv : public ModuleEnv { 1280 class TestModuleEnv : public ModuleEnv {
1281 public: 1281 public:
1282 TestModuleEnv() { 1282 explicit TestModuleEnv(ModuleOrigin origin = kWasmOrigin)
1283 instance = nullptr; 1283 : ModuleEnv(&mod, nullptr) {
1284 module = &mod; 1284 mod.origin = origin;
1285 } 1285 }
1286 byte AddGlobal(LocalType type, bool mutability = true) { 1286 byte AddGlobal(LocalType type, bool mutability = true) {
1287 mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false}); 1287 mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false});
1288 CHECK(mod.globals.size() <= 127); 1288 CHECK(mod.globals.size() <= 127);
1289 return static_cast<byte>(mod.globals.size() - 1); 1289 return static_cast<byte>(mod.globals.size() - 1);
1290 } 1290 }
1291 byte AddSignature(FunctionSig* sig) { 1291 byte AddSignature(FunctionSig* sig) {
1292 mod.signatures.push_back(sig); 1292 mod.signatures.push_back(sig);
1293 CHECK(mod.signatures.size() <= 127); 1293 CHECK(mod.signatures.size() <= 127);
1294 return static_cast<byte>(mod.signatures.size() - 1); 1294 return static_cast<byte>(mod.signatures.size() - 1);
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1647 } else { 1647 } else {
1648 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); 1648 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)));
1649 } 1649 }
1650 } 1650 }
1651 } 1651 }
1652 } 1652 }
1653 1653
1654 TEST_F(AstDecoderTest, WasmGrowMemory) { 1654 TEST_F(AstDecoderTest, WasmGrowMemory) {
1655 TestModuleEnv module_env; 1655 TestModuleEnv module_env;
1656 module = &module_env; 1656 module = &module_env;
1657 module->origin = kWasmOrigin;
1658 1657
1659 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; 1658 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0};
1660 EXPECT_VERIFIES_C(i_i, code); 1659 EXPECT_VERIFIES_C(i_i, code);
1661 EXPECT_FAILURE_C(i_d, code); 1660 EXPECT_FAILURE_C(i_d, code);
1662 } 1661 }
1663 1662
1664 TEST_F(AstDecoderTest, AsmJsGrowMemory) { 1663 TEST_F(AstDecoderTest, AsmJsGrowMemory) {
1665 TestModuleEnv module_env; 1664 TestModuleEnv module_env(kAsmJsOrigin);
1666 module = &module_env; 1665 module = &module_env;
1667 module->origin = kAsmJsOrigin;
1668 1666
1669 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; 1667 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0};
1670 EXPECT_FAILURE_C(i_i, code); 1668 EXPECT_FAILURE_C(i_i, code);
1671 } 1669 }
1672 1670
1673 TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) { 1671 TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) {
1674 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32}; 1672 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32};
1675 FunctionSig sig_f_if(1, 2, float32int32float32); 1673 FunctionSig sig_f_if(1, 2, float32int32float32);
1676 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64}; 1674 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64};
1677 FunctionSig sig_d_id(1, 2, float64int32float64); 1675 FunctionSig sig_d_id(1, 2, float64int32float64);
1678 struct { 1676 struct {
1679 WasmOpcode op; 1677 WasmOpcode op;
1680 FunctionSig* sig; 1678 FunctionSig* sig;
1681 } AsmJsBinOps[] = { 1679 } AsmJsBinOps[] = {
1682 {kExprF64Atan2, sigs.d_dd()}, 1680 {kExprF64Atan2, sigs.d_dd()},
1683 {kExprF64Pow, sigs.d_dd()}, 1681 {kExprF64Pow, sigs.d_dd()},
1684 {kExprF64Mod, sigs.d_dd()}, 1682 {kExprF64Mod, sigs.d_dd()},
1685 {kExprI32AsmjsDivS, sigs.i_ii()}, 1683 {kExprI32AsmjsDivS, sigs.i_ii()},
1686 {kExprI32AsmjsDivU, sigs.i_ii()}, 1684 {kExprI32AsmjsDivU, sigs.i_ii()},
1687 {kExprI32AsmjsRemS, sigs.i_ii()}, 1685 {kExprI32AsmjsRemS, sigs.i_ii()},
1688 {kExprI32AsmjsRemU, sigs.i_ii()}, 1686 {kExprI32AsmjsRemU, sigs.i_ii()},
1689 {kExprI32AsmjsStoreMem8, sigs.i_ii()}, 1687 {kExprI32AsmjsStoreMem8, sigs.i_ii()},
1690 {kExprI32AsmjsStoreMem16, sigs.i_ii()}, 1688 {kExprI32AsmjsStoreMem16, sigs.i_ii()},
1691 {kExprI32AsmjsStoreMem, sigs.i_ii()}, 1689 {kExprI32AsmjsStoreMem, sigs.i_ii()},
1692 {kExprF32AsmjsStoreMem, &sig_f_if}, 1690 {kExprF32AsmjsStoreMem, &sig_f_if},
1693 {kExprF64AsmjsStoreMem, &sig_d_id}, 1691 {kExprF64AsmjsStoreMem, &sig_d_id},
1694 }; 1692 };
1695 1693
1696 { 1694 {
1697 TestModuleEnv module_env; 1695 TestModuleEnv module_env(kAsmJsOrigin);
1698 module = &module_env; 1696 module = &module_env;
1699 module->origin = kAsmJsOrigin;
1700 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { 1697 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) {
1701 TestBinop(AsmJsBinOps[i].op, AsmJsBinOps[i].sig); 1698 TestBinop(AsmJsBinOps[i].op, AsmJsBinOps[i].sig);
1702 } 1699 }
1703 } 1700 }
1704 1701
1705 { 1702 {
1706 TestModuleEnv module_env; 1703 TestModuleEnv module_env;
1707 module = &module_env; 1704 module = &module_env;
1708 module->origin = kWasmOrigin;
1709 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { 1705 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) {
1710 byte code[] = { 1706 byte code[] = {
1711 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; 1707 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
1712 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); 1708 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code);
1713 } 1709 }
1714 } 1710 }
1715 } 1711 }
1716 1712
1717 TEST_F(AstDecoderTest, AsmJsUnOpsCheckOrigin) { 1713 TEST_F(AstDecoderTest, AsmJsUnOpsCheckOrigin) {
1718 LocalType float32int32[] = {kAstF32, kAstI32}; 1714 LocalType float32int32[] = {kAstF32, kAstI32};
(...skipping 16 matching lines...) Expand all
1735 {kExprI32AsmjsLoadMem16S, sigs.i_i()}, 1731 {kExprI32AsmjsLoadMem16S, sigs.i_i()},
1736 {kExprI32AsmjsLoadMem16U, sigs.i_i()}, 1732 {kExprI32AsmjsLoadMem16U, sigs.i_i()},
1737 {kExprI32AsmjsLoadMem, sigs.i_i()}, 1733 {kExprI32AsmjsLoadMem, sigs.i_i()},
1738 {kExprF32AsmjsLoadMem, &sig_f_i}, 1734 {kExprF32AsmjsLoadMem, &sig_f_i},
1739 {kExprF64AsmjsLoadMem, &sig_d_i}, 1735 {kExprF64AsmjsLoadMem, &sig_d_i},
1740 {kExprI32AsmjsSConvertF32, sigs.i_f()}, 1736 {kExprI32AsmjsSConvertF32, sigs.i_f()},
1741 {kExprI32AsmjsUConvertF32, sigs.i_f()}, 1737 {kExprI32AsmjsUConvertF32, sigs.i_f()},
1742 {kExprI32AsmjsSConvertF64, sigs.i_d()}, 1738 {kExprI32AsmjsSConvertF64, sigs.i_d()},
1743 {kExprI32AsmjsUConvertF64, sigs.i_d()}}; 1739 {kExprI32AsmjsUConvertF64, sigs.i_d()}};
1744 { 1740 {
1745 TestModuleEnv module_env; 1741 TestModuleEnv module_env(kAsmJsOrigin);
1746 module = &module_env; 1742 module = &module_env;
1747 module->origin = kAsmJsOrigin;
1748 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { 1743 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) {
1749 TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig); 1744 TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig);
1750 } 1745 }
1751 } 1746 }
1752 1747
1753 { 1748 {
1754 TestModuleEnv module_env; 1749 TestModuleEnv module_env;
1755 module = &module_env; 1750 module = &module_env;
1756 module->origin = kWasmOrigin;
1757 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { 1751 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) {
1758 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; 1752 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))};
1759 EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); 1753 EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code);
1760 } 1754 }
1761 } 1755 }
1762 } 1756 }
1763 1757
1764 TEST_F(AstDecoderTest, BreakEnd) { 1758 TEST_F(AstDecoderTest, BreakEnd) {
1765 EXPECT_VERIFIES( 1759 EXPECT_VERIFIES(
1766 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); 1760 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO)));
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after
2709 iter.next(); 2703 iter.next();
2710 EXPECT_TRUE(iter.has_next()); 2704 EXPECT_TRUE(iter.has_next());
2711 EXPECT_EQ(kExprI8Const, iter.current()); 2705 EXPECT_EQ(kExprI8Const, iter.current());
2712 iter.next(); 2706 iter.next();
2713 EXPECT_FALSE(iter.has_next()); 2707 EXPECT_FALSE(iter.has_next());
2714 } 2708 }
2715 2709
2716 } // namespace wasm 2710 } // namespace wasm
2717 } // namespace internal 2711 } // namespace internal
2718 } // namespace v8 2712 } // namespace v8
OLDNEW
« no previous file with comments | « test/fuzzer/wasm-code.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698