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

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

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

Powered by Google App Engine
This is Rietveld 408576698