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

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

Issue 2626263004: [wasm] Implement WebAssembly.Module.customSections. (Closed)
Patch Set: 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
« src/wasm/module-decoder.cc ('K') | « test/mjsunit/wasm/js-api.js ('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/handles.h" 7 #include "src/handles.h"
8 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
9 #include "src/wasm/module-decoder.h" 9 #include "src/wasm/module-decoder.h"
10 #include "src/wasm/wasm-limits.h" 10 #include "src/wasm/wasm-limits.h"
(...skipping 1490 matching lines...) Expand 10 before | Expand all | Expand 10 after
1501 1501
1502 TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) { 1502 TEST_F(WasmModuleVerifyTest, Multiple_Named_Sections) {
1503 static const byte data[] = { 1503 static const byte data[] = {
1504 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- 1504 SECTION(Unknown, 4), 1, 'X', 17, 18, // --
1505 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- 1505 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // --
1506 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- 1506 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
1507 }; 1507 };
1508 EXPECT_VERIFIES(data); 1508 EXPECT_VERIFIES(data);
1509 } 1509 }
1510 1510
1511 class WasmModuleCustomSectionTest : public TestWithIsolateAndZone {
1512 public:
1513 void CheckSections(const byte* module_start, const byte* module_end,
1514 CustomSectionOffset expected[], size_t num_expected) {
1515 // Add the WASM magic and version number automatically.
1516 size_t size = static_cast<size_t>(module_end - module_start);
1517 byte header[] = {WASM_MODULE_HEADER};
1518 size_t total = sizeof(header) + size;
1519 auto temp = new byte[total];
1520 memcpy(temp, header, sizeof(header));
1521 memcpy(temp + sizeof(header), module_start, size);
1522 std::vector<CustomSectionOffset> custom_sections =
1523 DecodeCustomSections(module_start, module_end);
1524
1525 CHECK_EQ(num_expected, custom_sections.size());
1526
1527 for (size_t i = 0; i < num_expected; i++) {
1528 EXPECT_EQ(expected[i].section_start, custom_sections[i].section_start);
1529 EXPECT_EQ(expected[i].name_offset, custom_sections[i].name_offset);
1530 EXPECT_EQ(expected[i].name_length, custom_sections[i].name_length);
1531 EXPECT_EQ(expected[i].payload_offset, custom_sections[i].payload_offset);
1532 EXPECT_EQ(expected[i].payload_length, custom_sections[i].payload_length);
1533 EXPECT_EQ(expected[i].section_length, custom_sections[i].section_length);
1534 }
1535 }
1536 };
1537
1538 TEST_F(WasmModuleCustomSectionTest, ThreeUnknownSections) {
1539 static const byte data[] = {
1540 U32_LE(kWasmMagic), // --
1541 U32_LE(kWasmVersion), // --
1542 SECTION(Unknown, 4), 1, 'X', 17, 18, // --
1543 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // --
1544 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
1545 };
1546
1547 static CustomSectionOffset expected[] = {
1548 // sec_start, nm_offset, nm_length, py_offset, py_length, sec_length
1549 {10, 11, 1, 12, 2, 4}, // --
1550 {16, 17, 3, 20, 5, 9}, // --
1551 {27, 28, 5, 33, 2, 8}, // --
1552 };
1553
1554 CheckSections(data, data + sizeof(data), expected, arraysize(expected));
1555 }
1556
1557 TEST_F(WasmModuleCustomSectionTest, TwoKnownTwoUnknownSections) {
1558 static const byte data[] = {
1559 U32_LE(kWasmMagic), // --
1560 U32_LE(kWasmVersion), // --
1561 SIGNATURES_SECTION(2, SIG_ENTRY_v_v, SIG_ENTRY_v_v), // --
1562 SECTION(Unknown, 4),
1563 1,
1564 'X',
1565 17,
1566 18, // --
1567 ONE_EMPTY_FUNCTION,
1568 SECTION(Unknown, 8),
1569 5,
1570 'o',
1571 't',
1572 'h',
1573 'e',
1574 'r',
1575 7,
1576 8, // --
1577 };
1578
1579 static CustomSectionOffset expected[] = {
1580 // sec_start, nm_offset, nm_length, py_offset, py_length, sec_length
1581 {19, 20, 1, 21, 2, 4}, // --
1582 {29, 30, 5, 35, 2, 8}, // --
1583 };
1584
1585 CheckSections(data, data + sizeof(data), expected, arraysize(expected));
1586 }
1587
1511 } // namespace wasm 1588 } // namespace wasm
1512 } // namespace internal 1589 } // namespace internal
1513 } // namespace v8 1590 } // namespace v8
OLDNEW
« src/wasm/module-decoder.cc ('K') | « test/mjsunit/wasm/js-api.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698