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

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

Issue 1787733002: [wasm] Fix OpcodeLength() calculation. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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 "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/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after
1718 public: 1718 public:
1719 WasmOpcodeLengthTest() : TestWithZone() {} 1719 WasmOpcodeLengthTest() : TestWithZone() {}
1720 }; 1720 };
1721 1721
1722 #define EXPECT_LENGTH(expected, opcode) \ 1722 #define EXPECT_LENGTH(expected, opcode) \
1723 { \ 1723 { \
1724 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ 1724 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \
1725 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ 1725 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \
1726 } 1726 }
1727 1727
1728 #define EXPECT_LENGTH_N(expected, ...) \
1729 { \
1730 static const byte code[] = {__VA_ARGS__}; \
1731 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \
1732 }
1733
1728 TEST_F(WasmOpcodeLengthTest, Statements) { 1734 TEST_F(WasmOpcodeLengthTest, Statements) {
1729 EXPECT_LENGTH(1, kExprNop); 1735 EXPECT_LENGTH(1, kExprNop);
1730 EXPECT_LENGTH(2, kExprBlock); 1736 EXPECT_LENGTH(2, kExprBlock);
1731 EXPECT_LENGTH(2, kExprLoop); 1737 EXPECT_LENGTH(2, kExprLoop);
1732 EXPECT_LENGTH(1, kExprIf); 1738 EXPECT_LENGTH(1, kExprIf);
1733 EXPECT_LENGTH(1, kExprIfElse); 1739 EXPECT_LENGTH(1, kExprIfElse);
1734 EXPECT_LENGTH(1, kExprSelect); 1740 EXPECT_LENGTH(1, kExprSelect);
1735 EXPECT_LENGTH(2, kExprBr); 1741 EXPECT_LENGTH(2, kExprBr);
1736 EXPECT_LENGTH(2, kExprBrIf); 1742 EXPECT_LENGTH(2, kExprBrIf);
1737 } 1743 }
1738 1744
1739 1745
1740 TEST_F(WasmOpcodeLengthTest, MiscExpressions) { 1746 TEST_F(WasmOpcodeLengthTest, MiscExpressions) {
1741 EXPECT_LENGTH(2, kExprI8Const); 1747 EXPECT_LENGTH(2, kExprI8Const);
1742 EXPECT_LENGTH(5, kExprI32Const);
1743 EXPECT_LENGTH(5, kExprF32Const); 1748 EXPECT_LENGTH(5, kExprF32Const);
1744 EXPECT_LENGTH(9, kExprI64Const);
1745 EXPECT_LENGTH(9, kExprF64Const); 1749 EXPECT_LENGTH(9, kExprF64Const);
1746 EXPECT_LENGTH(2, kExprGetLocal); 1750 EXPECT_LENGTH(2, kExprGetLocal);
1747 EXPECT_LENGTH(2, kExprSetLocal); 1751 EXPECT_LENGTH(2, kExprSetLocal);
1748 EXPECT_LENGTH(2, kExprLoadGlobal); 1752 EXPECT_LENGTH(2, kExprLoadGlobal);
1749 EXPECT_LENGTH(2, kExprStoreGlobal); 1753 EXPECT_LENGTH(2, kExprStoreGlobal);
1750 EXPECT_LENGTH(2, kExprCallFunction); 1754 EXPECT_LENGTH(2, kExprCallFunction);
1751 EXPECT_LENGTH(2, kExprCallImport); 1755 EXPECT_LENGTH(2, kExprCallImport);
1752 EXPECT_LENGTH(2, kExprCallIndirect); 1756 EXPECT_LENGTH(2, kExprCallIndirect);
1753 EXPECT_LENGTH(1, kExprIf); 1757 EXPECT_LENGTH(1, kExprIf);
1754 EXPECT_LENGTH(1, kExprIfElse); 1758 EXPECT_LENGTH(1, kExprIfElse);
1755 EXPECT_LENGTH(2, kExprBlock); 1759 EXPECT_LENGTH(2, kExprBlock);
1756 EXPECT_LENGTH(2, kExprLoop); 1760 EXPECT_LENGTH(2, kExprLoop);
1757 EXPECT_LENGTH(2, kExprBr); 1761 EXPECT_LENGTH(2, kExprBr);
1758 EXPECT_LENGTH(2, kExprBrIf); 1762 EXPECT_LENGTH(2, kExprBrIf);
1759 } 1763 }
1760 1764
1765 TEST_F(WasmOpcodeLengthTest, I32Const) {
1766 EXPECT_LENGTH_N(2, kExprI32Const, U32V_1(1));
1767 EXPECT_LENGTH_N(3, kExprI32Const, U32V_2(999));
1768 EXPECT_LENGTH_N(4, kExprI32Const, U32V_3(9999));
1769 EXPECT_LENGTH_N(5, kExprI32Const, U32V_4(999999));
1770 EXPECT_LENGTH_N(6, kExprI32Const, U32V_5(99999999));
1771 }
1772
1773 TEST_F(WasmOpcodeLengthTest, I64Const) {
1774 EXPECT_LENGTH_N(2, kExprI64Const, U32V_1(1));
1775 EXPECT_LENGTH_N(3, kExprI64Const, U32V_2(99));
1776 EXPECT_LENGTH_N(4, kExprI64Const, U32V_3(9999));
1777 EXPECT_LENGTH_N(5, kExprI64Const, U32V_4(99999));
1778 EXPECT_LENGTH_N(6, kExprI64Const, U32V_5(9999999));
1779 EXPECT_LENGTH_N(7, WASM_I64V_6(777777));
1780 EXPECT_LENGTH_N(8, WASM_I64V_7(7777777));
1781 EXPECT_LENGTH_N(9, WASM_I64V_8(77777777));
1782 EXPECT_LENGTH_N(10, WASM_I64V_9(777777777));
1783 }
1761 1784
1762 TEST_F(WasmOpcodeLengthTest, VariableLength) { 1785 TEST_F(WasmOpcodeLengthTest, VariableLength) {
1763 byte size2[] = {kExprLoadGlobal, 1}; 1786 EXPECT_LENGTH_N(2, kExprLoadGlobal, U32V_1(1));
1764 byte size3[] = {kExprLoadGlobal, 1 | 0x80, 2}; 1787 EXPECT_LENGTH_N(3, kExprLoadGlobal, U32V_2(33));
1765 byte size4[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3}; 1788 EXPECT_LENGTH_N(4, kExprLoadGlobal, U32V_3(44));
1766 byte size5[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4}; 1789 EXPECT_LENGTH_N(5, kExprLoadGlobal, U32V_4(66));
1767 byte size6[] = {kExprLoadGlobal, 1 | 0x80, 2 | 0x80, 3 | 0x80, 4 | 0x80, 5}; 1790 EXPECT_LENGTH_N(6, kExprLoadGlobal, U32V_5(77));
1768
1769 EXPECT_EQ(2, OpcodeLength(size2, size2 + sizeof(size2)));
1770 EXPECT_EQ(3, OpcodeLength(size3, size3 + sizeof(size3)));
1771 EXPECT_EQ(4, OpcodeLength(size4, size4 + sizeof(size4)));
1772 EXPECT_EQ(5, OpcodeLength(size5, size5 + sizeof(size5)));
1773 EXPECT_EQ(6, OpcodeLength(size6, size6 + sizeof(size6)));
1774 } 1791 }
1775 1792
1776
1777 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) { 1793 TEST_F(WasmOpcodeLengthTest, LoadsAndStores) {
1778 EXPECT_LENGTH(3, kExprI32LoadMem8S); 1794 EXPECT_LENGTH(3, kExprI32LoadMem8S);
1779 EXPECT_LENGTH(3, kExprI32LoadMem8U); 1795 EXPECT_LENGTH(3, kExprI32LoadMem8U);
1780 EXPECT_LENGTH(3, kExprI32LoadMem16S); 1796 EXPECT_LENGTH(3, kExprI32LoadMem16S);
1781 EXPECT_LENGTH(3, kExprI32LoadMem16U); 1797 EXPECT_LENGTH(3, kExprI32LoadMem16U);
1782 EXPECT_LENGTH(3, kExprI32LoadMem); 1798 EXPECT_LENGTH(3, kExprI32LoadMem);
1783 EXPECT_LENGTH(3, kExprI64LoadMem8S); 1799 EXPECT_LENGTH(3, kExprI64LoadMem8S);
1784 EXPECT_LENGTH(3, kExprI64LoadMem8U); 1800 EXPECT_LENGTH(3, kExprI64LoadMem8U);
1785 EXPECT_LENGTH(3, kExprI64LoadMem16S); 1801 EXPECT_LENGTH(3, kExprI64LoadMem16S);
1786 EXPECT_LENGTH(3, kExprI64LoadMem16U); 1802 EXPECT_LENGTH(3, kExprI64LoadMem16U);
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
2264 pos = ExpectRun(map, pos, kAstI32, 1337); 2280 pos = ExpectRun(map, pos, kAstI32, 1337);
2265 pos = ExpectRun(map, pos, kAstI64, 212); 2281 pos = ExpectRun(map, pos, kAstI64, 212);
2266 2282
2267 if (map) delete map; 2283 if (map) delete map;
2268 delete[] data; 2284 delete[] data;
2269 } 2285 }
2270 2286
2271 } // namespace wasm 2287 } // namespace wasm
2272 } // namespace internal 2288 } // namespace internal
2273 } // namespace v8 2289 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698