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

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

Issue 1776923005: [Wasm] Move data segment data inline to the data segment section (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
« no previous file with comments | « test/mjsunit/wasm/wasm-module-builder.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/wasm/module-decoder.h" 7 #include "src/wasm/module-decoder.h"
8 #include "src/wasm/wasm-macro-gen.h" 8 #include "src/wasm/wasm-macro-gen.h"
9 #include "src/wasm/wasm-opcodes.h" 9 #include "src/wasm/wasm-opcodes.h"
10 10
(...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 EXPECT_FALSE(function->exported); 449 EXPECT_FALSE(function->exported);
450 EXPECT_FALSE(function->external); 450 EXPECT_FALSE(function->external);
451 451
452 if (result.val) delete result.val; 452 if (result.val) delete result.val;
453 } 453 }
454 454
455 455
456 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { 456 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) {
457 static const byte kCodeStartOffset = 8 + 4 + 5 + 4 + 18; 457 static const byte kCodeStartOffset = 8 + 4 + 5 + 4 + 18;
458 static const byte kCodeEndOffset = kCodeStartOffset + 3; 458 static const byte kCodeEndOffset = kCodeStartOffset + 3;
459 static const byte kDataSegmentSourceOffset = kCodeEndOffset + 6;
459 460
460 static const byte data[] = { 461 static const byte data[] = {
461 kDeclMemory, 28, 28, 1, 462 kDeclMemory, 28, 28, 1,
462 // global#0 -------------------------------------------------- 463 // global#0 --------------------------------------------------
463 kDeclGlobals, 1, 0, // name length 464 kDeclGlobals, 1, 0, // name length
464 kMemU8, // memory type 465 kMemU8, // memory type
465 0, // exported 466 0, // exported
466 // sig#0 ----------------------------------------------------- 467 // sig#0 -----------------------------------------------------
467 kDeclSignatures, 1, 0, 0, // void -> void 468 kDeclSignatures, 1, 0, 0, // void -> void
468 // func#0 ---------------------------------------------------- 469 // func#0 ----------------------------------------------------
469 kDeclFunctions, 1, kDeclFunctionLocals | kDeclFunctionName, 0, 470 kDeclFunctions, 1, kDeclFunctionLocals | kDeclFunctionName, 0,
470 0, // signature index 471 0, // signature index
471 2, 'h', 'i', // name 472 2, 'h', 'i', // name
472 1, 2, // local int32 count 473 1, 2, // local int32 count
473 3, 4, // local int64 count 474 3, 4, // local int64 count
474 5, 6, // local float32 count 475 5, 6, // local float32 count
475 7, 8, // local float64 count 476 7, 8, // local float64 count
476 3, 0, // body size 477 3, 0, // body size
477 kExprNop, // func#0 body 478 kExprNop, // func#0 body
478 kExprNop, // func#0 body 479 kExprNop, // func#0 body
479 kExprNop, // func#0 body 480 kExprNop, // func#0 body
480 // segment#0 ------------------------------------------------- 481 // segment#0 -------------------------------------------------
481 kDeclDataSegments, 1, 0xae, 0xb3, 0x08, 0, // dest addr 482 kDeclDataSegments, 1, U32V_3(0x8b3ae), // dest addr
482 15, 0, 0, 0, // source offset 483 U32V_1(5), // source size
483 5, 0, 0, 0, // source size 484 0, 1, 2, 3, 4, // data bytes
484 1, // init
485 // rest ------------------------------------------------------ 485 // rest ------------------------------------------------------
486 kDeclEnd, 486 kDeclEnd,
487 }; 487 };
488 488
489 { 489 {
490 ModuleResult result = DecodeModule(data, data + arraysize(data)); 490 ModuleResult result = DecodeModule(data, data + arraysize(data));
491 EXPECT_TRUE(result.ok()); 491 EXPECT_TRUE(result.ok());
492 EXPECT_EQ(1, result.val->globals.size()); 492 EXPECT_EQ(1, result.val->globals.size());
493 EXPECT_EQ(1, result.val->functions.size()); 493 EXPECT_EQ(1, result.val->functions.size());
494 EXPECT_EQ(1, result.val->data_segments.size()); 494 EXPECT_EQ(1, result.val->data_segments.size());
(...skipping 11 matching lines...) Expand all
506 EXPECT_EQ(2, function->name_length); 506 EXPECT_EQ(2, function->name_length);
507 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); 507 EXPECT_EQ(kCodeStartOffset, function->code_start_offset);
508 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); 508 EXPECT_EQ(kCodeEndOffset, function->code_end_offset);
509 509
510 EXPECT_FALSE(function->exported); 510 EXPECT_FALSE(function->exported);
511 EXPECT_FALSE(function->external); 511 EXPECT_FALSE(function->external);
512 512
513 WasmDataSegment* segment = &result.val->data_segments.back(); 513 WasmDataSegment* segment = &result.val->data_segments.back();
514 514
515 EXPECT_EQ(0x8b3ae, segment->dest_addr); 515 EXPECT_EQ(0x8b3ae, segment->dest_addr);
516 EXPECT_EQ(15, segment->source_offset); 516 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset);
517 EXPECT_EQ(5, segment->source_size); 517 EXPECT_EQ(5, segment->source_size);
518 EXPECT_TRUE(segment->init); 518 EXPECT_TRUE(segment->init);
519 519
520 if (result.val) delete result.val; 520 if (result.val) delete result.val;
521 } 521 }
522 } 522 }
523 523
524 524
525 TEST_F(WasmModuleVerifyTest, OneDataSegment) { 525 TEST_F(WasmModuleVerifyTest, OneDataSegment) {
526 const byte kDataSegmentSourceOffset = 8 + 10;
526 const byte data[] = { 527 const byte data[] = {
527 kDeclMemory, 28, 28, 1, kDeclDataSegments, 1, 0xaa, 0xbb, 0x09, 528 kDeclMemory, 28, 28, 1,
528 0, // dest addr 529 kDeclDataSegments, 1,
529 11, 0, 0, 530 U32V_3(0x9bbaa), // dest addr
530 0, // source offset 531 U32V_1(3), // source size
531 3, 0, 0, 532 'a', 'b', 'c' // data bytes
532 0, // source size
533 1, // init
534 }; 533 };
535 534
536 { 535 {
537 EXPECT_VERIFIES(data); 536 EXPECT_VERIFIES(data);
538 ModuleResult result = DecodeModule(data, data + arraysize(data)); 537 ModuleResult result = DecodeModule(data, data + arraysize(data));
539 EXPECT_TRUE(result.ok()); 538 EXPECT_TRUE(result.ok());
540 EXPECT_EQ(0, result.val->globals.size()); 539 EXPECT_EQ(0, result.val->globals.size());
541 EXPECT_EQ(0, result.val->functions.size()); 540 EXPECT_EQ(0, result.val->functions.size());
542 EXPECT_EQ(1, result.val->data_segments.size()); 541 EXPECT_EQ(1, result.val->data_segments.size());
543 542
544 WasmDataSegment* segment = &result.val->data_segments.back(); 543 WasmDataSegment* segment = &result.val->data_segments.back();
545 544
546 EXPECT_EQ(0x9bbaa, segment->dest_addr); 545 EXPECT_EQ(0x9bbaa, segment->dest_addr);
547 EXPECT_EQ(11, segment->source_offset); 546 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset);
548 EXPECT_EQ(3, segment->source_size); 547 EXPECT_EQ(3, segment->source_size);
549 EXPECT_TRUE(segment->init); 548 EXPECT_TRUE(segment->init);
550 549
551 if (result.val) delete result.val; 550 if (result.val) delete result.val;
552 } 551 }
553 552
554 EXPECT_OFF_END_FAILURE(data, 5, sizeof(data)); 553 EXPECT_OFF_END_FAILURE(data, 5, sizeof(data));
555 } 554 }
556 555
557 556
558 TEST_F(WasmModuleVerifyTest, TwoDataSegments) { 557 TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
558 const byte kDataSegment0SourceOffset = 8 + 10;
559 const byte kDataSegment1SourceOffset = 8 + 10 + 8;
560
559 const byte data[] = { 561 const byte data[] = {
560 kDeclMemory, 28, 28, 1, kDeclDataSegments, 2, 0xee, 0xff, 0x07, 562 kDeclMemory, 28, 28, 1,
561 0, // dest addr 563 kDeclDataSegments, 2,
562 9, 0, 0, 564 U32V_3(0x7ffee), // #0: dest addr
563 0, // #0: source offset 565 U32V_1(4), // source size
564 4, 0, 0, 566 1, 2, 3, 4, // data bytes
565 0, // source size 567 U32V_3(0x6ddcc), // #1: dest addr
566 0, // init 568 U32V_1(10), // source size
567 0xcc, 0xdd, 0x06, 569 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 // data bytes
568 0, // #1: dest addr
569 6, 0, 0,
570 0, // source offset
571 10, 0, 0,
572 0, // source size
573 1, // init
574 }; 570 };
575 571
576 { 572 {
577 ModuleResult result = DecodeModule(data, data + arraysize(data)); 573 ModuleResult result = DecodeModule(data, data + arraysize(data));
578 EXPECT_TRUE(result.ok()); 574 EXPECT_TRUE(result.ok());
579 EXPECT_EQ(0, result.val->globals.size()); 575 EXPECT_EQ(0, result.val->globals.size());
580 EXPECT_EQ(0, result.val->functions.size()); 576 EXPECT_EQ(0, result.val->functions.size());
581 EXPECT_EQ(2, result.val->data_segments.size()); 577 EXPECT_EQ(2, result.val->data_segments.size());
582 578
583 WasmDataSegment* s0 = &result.val->data_segments[0]; 579 WasmDataSegment* s0 = &result.val->data_segments[0];
584 WasmDataSegment* s1 = &result.val->data_segments[1]; 580 WasmDataSegment* s1 = &result.val->data_segments[1];
585 581
586 EXPECT_EQ(0x7ffee, s0->dest_addr); 582 EXPECT_EQ(0x7ffee, s0->dest_addr);
587 EXPECT_EQ(9, s0->source_offset); 583 EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset);
588 EXPECT_EQ(4, s0->source_size); 584 EXPECT_EQ(4, s0->source_size);
589 EXPECT_FALSE(s0->init); 585 EXPECT_TRUE(s0->init);
590 586
591 EXPECT_EQ(0x6ddcc, s1->dest_addr); 587 EXPECT_EQ(0x6ddcc, s1->dest_addr);
592 EXPECT_EQ(6, s1->source_offset); 588 EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset);
593 EXPECT_EQ(10, s1->source_size); 589 EXPECT_EQ(10, s1->source_size);
594 EXPECT_TRUE(s1->init); 590 EXPECT_TRUE(s1->init);
595 591
596 if (result.val) delete result.val; 592 if (result.val) delete result.val;
597 } 593 }
598 594
599 EXPECT_OFF_END_FAILURE(data, 5, sizeof(data)); 595 EXPECT_OFF_END_FAILURE(data, 5, sizeof(data));
600 } 596 }
601 597
602 598
603 TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidSource) {
604 const int dest_addr = 0x100;
605 const byte mem_pages = 1;
606 const int kHeaderSize = 8;
607 const int kDataSize = 19;
608 const int kTotalSize = kHeaderSize + kDataSize;
609
610 for (int source_offset = 0; source_offset < 5 + kDataSize; source_offset++) {
611 for (int source_size = -1; source_size < 5 + kDataSize; source_size += 3) {
612 byte data[] = {
613 kDeclMemory,
614 mem_pages,
615 mem_pages,
616 1,
617 kDeclDataSegments,
618 1,
619 U32_LE(dest_addr),
620 U32_LE(source_offset),
621 U32_LE(source_size),
622 1, // init
623 };
624
625 STATIC_ASSERT(kDataSize == arraysize(data));
626
627 if (source_offset < kTotalSize && source_size >= 0 &&
628 (source_offset + source_size) <= kTotalSize) {
629 EXPECT_VERIFIES(data);
630 } else {
631 EXPECT_FAILURE(data);
632 }
633 }
634 }
635 }
636
637
638 TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidDest) { 599 TEST_F(WasmModuleVerifyTest, DataSegmentWithInvalidDest) {
639 const int source_size = 3; 600 const int source_size = 3;
640 const int source_offset = 11;
641 601
642 for (byte mem_pages = 1; mem_pages < 16; mem_pages++) { 602 for (byte mem_pages = 1; mem_pages < 16; mem_pages++) {
643 int mem_size = mem_pages * 0x10000; // 64k pages. 603 int mem_size = mem_pages * 0x10000; // 64k pages.
644 604
645 for (int dest_addr = mem_size - source_size; 605 for (int dest_addr = mem_size - source_size;
646 dest_addr < mem_size + source_size; dest_addr++) { 606 dest_addr < mem_size + source_size; dest_addr++) {
647 byte data[] = { 607 byte data[] = {
648 kDeclMemory, 608 kDeclMemory,
649 mem_pages, 609 mem_pages,
650 mem_pages, 610 mem_pages,
651 1, 611 1,
652 kDeclDataSegments, 612 kDeclDataSegments,
653 1, 613 1,
654 U32_LE(dest_addr), 614 U32V_3(dest_addr),
655 U32_LE(source_offset), 615 U32V_1(source_size),
656 U32_LE(source_size), 616 'a', 'b', 'c'
657 1, // init
658 }; 617 };
659 618
660 if (dest_addr <= (mem_size - source_size)) { 619 if (dest_addr <= (mem_size - source_size)) {
661 EXPECT_VERIFIES(data); 620 EXPECT_VERIFIES(data);
662 } else { 621 } else {
663 EXPECT_FAILURE(data); 622 EXPECT_FAILURE(data);
664 } 623 }
665 } 624 }
666 } 625 }
667 } 626 }
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 for (int length = 13; length < sizeof(data); length++) { 1158 for (int length = 13; length < sizeof(data); length++) {
1200 ModuleResult result = DecodeModule(data, data + length); 1159 ModuleResult result = DecodeModule(data, data + length);
1201 EXPECT_FALSE(result.ok()); 1160 EXPECT_FALSE(result.ok());
1202 if (result.val) delete result.val; 1161 if (result.val) delete result.val;
1203 } 1162 }
1204 } 1163 }
1205 1164
1206 } // namespace wasm 1165 } // namespace wasm
1207 } // namespace internal 1166 } // namespace internal
1208 } // namespace v8 1167 } // namespace v8
OLDNEW
« no previous file with comments | « test/mjsunit/wasm/wasm-module-builder.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698