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

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

Issue 2594993002: [wasm] Rename wasm::LocalType to wasm::ValueType and kAst* to kWasm* (Closed)
Patch Set: Fix inspector tests Created 4 years 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-limits.h" 10 #include "src/wasm/wasm-limits.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 static size_t SizeOfVarInt(size_t value) { 120 static size_t SizeOfVarInt(size_t value) {
121 size_t size = 0; 121 size_t size = 0;
122 do { 122 do {
123 size++; 123 size++;
124 value = value >> 7; 124 value = value >> 7;
125 } while (value > 0); 125 } while (value > 0);
126 return size; 126 return size;
127 } 127 }
128 128
129 struct LocalTypePair { 129 struct ValueTypePair {
130 uint8_t code; 130 uint8_t code;
131 LocalType type; 131 ValueType type;
132 } kLocalTypes[] = {{kLocalI32, kAstI32}, 132 } kValueTypes[] = {{kLocalI32, kWasmI32},
133 {kLocalI64, kAstI64}, 133 {kLocalI64, kWasmI64},
134 {kLocalF32, kAstF32}, 134 {kLocalF32, kWasmF32},
135 {kLocalF64, kAstF64}}; 135 {kLocalF64, kWasmF64}};
136 136
137 class WasmModuleVerifyTest : public TestWithIsolateAndZone { 137 class WasmModuleVerifyTest : public TestWithIsolateAndZone {
138 public: 138 public:
139 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { 139 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) {
140 // Add the WASM magic and version number automatically. 140 // Add the WASM magic and version number automatically.
141 size_t size = static_cast<size_t>(module_end - module_start); 141 size_t size = static_cast<size_t>(module_end - module_start);
142 byte header[] = {WASM_MODULE_HEADER}; 142 byte header[] = {WASM_MODULE_HEADER};
143 size_t total = sizeof(header) + size; 143 size_t total = sizeof(header) + size;
144 auto temp = new byte[total]; 144 auto temp = new byte[total];
145 memcpy(temp, header, sizeof(header)); 145 memcpy(temp, header, sizeof(header));
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 { 192 {
193 // Should decode to exactly one global. 193 // Should decode to exactly one global.
194 ModuleResult result = DecodeModule(data, data + sizeof(data)); 194 ModuleResult result = DecodeModule(data, data + sizeof(data));
195 EXPECT_OK(result); 195 EXPECT_OK(result);
196 EXPECT_EQ(1u, result.val->globals.size()); 196 EXPECT_EQ(1u, result.val->globals.size());
197 EXPECT_EQ(0u, result.val->functions.size()); 197 EXPECT_EQ(0u, result.val->functions.size());
198 EXPECT_EQ(0u, result.val->data_segments.size()); 198 EXPECT_EQ(0u, result.val->data_segments.size());
199 199
200 const WasmGlobal* global = &result.val->globals.back(); 200 const WasmGlobal* global = &result.val->globals.back();
201 201
202 EXPECT_EQ(kAstI32, global->type); 202 EXPECT_EQ(kWasmI32, global->type);
203 EXPECT_EQ(0u, global->offset); 203 EXPECT_EQ(0u, global->offset);
204 EXPECT_FALSE(global->mutability); 204 EXPECT_FALSE(global->mutability);
205 EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind); 205 EXPECT_EQ(WasmInitExpr::kI32Const, global->init.kind);
206 EXPECT_EQ(13, global->init.val.i32_const); 206 EXPECT_EQ(13, global->init.val.i32_const);
207 207
208 if (result.val) delete result.val; 208 if (result.val) delete result.val;
209 } 209 }
210 210
211 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); 211 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
212 } 212 }
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 { 353 {
354 // Should decode to exactly two globals. 354 // Should decode to exactly two globals.
355 ModuleResult result = DecodeModule(data, data + sizeof(data)); 355 ModuleResult result = DecodeModule(data, data + sizeof(data));
356 EXPECT_OK(result); 356 EXPECT_OK(result);
357 EXPECT_EQ(2u, result.val->globals.size()); 357 EXPECT_EQ(2u, result.val->globals.size());
358 EXPECT_EQ(0u, result.val->functions.size()); 358 EXPECT_EQ(0u, result.val->functions.size());
359 EXPECT_EQ(0u, result.val->data_segments.size()); 359 EXPECT_EQ(0u, result.val->data_segments.size());
360 360
361 const WasmGlobal* g0 = &result.val->globals[0]; 361 const WasmGlobal* g0 = &result.val->globals[0];
362 362
363 EXPECT_EQ(kAstF32, g0->type); 363 EXPECT_EQ(kWasmF32, g0->type);
364 EXPECT_EQ(0u, g0->offset); 364 EXPECT_EQ(0u, g0->offset);
365 EXPECT_FALSE(g0->mutability); 365 EXPECT_FALSE(g0->mutability);
366 EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind); 366 EXPECT_EQ(WasmInitExpr::kF32Const, g0->init.kind);
367 367
368 const WasmGlobal* g1 = &result.val->globals[1]; 368 const WasmGlobal* g1 = &result.val->globals[1];
369 369
370 EXPECT_EQ(kAstF64, g1->type); 370 EXPECT_EQ(kWasmF64, g1->type);
371 EXPECT_EQ(8u, g1->offset); 371 EXPECT_EQ(8u, g1->offset);
372 EXPECT_TRUE(g1->mutability); 372 EXPECT_TRUE(g1->mutability);
373 EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind); 373 EXPECT_EQ(WasmInitExpr::kF64Const, g1->init.kind);
374 374
375 if (result.val) delete result.val; 375 if (result.val) delete result.val;
376 } 376 }
377 377
378 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); 378 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data));
379 } 379 }
380 380
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 Zone zone(&allocator, ZONE_NAME); 777 Zone zone(&allocator, ZONE_NAME);
778 FunctionSig* sig = 778 FunctionSig* sig =
779 DecodeWasmSignatureForTesting(&zone, data, data + sizeof(data)); 779 DecodeWasmSignatureForTesting(&zone, data, data + sizeof(data));
780 780
781 EXPECT_TRUE(sig != nullptr); 781 EXPECT_TRUE(sig != nullptr);
782 EXPECT_EQ(0u, sig->parameter_count()); 782 EXPECT_EQ(0u, sig->parameter_count());
783 EXPECT_EQ(0u, sig->return_count()); 783 EXPECT_EQ(0u, sig->return_count());
784 } 784 }
785 785
786 TEST_F(WasmSignatureDecodeTest, Ok_t_v) { 786 TEST_F(WasmSignatureDecodeTest, Ok_t_v) {
787 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 787 for (size_t i = 0; i < arraysize(kValueTypes); i++) {
788 LocalTypePair ret_type = kLocalTypes[i]; 788 ValueTypePair ret_type = kValueTypes[i];
789 const byte data[] = {SIG_ENTRY_x(ret_type.code)}; 789 const byte data[] = {SIG_ENTRY_x(ret_type.code)};
790 FunctionSig* sig = 790 FunctionSig* sig =
791 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 791 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
792 792
793 EXPECT_TRUE(sig != nullptr); 793 EXPECT_TRUE(sig != nullptr);
794 EXPECT_EQ(0u, sig->parameter_count()); 794 EXPECT_EQ(0u, sig->parameter_count());
795 EXPECT_EQ(1u, sig->return_count()); 795 EXPECT_EQ(1u, sig->return_count());
796 EXPECT_EQ(ret_type.type, sig->GetReturn()); 796 EXPECT_EQ(ret_type.type, sig->GetReturn());
797 } 797 }
798 } 798 }
799 799
800 TEST_F(WasmSignatureDecodeTest, Ok_v_t) { 800 TEST_F(WasmSignatureDecodeTest, Ok_v_t) {
801 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 801 for (size_t i = 0; i < arraysize(kValueTypes); i++) {
802 LocalTypePair param_type = kLocalTypes[i]; 802 ValueTypePair param_type = kValueTypes[i];
803 const byte data[] = {SIG_ENTRY_v_x(param_type.code)}; 803 const byte data[] = {SIG_ENTRY_v_x(param_type.code)};
804 FunctionSig* sig = 804 FunctionSig* sig =
805 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 805 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
806 806
807 EXPECT_TRUE(sig != nullptr); 807 EXPECT_TRUE(sig != nullptr);
808 EXPECT_EQ(1u, sig->parameter_count()); 808 EXPECT_EQ(1u, sig->parameter_count());
809 EXPECT_EQ(0u, sig->return_count()); 809 EXPECT_EQ(0u, sig->return_count());
810 EXPECT_EQ(param_type.type, sig->GetParam(0)); 810 EXPECT_EQ(param_type.type, sig->GetParam(0));
811 } 811 }
812 } 812 }
813 813
814 TEST_F(WasmSignatureDecodeTest, Ok_t_t) { 814 TEST_F(WasmSignatureDecodeTest, Ok_t_t) {
815 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 815 for (size_t i = 0; i < arraysize(kValueTypes); i++) {
816 LocalTypePair ret_type = kLocalTypes[i]; 816 ValueTypePair ret_type = kValueTypes[i];
817 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 817 for (size_t j = 0; j < arraysize(kValueTypes); j++) {
818 LocalTypePair param_type = kLocalTypes[j]; 818 ValueTypePair param_type = kValueTypes[j];
819 const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)}; 819 const byte data[] = {SIG_ENTRY_x_x(ret_type.code, param_type.code)};
820 FunctionSig* sig = 820 FunctionSig* sig =
821 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 821 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
822 822
823 EXPECT_TRUE(sig != nullptr); 823 EXPECT_TRUE(sig != nullptr);
824 EXPECT_EQ(1u, sig->parameter_count()); 824 EXPECT_EQ(1u, sig->parameter_count());
825 EXPECT_EQ(1u, sig->return_count()); 825 EXPECT_EQ(1u, sig->return_count());
826 EXPECT_EQ(param_type.type, sig->GetParam(0)); 826 EXPECT_EQ(param_type.type, sig->GetParam(0));
827 EXPECT_EQ(ret_type.type, sig->GetReturn()); 827 EXPECT_EQ(ret_type.type, sig->GetReturn());
828 } 828 }
829 } 829 }
830 } 830 }
831 831
832 TEST_F(WasmSignatureDecodeTest, Ok_i_tt) { 832 TEST_F(WasmSignatureDecodeTest, Ok_i_tt) {
833 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 833 for (size_t i = 0; i < arraysize(kValueTypes); i++) {
834 LocalTypePair p0_type = kLocalTypes[i]; 834 ValueTypePair p0_type = kValueTypes[i];
835 for (size_t j = 0; j < arraysize(kLocalTypes); j++) { 835 for (size_t j = 0; j < arraysize(kValueTypes); j++) {
836 LocalTypePair p1_type = kLocalTypes[j]; 836 ValueTypePair p1_type = kValueTypes[j];
837 const byte data[] = { 837 const byte data[] = {
838 SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)}; 838 SIG_ENTRY_x_xx(kLocalI32, p0_type.code, p1_type.code)};
839 FunctionSig* sig = 839 FunctionSig* sig =
840 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data)); 840 DecodeWasmSignatureForTesting(zone(), data, data + sizeof(data));
841 841
842 EXPECT_TRUE(sig != nullptr); 842 EXPECT_TRUE(sig != nullptr);
843 EXPECT_EQ(2u, sig->parameter_count()); 843 EXPECT_EQ(2u, sig->parameter_count());
844 EXPECT_EQ(1u, sig->return_count()); 844 EXPECT_EQ(1u, sig->return_count());
845 EXPECT_EQ(p0_type.type, sig->GetParam(0)); 845 EXPECT_EQ(p0_type.type, sig->GetParam(0));
846 EXPECT_EQ(p1_type.type, sig->GetParam(1)); 846 EXPECT_EQ(p1_type.type, sig->GetParam(1));
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1047 }; 1047 };
1048 ModuleResult result = DecodeModule(data, data + sizeof(data)); 1048 ModuleResult result = DecodeModule(data, data + sizeof(data));
1049 EXPECT_OK(result); 1049 EXPECT_OK(result);
1050 1050
1051 EXPECT_EQ(1u, result.val->globals.size()); 1051 EXPECT_EQ(1u, result.val->globals.size());
1052 EXPECT_EQ(0u, result.val->functions.size()); 1052 EXPECT_EQ(0u, result.val->functions.size());
1053 EXPECT_EQ(0u, result.val->data_segments.size()); 1053 EXPECT_EQ(0u, result.val->data_segments.size());
1054 1054
1055 const WasmGlobal* global = &result.val->globals.back(); 1055 const WasmGlobal* global = &result.val->globals.back();
1056 1056
1057 EXPECT_EQ(kAstI32, global->type); 1057 EXPECT_EQ(kWasmI32, global->type);
1058 EXPECT_EQ(0u, global->offset); 1058 EXPECT_EQ(0u, global->offset);
1059 1059
1060 if (result.val) delete result.val; 1060 if (result.val) delete result.val;
1061 } 1061 }
1062 1062
1063 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { 1063 TEST_F(WasmModuleVerifyTest, ImportTable_empty) {
1064 static const byte data[] = {SECTION(Type, 1), 0, SECTION(Import, 1), 0}; 1064 static const byte data[] = {SECTION(Type, 1), 0, SECTION(Import, 1), 0};
1065 EXPECT_VERIFIES(data); 1065 EXPECT_VERIFIES(data);
1066 } 1066 }
1067 1067
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 } // namespace wasm 1511 } // namespace wasm
1512 } // namespace internal 1512 } // namespace internal
1513 } // namespace v8 1513 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/wasm/function-body-decoder-unittest.cc ('k') | test/unittests/wasm/wasm-module-builder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698