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

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

Issue 2492793005: [wasm] Fix more -Wsign-compare warnings. (Closed)
Patch Set: Created 4 years, 1 month 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/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-macro-gen.h" 10 #include "src/wasm/wasm-macro-gen.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 1, 185 1,
186 kLocalI32, // local type 186 kLocalI32, // local type
187 0, // immutable 187 0, // immutable
188 WASM_INIT_EXPR_I32V_1(13) // init 188 WASM_INIT_EXPR_I32V_1(13) // init
189 }; 189 };
190 190
191 { 191 {
192 // Should decode to exactly one global. 192 // Should decode to exactly one global.
193 ModuleResult result = DecodeModule(data, data + sizeof(data)); 193 ModuleResult result = DecodeModule(data, data + sizeof(data));
194 EXPECT_OK(result); 194 EXPECT_OK(result);
195 EXPECT_EQ(1, result.val->globals.size()); 195 EXPECT_EQ(1u, result.val->globals.size());
196 EXPECT_EQ(0, result.val->functions.size()); 196 EXPECT_EQ(0u, result.val->functions.size());
197 EXPECT_EQ(0, result.val->data_segments.size()); 197 EXPECT_EQ(0u, result.val->data_segments.size());
198 198
199 const WasmGlobal* global = &result.val->globals.back(); 199 const WasmGlobal* global = &result.val->globals.back();
200 200
201 EXPECT_EQ(kAstI32, global->type); 201 EXPECT_EQ(kAstI32, global->type);
202 EXPECT_EQ(0, global->offset); 202 EXPECT_EQ(0u, global->offset);
203 EXPECT_FALSE(global->mutability); 203 EXPECT_FALSE(global->mutability);
204 EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind); 204 EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind);
205 EXPECT_EQ(13, global->init.val.i32_const); 205 EXPECT_EQ(13, global->init.val.i32_const);
206 206
207 if (result.val) delete result.val; 207 if (result.val) delete result.val;
208 } 208 }
209 209
210 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); 210 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
211 } 211 }
212 212
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 WASM_INIT_EXPR_F32(22.0), 346 WASM_INIT_EXPR_F32(22.0),
347 kLocalF64, // type 347 kLocalF64, // type
348 1, // mutable 348 1, // mutable
349 WASM_INIT_EXPR_F64(23.0), 349 WASM_INIT_EXPR_F64(23.0),
350 }; 350 };
351 351
352 { 352 {
353 // Should decode to exactly two globals. 353 // Should decode to exactly two globals.
354 ModuleResult result = DecodeModule(data, data + sizeof(data)); 354 ModuleResult result = DecodeModule(data, data + sizeof(data));
355 EXPECT_OK(result); 355 EXPECT_OK(result);
356 EXPECT_EQ(2, result.val->globals.size()); 356 EXPECT_EQ(2u, result.val->globals.size());
357 EXPECT_EQ(0, result.val->functions.size()); 357 EXPECT_EQ(0u, result.val->functions.size());
358 EXPECT_EQ(0, result.val->data_segments.size()); 358 EXPECT_EQ(0u, result.val->data_segments.size());
359 359
360 const WasmGlobal* g0 = &result.val->globals[0]; 360 const WasmGlobal* g0 = &result.val->globals[0];
361 361
362 EXPECT_EQ(kAstF32, g0->type); 362 EXPECT_EQ(kAstF32, g0->type);
363 EXPECT_EQ(0, g0->offset); 363 EXPECT_EQ(0u, g0->offset);
364 EXPECT_FALSE(g0->mutability); 364 EXPECT_FALSE(g0->mutability);
365 EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind); 365 EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind);
366 366
367 const WasmGlobal* g1 = &result.val->globals[1]; 367 const WasmGlobal* g1 = &result.val->globals[1];
368 368
369 EXPECT_EQ(kAstF64, g1->type); 369 EXPECT_EQ(kAstF64, g1->type);
370 EXPECT_EQ(8, g1->offset); 370 EXPECT_EQ(8u, g1->offset);
371 EXPECT_TRUE(g1->mutability); 371 EXPECT_TRUE(g1->mutability);
372 EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind); 372 EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind);
373 373
374 if (result.val) delete result.val; 374 if (result.val) delete result.val;
375 } 375 }
376 376
377 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); 377 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
378 } 378 }
379 379
380 TEST_F(WasmModuleVerifyTest, OneSignature) { 380 TEST_F(WasmModuleVerifyTest, OneSignature) {
(...skipping 14 matching lines...) Expand all
395 SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_x_x + 395 SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_x_x +
396 SIZEOF_SIG_ENTRY_x_xx), // -- 396 SIZEOF_SIG_ENTRY_x_xx), // --
397 3, // -- 397 3, // --
398 SIG_ENTRY_v_v, // void -> void 398 SIG_ENTRY_v_v, // void -> void
399 SIG_ENTRY_x_x(kLocalI32, kLocalF32), // f32 -> i32 399 SIG_ENTRY_x_x(kLocalI32, kLocalF32), // f32 -> i32
400 SIG_ENTRY_x_xx(kLocalI32, kLocalF64, kLocalF64), // f64,f64 -> i32 400 SIG_ENTRY_x_xx(kLocalI32, kLocalF64, kLocalF64), // f64,f64 -> i32
401 }; 401 };
402 402
403 ModuleResult result = DecodeModule(data, data + sizeof(data)); 403 ModuleResult result = DecodeModule(data, data + sizeof(data));
404 EXPECT_OK(result); 404 EXPECT_OK(result);
405 EXPECT_EQ(3, result.val->signatures.size()); 405 EXPECT_EQ(3u, result.val->signatures.size());
406 if (result.val->signatures.size() == 3) { 406 if (result.val->signatures.size() == 3) {
407 EXPECT_EQ(0, result.val->signatures[0]->return_count()); 407 EXPECT_EQ(0u, result.val->signatures[0]->return_count());
408 EXPECT_EQ(1, result.val->signatures[1]->return_count()); 408 EXPECT_EQ(1u, result.val->signatures[1]->return_count());
409 EXPECT_EQ(1, result.val->signatures[2]->return_count()); 409 EXPECT_EQ(1u, result.val->signatures[2]->return_count());
410 410
411 EXPECT_EQ(0, result.val->signatures[0]->parameter_count()); 411 EXPECT_EQ(0u, result.val->signatures[0]->parameter_count());
412 EXPECT_EQ(1, result.val->signatures[1]->parameter_count()); 412 EXPECT_EQ(1u, result.val->signatures[1]->parameter_count());
413 EXPECT_EQ(2, result.val->signatures[2]->parameter_count()); 413 EXPECT_EQ(2u, result.val->signatures[2]->parameter_count());
414 } 414 }
415 if (result.val) delete result.val; 415 if (result.val) delete result.val;
416 416
417 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); 417 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
418 } 418 }
419 419
420 TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) { 420 TEST_F(WasmModuleVerifyTest, DataSegmentWithImmutableImportedGlobal) {
421 // Import 2 globals so that we can initialize data with a global index != 0. 421 // Import 2 globals so that we can initialize data with a global index != 0.
422 const byte data[] = { 422 const byte data[] = {
423 SECTION(Import, 15), // section header 423 SECTION(Import, 15), // section header
(...skipping 23 matching lines...) Expand all
447 WASM_INIT_EXPR_GLOBAL(1), // dest addr 447 WASM_INIT_EXPR_GLOBAL(1), // dest addr
448 U32V_1(3), // source size 448 U32V_1(3), // source size
449 'a', 449 'a',
450 'b', 450 'b',
451 'c' // data bytes 451 'c' // data bytes
452 }; 452 };
453 ModuleResult result = DecodeModule(data, data + sizeof(data)); 453 ModuleResult result = DecodeModule(data, data + sizeof(data));
454 EXPECT_OK(result); 454 EXPECT_OK(result);
455 WasmInitExpr expr = result.val->data_segments.back().dest_addr; 455 WasmInitExpr expr = result.val->data_segments.back().dest_addr;
456 EXPECT_EQ(WasmInitExpr::kGlobalIndex, expr.kind); 456 EXPECT_EQ(WasmInitExpr::kGlobalIndex, expr.kind);
457 EXPECT_EQ(1, expr.val.global_index); 457 EXPECT_EQ(1u, expr.val.global_index);
458 if (result.val) delete result.val; 458 if (result.val) delete result.val;
459 } 459 }
460 460
461 TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) { 461 TEST_F(WasmModuleVerifyTest, DataSegmentWithMutableImportedGlobal) {
462 // Only an immutable imported global can be used as an init_expr. 462 // Only an immutable imported global can be used as an init_expr.
463 const byte data[] = { 463 const byte data[] = {
464 SECTION(Import, 8), // section header 464 SECTION(Import, 8), // section header
465 1, // number of imports 465 1, // number of imports
466 NAME_LENGTH(1), // -- 466 NAME_LENGTH(1), // --
467 'm', // module name 467 'm', // module name
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 U32V_1(3), // source size 526 U32V_1(3), // source size
527 'a', 527 'a',
528 'b', 528 'b',
529 'c' // data bytes 529 'c' // data bytes
530 }; 530 };
531 531
532 { 532 {
533 EXPECT_VERIFIES(data); 533 EXPECT_VERIFIES(data);
534 ModuleResult result = DecodeModule(data, data + sizeof(data)); 534 ModuleResult result = DecodeModule(data, data + sizeof(data));
535 EXPECT_OK(result); 535 EXPECT_OK(result);
536 EXPECT_EQ(0, result.val->globals.size()); 536 EXPECT_EQ(0u, result.val->globals.size());
537 EXPECT_EQ(0, result.val->functions.size()); 537 EXPECT_EQ(0u, result.val->functions.size());
538 EXPECT_EQ(1, result.val->data_segments.size()); 538 EXPECT_EQ(1u, result.val->data_segments.size());
539 539
540 const WasmDataSegment* segment = &result.val->data_segments.back(); 540 const WasmDataSegment* segment = &result.val->data_segments.back();
541 541
542 EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind); 542 EXPECT_EQ(WasmInitExpr::kI32Const, segment->dest_addr.kind);
543 EXPECT_EQ(0x9bbaa, segment->dest_addr.val.i32_const); 543 EXPECT_EQ(0x9bbaa, segment->dest_addr.val.i32_const);
544 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); 544 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset);
545 EXPECT_EQ(3, segment->source_size); 545 EXPECT_EQ(3u, segment->source_size);
546 546
547 if (result.val) delete result.val; 547 if (result.val) delete result.val;
548 } 548 }
549 549
550 EXPECT_OFF_END_FAILURE(data, 14, sizeof(data)); 550 EXPECT_OFF_END_FAILURE(data, 14, sizeof(data));
551 } 551 }
552 552
553 TEST_F(WasmModuleVerifyTest, TwoDataSegments) { 553 TEST_F(WasmModuleVerifyTest, TwoDataSegments) {
554 const byte kDataSegment0SourceOffset = 24; 554 const byte kDataSegment0SourceOffset = 24;
555 const byte kDataSegment1SourceOffset = kDataSegment0SourceOffset + 11; 555 const byte kDataSegment1SourceOffset = kDataSegment0SourceOffset + 11;
(...skipping 24 matching lines...) Expand all
580 6, 580 6,
581 7, 581 7,
582 8, 582 8,
583 9, 583 9,
584 10 // data bytes 584 10 // data bytes
585 }; 585 };
586 586
587 { 587 {
588 ModuleResult result = DecodeModule(data, data + sizeof(data)); 588 ModuleResult result = DecodeModule(data, data + sizeof(data));
589 EXPECT_OK(result); 589 EXPECT_OK(result);
590 EXPECT_EQ(0, result.val->globals.size()); 590 EXPECT_EQ(0u, result.val->globals.size());
591 EXPECT_EQ(0, result.val->functions.size()); 591 EXPECT_EQ(0u, result.val->functions.size());
592 EXPECT_EQ(2, result.val->data_segments.size()); 592 EXPECT_EQ(2u, result.val->data_segments.size());
593 593
594 const WasmDataSegment* s0 = &result.val->data_segments[0]; 594 const WasmDataSegment* s0 = &result.val->data_segments[0];
595 const WasmDataSegment* s1 = &result.val->data_segments[1]; 595 const WasmDataSegment* s1 = &result.val->data_segments[1];
596 596
597 EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind); 597 EXPECT_EQ(WasmInitExpr::kI32Const, s0->dest_addr.kind);
598 EXPECT_EQ(0x7ffee, s0->dest_addr.val.i32_const); 598 EXPECT_EQ(0x7ffee, s0->dest_addr.val.i32_const);
599 EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset); 599 EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset);
600 EXPECT_EQ(4, s0->source_size); 600 EXPECT_EQ(4u, s0->source_size);
601 601
602 EXPECT_EQ(WasmInitExpr::kI32Const, s1->dest_addr.kind); 602 EXPECT_EQ(WasmInitExpr::kI32Const, s1->dest_addr.kind);
603 EXPECT_EQ(0x6ddcc, s1->dest_addr.val.i32_const); 603 EXPECT_EQ(0x6ddcc, s1->dest_addr.val.i32_const);
604 EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset); 604 EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset);
605 EXPECT_EQ(10, s1->source_size); 605 EXPECT_EQ(10u, s1->source_size);
606 606
607 if (result.val) delete result.val; 607 if (result.val) delete result.val;
608 } 608 }
609 609
610 EXPECT_OFF_END_FAILURE(data, 14, sizeof(data)); 610 EXPECT_OFF_END_FAILURE(data, 14, sizeof(data));
611 } 611 }
612 612
613 TEST_F(WasmModuleVerifyTest, DataWithoutMemory) { 613 TEST_F(WasmModuleVerifyTest, DataWithoutMemory) {
614 const byte data[] = { 614 const byte data[] = {
615 SECTION(Data, 11), 615 SECTION(Data, 11),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 // sig#0 --------------------------------------------------------------- 666 // sig#0 ---------------------------------------------------------------
667 SIGNATURES_SECTION_VOID_VOID, 667 SIGNATURES_SECTION_VOID_VOID,
668 // funcs --------------------------------------------------------------- 668 // funcs ---------------------------------------------------------------
669 ONE_EMPTY_FUNCTION, 669 ONE_EMPTY_FUNCTION,
670 // table declaration --------------------------------------------------- 670 // table declaration ---------------------------------------------------
671 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1}; 671 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1};
672 672
673 ModuleResult result = DecodeModule(data, data + sizeof(data)); 673 ModuleResult result = DecodeModule(data, data + sizeof(data));
674 EXPECT_OK(result); 674 EXPECT_OK(result);
675 if (result.ok()) { 675 if (result.ok()) {
676 EXPECT_EQ(1, result.val->signatures.size()); 676 EXPECT_EQ(1u, result.val->signatures.size());
677 EXPECT_EQ(1, result.val->functions.size()); 677 EXPECT_EQ(1u, result.val->functions.size());
678 EXPECT_EQ(1, result.val->function_tables.size()); 678 EXPECT_EQ(1u, result.val->function_tables.size());
679 EXPECT_EQ(1, result.val->function_tables[0].min_size); 679 EXPECT_EQ(1u, result.val->function_tables[0].min_size);
680 } 680 }
681 if (result.val) delete result.val; 681 if (result.val) delete result.val;
682 } 682 }
683 683
684 TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) { 684 TEST_F(WasmModuleVerifyTest, OneIndirectFunction_one_entry) {
685 static const byte data[] = { 685 static const byte data[] = {
686 // sig#0 --------------------------------------------------------------- 686 // sig#0 ---------------------------------------------------------------
687 SIGNATURES_SECTION_VOID_VOID, 687 SIGNATURES_SECTION_VOID_VOID,
688 // funcs --------------------------------------------------------------- 688 // funcs ---------------------------------------------------------------
689 ONE_EMPTY_FUNCTION, 689 ONE_EMPTY_FUNCTION,
690 // table declaration --------------------------------------------------- 690 // table declaration ---------------------------------------------------
691 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1, 691 SECTION(Table, 4), ENTRY_COUNT(1), kWasmAnyFunctionTypeForm, 0, 1,
692 // elements ------------------------------------------------------------ 692 // elements ------------------------------------------------------------
693 SECTION(Element, 7), 693 SECTION(Element, 7),
694 1, // entry count 694 1, // entry count
695 TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0), 695 TABLE_INDEX(0), WASM_INIT_EXPR_I32V_1(0),
696 1, // elements count 696 1, // elements count
697 FUNC_INDEX(0)}; 697 FUNC_INDEX(0)};
698 698
699 ModuleResult result = DecodeModule(data, data + sizeof(data)); 699 ModuleResult result = DecodeModule(data, data + sizeof(data));
700 EXPECT_OK(result); 700 EXPECT_OK(result);
701 if (result.ok()) { 701 if (result.ok()) {
702 EXPECT_EQ(1, result.val->signatures.size()); 702 EXPECT_EQ(1u, result.val->signatures.size());
703 EXPECT_EQ(1, result.val->functions.size()); 703 EXPECT_EQ(1u, result.val->functions.size());
704 EXPECT_EQ(1, result.val->function_tables.size()); 704 EXPECT_EQ(1u, result.val->function_tables.size());
705 EXPECT_EQ(1, result.val->function_tables[0].min_size); 705 EXPECT_EQ(1u, result.val->function_tables[0].min_size);
706 } 706 }
707 if (result.val) delete result.val; 707 if (result.val) delete result.val;
708 } 708 }
709 709
710 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { 710 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
711 static const byte data[] = { 711 static const byte data[] = {
712 // sig#0 ------------------------------------------------------- 712 // sig#0 -------------------------------------------------------
713 SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), 713 SECTION(Type, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x),
714 2, // -- 714 2, // --
715 SIG_ENTRY_v_v, // void -> void 715 SIG_ENTRY_v_v, // void -> void
(...skipping 13 matching lines...) Expand all
729 FUNC_INDEX(3), // -- 729 FUNC_INDEX(3), // --
730 FUNC_INDEX(0), // -- 730 FUNC_INDEX(0), // --
731 FUNC_INDEX(1), // -- 731 FUNC_INDEX(1), // --
732 FUNC_INDEX(2), // -- 732 FUNC_INDEX(2), // --
733 FUNC_INDEX(3), // -- 733 FUNC_INDEX(3), // --
734 FOUR_EMPTY_BODIES}; 734 FOUR_EMPTY_BODIES};
735 735
736 ModuleResult result = DecodeModule(data, data + sizeof(data)); 736 ModuleResult result = DecodeModule(data, data + sizeof(data));
737 EXPECT_OK(result); 737 EXPECT_OK(result);
738 if (result.ok()) { 738 if (result.ok()) {
739 EXPECT_EQ(2, result.val->signatures.size()); 739 EXPECT_EQ(2u, result.val->signatures.size());
740 EXPECT_EQ(4, result.val->functions.size()); 740 EXPECT_EQ(4u, result.val->functions.size());
741 EXPECT_EQ(1, result.val->function_tables.size()); 741 EXPECT_EQ(1u, result.val->function_tables.size());
742 EXPECT_EQ(8, result.val->function_tables[0].min_size); 742 EXPECT_EQ(8u, result.val->function_tables[0].min_size);
743 } 743 }
744 if (result.val) delete result.val; 744 if (result.val) delete result.val;
745 } 745 }
746 746
747 TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) { 747 TEST_F(WasmModuleVerifyTest, IndirectFunctionNoFunctions) {
748 static const byte data[] = { 748 static const byte data[] = {
749 // sig#0 ------------------------------------------------------- 749 // sig#0 -------------------------------------------------------
750 SIGNATURES_SECTION_VOID_VOID, 750 SIGNATURES_SECTION_VOID_VOID,
751 // indirect table ---------------------------------------------- 751 // indirect table ----------------------------------------------
752 SECTION(Table, 4), ENTRY_COUNT(1), 1, 0, 0, 752 SECTION(Table, 4), ENTRY_COUNT(1), 1, 0, 0,
(...skipping 18 matching lines...) Expand all
771 class WasmSignatureDecodeTest : public TestWithZone {}; 771 class WasmSignatureDecodeTest : public TestWithZone {};
772 772
773 TEST_F(WasmSignatureDecodeTest, Ok_v_v) { 773 TEST_F(WasmSignatureDecodeTest, Ok_v_v) {
774 static const byte data[] = {SIG_ENTRY_v_v}; 774 static const byte data[] = {SIG_ENTRY_v_v};
775 v8::internal::AccountingAllocator allocator; 775 v8::internal::AccountingAllocator allocator;
776 Zone zone(&allocator, ZONE_NAME); 776 Zone zone(&allocator, ZONE_NAME);
777 FunctionSig* sig = 777 FunctionSig* sig =
778 DecodeWasmSignatureForTesting(&zone, data, data + sizeof(data)); 778 DecodeWasmSignatureForTesting(&zone, data, data + sizeof(data));
779 779
780 EXPECT_TRUE(sig != nullptr); 780 EXPECT_TRUE(sig != nullptr);
781 EXPECT_EQ(0, sig->parameter_count()); 781 EXPECT_EQ(0u, sig->parameter_count());
782 EXPECT_EQ(0, sig->return_count()); 782 EXPECT_EQ(0u, sig->return_count());
783 } 783 }
784 784
785 TEST_F(WasmSignatureDecodeTest, Ok_t_v) { 785 TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
786 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 786 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
787 LocalTypePair ret_type = kLocalTypes[i]; 787 LocalTypePair ret_type = kLocalTypes[i];
788 const byte data[] = {SIG_ENTRY_x(ret_type.code)}; 788 const byte data[] = {SIG_ENTRY_x(ret_type.code)};
789 FunctionSig* sig = 789 FunctionSig* sig =
790 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 790 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
791 791
792 EXPECT_TRUE(sig != nullptr); 792 EXPECT_TRUE(sig != nullptr);
793 EXPECT_EQ(0, sig->parameter_count()); 793 EXPECT_EQ(0u, sig->parameter_count());
794 EXPECT_EQ(1, sig->return_count()); 794 EXPECT_EQ(1u, sig->return_count());
795 EXPECT_EQ(ret_type.type, sig->GetReturn()); 795 EXPECT_EQ(ret_type.type, sig->GetReturn());
796 } 796 }
797 } 797 }
798 798
799 TEST_F(WasmSignatureDecodeTest, Ok_v_t) { 799 TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
800 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 800 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
801 LocalTypePair param_type = kLocalTypes[i]; 801 LocalTypePair param_type = kLocalTypes[i];
802 const byte data[] = {SIG_ENTRY_v_x(param_type.code)}; 802 const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
803 FunctionSig* sig = 803 FunctionSig* sig =
804 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 804 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
805 805
806 EXPECT_TRUE(sig != nullptr); 806 EXPECT_TRUE(sig != nullptr);
807 EXPECT_EQ(1, sig->parameter_count()); 807 EXPECT_EQ(1u, sig->parameter_count());
808 EXPECT_EQ(0, sig->return_count()); 808 EXPECT_EQ(0u, sig->return_count());
809 EXPECT_EQ(param_type.type, sig->GetParam(0)); 809 EXPECT_EQ(param_type.type, sig->GetParam(0));
810 } 810 }
811 } 811 }
812 812
813 TEST_F(WasmSignatureDecodeTest, Ok_t_t) { 813 TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
814 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 814 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
815 LocalTypePair ret_type = kLocalTypes[i]; 815 LocalTypePair ret_type = kLocalTypes[i];
816 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 816 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
817 LocalTypePair param_type = kLocalTypes[j]; 817 LocalTypePair param_type = kLocalTypes[j];
818 const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)}; 818 const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
819 FunctionSig* sig = 819 FunctionSig* sig =
820 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 820 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
821 821
822 EXPECT_TRUE(sig != nullptr); 822 EXPECT_TRUE(sig != nullptr);
823 EXPECT_EQ(1, sig->parameter_count()); 823 EXPECT_EQ(1u, sig->parameter_count());
824 EXPECT_EQ(1, sig->return_count()); 824 EXPECT_EQ(1u, sig->return_count());
825 EXPECT_EQ(param_type.type, sig->GetParam(0)); 825 EXPECT_EQ(param_type.type, sig->GetParam(0));
826 EXPECT_EQ(ret_type.type, sig->GetReturn()); 826 EXPECT_EQ(ret_type.type, sig->GetReturn());
827 } 827 }
828 } 828 }
829 } 829 }
830 830
831 TEST_F(WasmSignatureDecodeTest, Ok_i_tt) { 831 TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
832 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 832 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
833 LocalTypePair p0_type = kLocalTypes[i]; 833 LocalTypePair p0_type = kLocalTypes[i];
834 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 834 for (size_t j = 0; j < arraysize(kLocalTypes); j++) {
835 LocalTypePair p1_type = kLocalTypes[j]; 835 LocalTypePair p1_type = kLocalTypes[j];
836 const byte data[] = { 836 const byte data[] = {
837 SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)}; 837 SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)};
838 FunctionSig* sig = 838 FunctionSig* sig =
839 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 839 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
840 840
841 EXPECT_TRUE(sig != nullptr); 841 EXPECT_TRUE(sig != nullptr);
842 EXPECT_EQ(2, sig->parameter_count()); 842 EXPECT_EQ(2u, sig->parameter_count());
843 EXPECT_EQ(1, sig->return_count()); 843 EXPECT_EQ(1u, sig->return_count());
844 EXPECT_EQ(p0_type.type, sig->GetParam(0)); 844 EXPECT_EQ(p0_type.type, sig->GetParam(0));
845 EXPECT_EQ(p1_type.type, sig->GetParam(1)); 845 EXPECT_EQ(p1_type.type, sig->GetParam(1));
846 } 846 }
847 } 847 }
848 } 848 }
849 849
850 TEST_F(WasmSignatureDecodeTest, Fail_off_end) { 850 TEST_F(WasmSignatureDecodeTest, Fail_off_end) {
851 byte data[256]; 851 byte data[256];
852 for (int p = 0; p <= 255; p = p + 1 + p * 3) { 852 for (int p = 0; p <= 255; p = p + 1 + p * 3) {
853 for (int i = 0; i <= p; i++) data[i] = kLocalI32; 853 for (int i = 0; i <= p; i++) data[i] = kLocalI32;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 kLocalF64, // -- 909 kLocalF64, // --
910 kExprNop // body 910 kExprNop // body
911 }; 911 };
912 912
913 FunctionResult result = 913 FunctionResult result =
914 DecodeWasmFunction(isolate(), zone(), nullptr, data, data + sizeof(data)); 914 DecodeWasmFunction(isolate(), zone(), nullptr, data, data + sizeof(data));
915 EXPECT_OK(result); 915 EXPECT_OK(result);
916 916
917 if (result.val && result.ok()) { 917 if (result.val && result.ok()) {
918 WasmFunction* function = result.val; 918 WasmFunction* function = result.val;
919 EXPECT_EQ(0, function->sig->parameter_count()); 919 EXPECT_EQ(0u, function->sig->parameter_count());
920 EXPECT_EQ(0, function->sig->return_count()); 920 EXPECT_EQ(0u, function->sig->return_count());
921 EXPECT_EQ(0, function->name_offset); 921 EXPECT_EQ(0u, function->name_offset);
922 EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset); 922 EXPECT_EQ(static_cast<uint32_t>(SIZEOF_SIG_ENTRY_v_v),
923 function->code_start_offset);
923 EXPECT_EQ(sizeof(data), function->code_end_offset); 924 EXPECT_EQ(sizeof(data), function->code_end_offset);
924 // TODO(titzer): verify encoding of local declarations 925 // TODO(titzer): verify encoding of local declarations
925 } 926 }
926 927
927 if (result.val) delete result.val; 928 if (result.val) delete result.val;
928 } 929 }
929 930
930 TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) { 931 TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) {
931 const byte data[] = {1}; 932 const byte data[] = {1};
932 EXPECT_FAILURE(data); 933 EXPECT_FAILURE(data);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 0, // one byte section 1015 0, // one byte section
1015 SECTION(Global, 6), 1016 SECTION(Global, 6),
1016 1, 1017 1,
1017 kLocalI32, // memory type 1018 kLocalI32, // memory type
1018 0, // exported 1019 0, // exported
1019 WASM_INIT_EXPR_I32V_1(33), // init 1020 WASM_INIT_EXPR_I32V_1(33), // init
1020 }; 1021 };
1021 ModuleResult result = DecodeModule(data, data + sizeof(data)); 1022 ModuleResult result = DecodeModule(data, data + sizeof(data));
1022 EXPECT_OK(result); 1023 EXPECT_OK(result);
1023 1024
1024 EXPECT_EQ(1, result.val->globals.size()); 1025 EXPECT_EQ(1u, result.val->globals.size());
1025 EXPECT_EQ(0, result.val->functions.size()); 1026 EXPECT_EQ(0u, result.val->functions.size());
1026 EXPECT_EQ(0, result.val->data_segments.size()); 1027 EXPECT_EQ(0u, result.val->data_segments.size());
1027 1028
1028 const WasmGlobal* global = &result.val->globals.back(); 1029 const WasmGlobal* global = &result.val->globals.back();
1029 1030
1030 EXPECT_EQ(kAstI32, global->type); 1031 EXPECT_EQ(kAstI32, global->type);
1031 EXPECT_EQ(0, global->offset); 1032 EXPECT_EQ(0u, global->offset);
1032 1033
1033 if (result.val) delete result.val; 1034 if (result.val) delete result.val;
1034 } 1035 }
1035 1036
1036 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { 1037 TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
1037 static const byte data[] = {SECTION(Type, 1), 0, SECTION(Import, 1), 0}; 1038 static const byte data[] = {SECTION(Type, 1), 0, SECTION(Import, 1), 0};
1038 EXPECT_VERIFIES(data); 1039 EXPECT_VERIFIES(data);
1039 } 1040 }
1040 1041
1041 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs1) { 1042 TEST_F(WasmModuleVerifyTest, ImportTable_nosigs1) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
1148 TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { 1149 TEST_F(WasmModuleVerifyTest, ExportTable_empty1) {
1149 static const byte data[] = { // signatures 1150 static const byte data[] = { // signatures
1150 SIGNATURES_SECTION_VOID_VOID, // -- 1151 SIGNATURES_SECTION_VOID_VOID, // --
1151 ONE_EMPTY_FUNCTION, SECTION(Export, 1), // -- 1152 ONE_EMPTY_FUNCTION, SECTION(Export, 1), // --
1152 0, // -- 1153 0, // --
1153 ONE_EMPTY_BODY}; 1154 ONE_EMPTY_BODY};
1154 1155
1155 ModuleResult result = DecodeModule(data, data + sizeof(data)); 1156 ModuleResult result = DecodeModule(data, data + sizeof(data));
1156 EXPECT_OK(result); 1157 EXPECT_OK(result);
1157 1158
1158 EXPECT_EQ(1, result.val->functions.size()); 1159 EXPECT_EQ(1u, result.val->functions.size());
1159 EXPECT_EQ(0, result.val->export_table.size()); 1160 EXPECT_EQ(0u, result.val->export_table.size());
1160 1161
1161 if (result.val) delete result.val; 1162 if (result.val) delete result.val;
1162 } 1163 }
1163 1164
1164 TEST_F(WasmModuleVerifyTest, ExportTable_empty2) { 1165 TEST_F(WasmModuleVerifyTest, ExportTable_empty2) {
1165 static const byte data[] = { 1166 static const byte data[] = {
1166 SECTION(Type, 1), 0, SECTION(Export, 1), 0 // -- 1167 SECTION(Type, 1), 0, SECTION(Export, 1), 0 // --
1167 }; 1168 };
1168 EXPECT_VERIFIES(data); 1169 EXPECT_VERIFIES(data);
1169 } 1170 }
1170 1171
1171 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) { 1172 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) {
1172 static const byte data[] = {SECTION(Export, 1), 0}; 1173 static const byte data[] = {SECTION(Export, 1), 0};
1173 EXPECT_VERIFIES(data); 1174 EXPECT_VERIFIES(data);
1174 } 1175 }
1175 1176
1176 TEST_F(WasmModuleVerifyTest, ExportTableOne) { 1177 TEST_F(WasmModuleVerifyTest, ExportTableOne) {
1177 static const byte data[] = {// signatures 1178 static const byte data[] = {// signatures
1178 SIGNATURES_SECTION_VOID_VOID, 1179 SIGNATURES_SECTION_VOID_VOID,
1179 ONE_EMPTY_FUNCTION, 1180 ONE_EMPTY_FUNCTION,
1180 SECTION(Export, 4), 1181 SECTION(Export, 4),
1181 1, // exports 1182 1, // exports
1182 NO_NAME, // -- 1183 NO_NAME, // --
1183 kExternalFunction, // -- 1184 kExternalFunction, // --
1184 FUNC_INDEX(0), // -- 1185 FUNC_INDEX(0), // --
1185 ONE_EMPTY_BODY}; 1186 ONE_EMPTY_BODY};
1186 ModuleResult result = DecodeModule(data, data + sizeof(data)); 1187 ModuleResult result = DecodeModule(data, data + sizeof(data));
1187 EXPECT_OK(result); 1188 EXPECT_OK(result);
1188 1189
1189 EXPECT_EQ(1, result.val->functions.size()); 1190 EXPECT_EQ(1u, result.val->functions.size());
1190 EXPECT_EQ(1, result.val->export_table.size()); 1191 EXPECT_EQ(1u, result.val->export_table.size());
1191 1192
1192 if (result.val) delete result.val; 1193 if (result.val) delete result.val;
1193 } 1194 }
1194 1195
1195 TEST_F(WasmModuleVerifyTest, ExportNameWithInvalidStringLength) { 1196 TEST_F(WasmModuleVerifyTest, ExportNameWithInvalidStringLength) {
1196 static const byte data[] = {// signatures 1197 static const byte data[] = {// signatures
1197 SIGNATURES_SECTION_VOID_VOID, 1198 SIGNATURES_SECTION_VOID_VOID,
1198 ONE_EMPTY_FUNCTION, 1199 ONE_EMPTY_FUNCTION,
1199 SECTION(Export, 12), 1200 SECTION(Export, 12),
1200 1, // exports 1201 1, // exports
(...skipping 22 matching lines...) Expand all
1223 'n', 1224 'n',
1224 'o', 1225 'o',
1225 'm', // -- 1226 'm', // --
1226 kExternalFunction, // -- 1227 kExternalFunction, // --
1227 FUNC_INDEX(0), // -- 1228 FUNC_INDEX(0), // --
1228 ONE_EMPTY_BODY}; 1229 ONE_EMPTY_BODY};
1229 1230
1230 ModuleResult result = DecodeModule(data, data + sizeof(data)); 1231 ModuleResult result = DecodeModule(data, data + sizeof(data));
1231 EXPECT_OK(result); 1232 EXPECT_OK(result);
1232 1233
1233 EXPECT_EQ(1, result.val->functions.size()); 1234 EXPECT_EQ(1u, result.val->functions.size());
1234 EXPECT_EQ(2, result.val->export_table.size()); 1235 EXPECT_EQ(2u, result.val->export_table.size());
1235 1236
1236 if (result.val) delete result.val; 1237 if (result.val) delete result.val;
1237 } 1238 }
1238 1239
1239 TEST_F(WasmModuleVerifyTest, ExportTableThree) { 1240 TEST_F(WasmModuleVerifyTest, ExportTableThree) {
1240 static const byte data[] = {// signatures 1241 static const byte data[] = {// signatures
1241 SIGNATURES_SECTION_VOID_VOID, 1242 SIGNATURES_SECTION_VOID_VOID,
1242 THREE_EMPTY_FUNCTIONS, 1243 THREE_EMPTY_FUNCTIONS,
1243 SECTION(Export, 13), 1244 SECTION(Export, 13),
1244 3, // exports 1245 3, // exports
1245 NAME_LENGTH(1), 1246 NAME_LENGTH(1),
1246 'a', // -- 1247 'a', // --
1247 kExternalFunction, 1248 kExternalFunction,
1248 FUNC_INDEX(0), // -- 1249 FUNC_INDEX(0), // --
1249 NAME_LENGTH(1), 1250 NAME_LENGTH(1),
1250 'b', // -- 1251 'b', // --
1251 kExternalFunction, 1252 kExternalFunction,
1252 FUNC_INDEX(1), // -- 1253 FUNC_INDEX(1), // --
1253 NAME_LENGTH(1), 1254 NAME_LENGTH(1),
1254 'c', // -- 1255 'c', // --
1255 kExternalFunction, 1256 kExternalFunction,
1256 FUNC_INDEX(2), // -- 1257 FUNC_INDEX(2), // --
1257 THREE_EMPTY_BODIES}; 1258 THREE_EMPTY_BODIES};
1258 ModuleResult result = DecodeModule(data, data + sizeof(data)); 1259 ModuleResult result = DecodeModule(data, data + sizeof(data));
1259 EXPECT_OK(result); 1260 EXPECT_OK(result);
1260 1261
1261 EXPECT_EQ(3, result.val->functions.size()); 1262 EXPECT_EQ(3u, result.val->functions.size());
1262 EXPECT_EQ(3, result.val->export_table.size()); 1263 EXPECT_EQ(3u, result.val->export_table.size());
1263 1264
1264 if (result.val) delete result.val; 1265 if (result.val) delete result.val;
1265 } 1266 }
1266 1267
1267 TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) { 1268 TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) {
1268 for (int i = 0; i < 6; i++) { 1269 for (int i = 0; i < 6; i++) {
1269 const byte data[] = {// signatures 1270 const byte data[] = {// signatures
1270 SIGNATURES_SECTION_VOID_VOID, 1271 SIGNATURES_SECTION_VOID_VOID,
1271 THREE_EMPTY_FUNCTIONS, 1272 THREE_EMPTY_FUNCTIONS,
1272 SECTION(Export, 6), 1273 SECTION(Export, 6),
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1477 SECTION(Unknown, 4), 1, 'X', 17, 18, // -- 1478 SECTION(Unknown, 4), 1, 'X', 17, 18, // --
1478 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // -- 1479 SECTION(Unknown, 9), 3, 'f', 'o', 'o', 5, 6, 7, 8, 9, // --
1479 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // -- 1480 SECTION(Unknown, 8), 5, 'o', 't', 'h', 'e', 'r', 7, 8, // --
1480 }; 1481 };
1481 EXPECT_VERIFIES(data); 1482 EXPECT_VERIFIES(data);
1482 } 1483 }
1483 1484
1484 } // namespace wasm 1485 } // namespace wasm
1485 } // namespace internal 1486 } // namespace internal
1486 } // namespace v8 1487 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/wasm/leb-helper-unittest.cc ('k') | test/unittests/wasm/wasm-macro-gen-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698