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

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

Issue 1775873002: [Wasm] Convert many of the fixed-size values to LEB128. (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix windows 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/unittests/wasm/encoder-unittest.cc ('k') | test/unittests/wasm/wasm-macro-gen-unittest.cc » ('j') | 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 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 EXPECT_VERIFIES(data); 674 EXPECT_VERIFIES(data);
675 } else { 675 } else {
676 EXPECT_FAILURE(data); 676 EXPECT_FAILURE(data);
677 } 677 }
678 } 678 }
679 } 679 }
680 } 680 }
681 681
682 682
683 // To make below tests for indirect calls much shorter. 683 // To make below tests for indirect calls much shorter.
684 #define FUNCTION(sig_index, external) \ 684 #define FUNCTION(sig_index, external) kDeclFunctionImport, SIG_INDEX(sig_index)
685 kDeclFunctionImport, static_cast<byte>(sig_index), \
686 static_cast<byte>(sig_index >> 8)
687
688 685
689 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { 686 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) {
690 static const byte data[] = { 687 static const byte data[] = {
691 // sig#0 ------------------------------------------------------- 688 // sig#0 -------------------------------------------------------
692 kDeclSignatures, 1, 0, 0, // void -> void 689 kDeclSignatures, 1, 0, 0, // void -> void
693 // func#0 ------------------------------------------------------ 690 // func#0 ------------------------------------------------------
694 kDeclFunctions, 1, FUNCTION(0, 0), 691 kDeclFunctions, 1, FUNCTION(0, 0),
695 // indirect table ---------------------------------------------- 692 // indirect table ----------------------------------------------
696 kDeclFunctionTable, 1, 0, 0}; 693 kDeclFunctionTable, 1, U32V_1(0)};
697 694
698 ModuleResult result = DecodeModule(data, data + arraysize(data)); 695 ModuleResult result = DecodeModule(data, data + arraysize(data));
699 EXPECT_TRUE(result.ok()); 696 EXPECT_TRUE(result.ok());
700 if (result.ok()) { 697 if (result.ok()) {
701 EXPECT_EQ(1, result.val->signatures.size()); 698 EXPECT_EQ(1, result.val->signatures.size());
702 EXPECT_EQ(1, result.val->functions.size()); 699 EXPECT_EQ(1, result.val->functions.size());
703 EXPECT_EQ(1, result.val->function_table.size()); 700 EXPECT_EQ(1, result.val->function_table.size());
704 EXPECT_EQ(0, result.val->function_table[0]); 701 EXPECT_EQ(0, result.val->function_table[0]);
705 } 702 }
706 if (result.val) delete result.val; 703 if (result.val) delete result.val;
707 } 704 }
708 705
709 706
710 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { 707 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) {
711 static const byte data[] = { 708 static const byte data[] = {
712 // sig#0 ------------------------------------------------------- 709 // sig#0 -------------------------------------------------------
713 kDeclSignatures, 2, 0, 0, // void -> void 710 kDeclSignatures, 2, 0, 0, // void -> void
714 0, kLocalI32, // void -> i32 711 0, kLocalI32, // void -> i32
715 // func#0 ------------------------------------------------------ 712 // func#0 ------------------------------------------------------
716 kDeclFunctions, 4, FUNCTION(0, 1), // -- 713 kDeclFunctions, 4, FUNCTION(0, 1), // --
717 FUNCTION(1, 1), // -- 714 FUNCTION(1, 1), // --
718 FUNCTION(0, 1), // -- 715 FUNCTION(0, 1), // --
719 FUNCTION(1, 1), // -- 716 FUNCTION(1, 1), // --
720 // indirect table ---------------------------------------------- 717 // indirect table ----------------------------------------------
721 kDeclFunctionTable, 8, 718 kDeclFunctionTable, 8,
722 U16_LE(0), // -- 719 U32V_1(0), // --
723 U16_LE(1), // -- 720 U32V_1(1), // --
724 U16_LE(2), // -- 721 U32V_1(2), // --
725 U16_LE(3), // -- 722 U32V_1(3), // --
726 U16_LE(0), // -- 723 U32V_1(0), // --
727 U16_LE(1), // -- 724 U32V_1(1), // --
728 U16_LE(2), // -- 725 U32V_1(2), // --
729 U16_LE(3), // -- 726 U32V_1(3), // --
730 }; 727 };
731 728
732 ModuleResult result = DecodeModule(data, data + arraysize(data)); 729 ModuleResult result = DecodeModule(data, data + arraysize(data));
733 EXPECT_TRUE(result.ok()); 730 EXPECT_TRUE(result.ok());
734 if (result.ok()) { 731 if (result.ok()) {
735 EXPECT_EQ(2, result.val->signatures.size()); 732 EXPECT_EQ(2, result.val->signatures.size());
736 EXPECT_EQ(4, result.val->functions.size()); 733 EXPECT_EQ(4, result.val->functions.size());
737 EXPECT_EQ(8, result.val->function_table.size()); 734 EXPECT_EQ(8, result.val->function_table.size());
738 for (int i = 0; i < 8; i++) { 735 for (int i = 0; i < 8; i++) {
739 EXPECT_EQ(i & 3, result.val->function_table[i]); 736 EXPECT_EQ(i & 3, result.val->function_table[i]);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 EXPECT_FAILURE(data); 1077 EXPECT_FAILURE(data);
1081 } 1078 }
1082 1079
1083 TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) { 1080 TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) {
1084 static const byte data[] = { 1081 static const byte data[] = {
1085 kDeclSignatures, 1082 kDeclSignatures,
1086 1, 1083 1,
1087 VOID_VOID_SIG, 1084 VOID_VOID_SIG,
1088 kDeclImportTable, 1085 kDeclImportTable,
1089 1, // -- 1086 1, // --
1090 SIG_INDEX(0), // sig index 1087 U32V_1(0), // sig index
1091 NAME_OFFSET(1), // module name 1088 NAME_OFFSET(1), // module name
1092 NAME_OFFSET(1) // function name 1089 NAME_OFFSET(1) // function name
1093 }; 1090 };
1094 EXPECT_VERIFIES(data); 1091 EXPECT_VERIFIES(data);
1095 } 1092 }
1096 1093
1097 TEST_F(WasmModuleVerifyTest, ImportTable_invalid_module) { 1094 TEST_F(WasmModuleVerifyTest, ImportTable_invalid_module) {
1098 static const byte data[] = { 1095 static const byte data[] = {
1099 kDeclSignatures, 1096 kDeclSignatures,
1100 1, 1097 1,
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 for (int length = 13; length < sizeof(data); length++) { 1215 for (int length = 13; length < sizeof(data); length++) {
1219 ModuleResult result = DecodeModule(data, data + length); 1216 ModuleResult result = DecodeModule(data, data + length);
1220 EXPECT_FALSE(result.ok()); 1217 EXPECT_FALSE(result.ok());
1221 if (result.val) delete result.val; 1218 if (result.val) delete result.val;
1222 } 1219 }
1223 } 1220 }
1224 1221
1225 } // namespace wasm 1222 } // namespace wasm
1226 } // namespace internal 1223 } // namespace internal
1227 } // namespace v8 1224 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/wasm/encoder-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