OLD | NEW |
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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 TEST_F(WasmModuleVerifyTest, DecodeEmpty) { | 170 TEST_F(WasmModuleVerifyTest, DecodeEmpty) { |
171 static const byte data[] = {SECTION(END, 0)}; | 171 static const byte data[] = {SECTION(END, 0)}; |
172 EXPECT_VERIFIES(data); | 172 EXPECT_VERIFIES(data); |
173 } | 173 } |
174 | 174 |
175 TEST_F(WasmModuleVerifyTest, OneGlobal) { | 175 TEST_F(WasmModuleVerifyTest, OneGlobal) { |
176 static const byte data[] = { | 176 static const byte data[] = { |
177 SECTION(GLOBALS, 5), // -- | 177 SECTION(GLOBALS, 5), // -- |
178 1, | 178 1, |
179 NAME_LENGTH(1), | 179 NAME_LENGTH(1), |
180 'g', // name | 180 'g', // name |
181 kMemI32, // memory type | 181 kLocalI32, // local type |
182 0, // exported | 182 0, // exported |
183 }; | 183 }; |
184 | 184 |
185 { | 185 { |
186 // Should decode to exactly one global. | 186 // Should decode to exactly one global. |
187 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 187 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
188 EXPECT_OK(result); | 188 EXPECT_OK(result); |
189 EXPECT_EQ(1, result.val->globals.size()); | 189 EXPECT_EQ(1, result.val->globals.size()); |
190 EXPECT_EQ(0, result.val->functions.size()); | 190 EXPECT_EQ(0, result.val->functions.size()); |
191 EXPECT_EQ(0, result.val->data_segments.size()); | 191 EXPECT_EQ(0, result.val->data_segments.size()); |
192 | 192 |
193 const WasmGlobal* global = &result.val->globals.back(); | 193 const WasmGlobal* global = &result.val->globals.back(); |
194 | 194 |
195 EXPECT_EQ(1, global->name_length); | 195 EXPECT_EQ(1, global->name_length); |
196 EXPECT_EQ(MachineType::Int32(), global->type); | 196 EXPECT_EQ(kAstI32, global->type); |
197 EXPECT_EQ(0, global->offset); | 197 EXPECT_EQ(0, global->offset); |
198 EXPECT_FALSE(global->exported); | 198 EXPECT_FALSE(global->exported); |
199 | 199 |
200 if (result.val) delete result.val; | 200 if (result.val) delete result.val; |
201 } | 201 } |
202 | 202 |
203 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); | 203 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); |
204 } | 204 } |
205 | 205 |
206 TEST_F(WasmModuleVerifyTest, Global_invalid_type) { | 206 TEST_F(WasmModuleVerifyTest, Global_invalid_type) { |
(...skipping 30 matching lines...) Expand all Loading... |
237 val = next; | 237 val = next; |
238 } else { | 238 } else { |
239 buffer.push_back(static_cast<byte>(out)); | 239 buffer.push_back(static_cast<byte>(out)); |
240 break; | 240 break; |
241 } | 241 } |
242 } | 242 } |
243 } | 243 } |
244 | 244 |
245 TEST_F(WasmModuleVerifyTest, NGlobals) { | 245 TEST_F(WasmModuleVerifyTest, NGlobals) { |
246 static const byte data[] = { | 246 static const byte data[] = { |
247 NO_NAME, // name length | 247 NO_NAME, // name length |
248 kMemI32, // memory type | 248 kLocalF32, // memory type |
249 0, // exported | 249 0, // exported |
250 }; | 250 }; |
251 | 251 |
252 for (uint32_t i = 0; i < 1000000; i = i * 13 + 1) { | 252 for (uint32_t i = 0; i < 1000000; i = i * 13 + 1) { |
253 std::vector<byte> buffer; | 253 std::vector<byte> buffer; |
254 size_t size = SizeOfVarInt(i) + i * sizeof(data); | 254 size_t size = SizeOfVarInt(i) + i * sizeof(data); |
255 const byte globals[] = {WASM_SECTION_GLOBALS, U32V_5(size)}; | 255 const byte globals[] = {WASM_SECTION_GLOBALS, U32V_5(size)}; |
256 for (size_t g = 0; g != sizeof(globals); ++g) { | 256 for (size_t g = 0; g != sizeof(globals); ++g) { |
257 buffer.push_back(globals[g]); | 257 buffer.push_back(globals[g]); |
258 } | 258 } |
259 AppendUint32v(buffer, i); // Number of globals. | 259 AppendUint32v(buffer, i); // Number of globals. |
(...skipping 28 matching lines...) Expand all Loading... |
288 0, // exported | 288 0, // exported |
289 }; | 289 }; |
290 | 290 |
291 EXPECT_FAILURE(data); | 291 EXPECT_FAILURE(data); |
292 } | 292 } |
293 | 293 |
294 TEST_F(WasmModuleVerifyTest, TwoGlobals) { | 294 TEST_F(WasmModuleVerifyTest, TwoGlobals) { |
295 static const byte data[] = { | 295 static const byte data[] = { |
296 SECTION(GLOBALS, 7), | 296 SECTION(GLOBALS, 7), |
297 2, | 297 2, |
298 NO_NAME, // #0: name length | 298 NO_NAME, // #0: name length |
299 kMemF32, // memory type | 299 kLocalF32, // type |
300 0, // exported | 300 0, // exported |
301 NO_NAME, // #1: name length | 301 NO_NAME, // #1: name length |
302 kMemF64, // memory type | 302 kLocalF64, // type |
303 1, // exported | 303 1, // exported |
304 }; | 304 }; |
305 | 305 |
306 { | 306 { |
307 // Should decode to exactly two globals. | 307 // Should decode to exactly two globals. |
308 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 308 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
309 EXPECT_OK(result); | 309 EXPECT_OK(result); |
310 EXPECT_EQ(2, result.val->globals.size()); | 310 EXPECT_EQ(2, result.val->globals.size()); |
311 EXPECT_EQ(0, result.val->functions.size()); | 311 EXPECT_EQ(0, result.val->functions.size()); |
312 EXPECT_EQ(0, result.val->data_segments.size()); | 312 EXPECT_EQ(0, result.val->data_segments.size()); |
313 | 313 |
314 const WasmGlobal* g0 = &result.val->globals[0]; | 314 const WasmGlobal* g0 = &result.val->globals[0]; |
315 const WasmGlobal* g1 = &result.val->globals[1]; | 315 const WasmGlobal* g1 = &result.val->globals[1]; |
316 | 316 |
317 EXPECT_EQ(0, g0->name_length); | 317 EXPECT_EQ(0, g0->name_length); |
318 EXPECT_EQ(MachineType::Float32(), g0->type); | 318 EXPECT_EQ(kAstF32, g0->type); |
319 EXPECT_EQ(0, g0->offset); | 319 EXPECT_EQ(0, g0->offset); |
320 EXPECT_FALSE(g0->exported); | 320 EXPECT_FALSE(g0->exported); |
321 | 321 |
322 EXPECT_EQ(0, g1->name_length); | 322 EXPECT_EQ(0, g1->name_length); |
323 EXPECT_EQ(MachineType::Float64(), g1->type); | 323 EXPECT_EQ(kAstF64, g1->type); |
324 EXPECT_EQ(8, g1->offset); | 324 EXPECT_EQ(8, g1->offset); |
325 EXPECT_TRUE(g1->exported); | 325 EXPECT_TRUE(g1->exported); |
326 | 326 |
327 if (result.val) delete result.val; | 327 if (result.val) delete result.val; |
328 } | 328 } |
329 | 329 |
330 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); | 330 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); |
331 } | 331 } |
332 | 332 |
333 TEST_F(WasmModuleVerifyTest, OneSignature) { | 333 TEST_F(WasmModuleVerifyTest, OneSignature) { |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
850 EXPECT_FAILURE(data); | 850 EXPECT_FAILURE(data); |
851 } | 851 } |
852 | 852 |
853 TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) { | 853 TEST_F(WasmModuleVerifyTest, UnknownSectionSkipped) { |
854 static const byte data[] = { | 854 static const byte data[] = { |
855 UNKNOWN_EMPTY_SECTION_NAME, | 855 UNKNOWN_EMPTY_SECTION_NAME, |
856 1, // section size | 856 1, // section size |
857 0, // one byte section | 857 0, // one byte section |
858 SECTION(GLOBALS, 4), | 858 SECTION(GLOBALS, 4), |
859 1, | 859 1, |
860 0, // name length | 860 0, // name length |
861 kMemI32, // memory type | 861 kLocalI32, // memory type |
862 0, // exported | 862 0, // exported |
863 }; | 863 }; |
864 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 864 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
865 EXPECT_OK(result); | 865 EXPECT_OK(result); |
866 | 866 |
867 EXPECT_EQ(1, result.val->globals.size()); | 867 EXPECT_EQ(1, result.val->globals.size()); |
868 EXPECT_EQ(0, result.val->functions.size()); | 868 EXPECT_EQ(0, result.val->functions.size()); |
869 EXPECT_EQ(0, result.val->data_segments.size()); | 869 EXPECT_EQ(0, result.val->data_segments.size()); |
870 | 870 |
871 const WasmGlobal* global = &result.val->globals.back(); | 871 const WasmGlobal* global = &result.val->globals.back(); |
872 | 872 |
873 EXPECT_EQ(0, global->name_length); | 873 EXPECT_EQ(0, global->name_length); |
874 EXPECT_EQ(MachineType::Int32(), global->type); | 874 EXPECT_EQ(kAstI32, global->type); |
875 EXPECT_EQ(0, global->offset); | 875 EXPECT_EQ(0, global->offset); |
876 EXPECT_FALSE(global->exported); | 876 EXPECT_FALSE(global->exported); |
877 | 877 |
878 if (result.val) delete result.val; | 878 if (result.val) delete result.val; |
879 } | 879 } |
880 | 880 |
881 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { | 881 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { |
882 static const byte data[] = {SECTION(SIGNATURES, 1), 0, | 882 static const byte data[] = {SECTION(SIGNATURES, 1), 0, |
883 SECTION(IMPORT_TABLE, 1), 0}; | 883 SECTION(IMPORT_TABLE, 1), 0}; |
884 EXPECT_VERIFIES(data); | 884 EXPECT_VERIFIES(data); |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 NO_LOCAL_NAMES, // -- | 1202 NO_LOCAL_NAMES, // -- |
1203 FOO_STRING, | 1203 FOO_STRING, |
1204 NO_LOCAL_NAMES, // -- | 1204 NO_LOCAL_NAMES, // -- |
1205 }; | 1205 }; |
1206 EXPECT_VERIFIES(data); | 1206 EXPECT_VERIFIES(data); |
1207 } | 1207 } |
1208 | 1208 |
1209 } // namespace wasm | 1209 } // namespace wasm |
1210 } // namespace internal | 1210 } // namespace internal |
1211 } // namespace v8 | 1211 } // namespace v8 |
OLD | NEW |