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/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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 }; | 149 }; |
150 | 150 |
151 { | 151 { |
152 // Should decode to exactly one global. | 152 // Should decode to exactly one global. |
153 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 153 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
154 EXPECT_OK(result); | 154 EXPECT_OK(result); |
155 EXPECT_EQ(1, result.val->globals.size()); | 155 EXPECT_EQ(1, result.val->globals.size()); |
156 EXPECT_EQ(0, result.val->functions.size()); | 156 EXPECT_EQ(0, result.val->functions.size()); |
157 EXPECT_EQ(0, result.val->data_segments.size()); | 157 EXPECT_EQ(0, result.val->data_segments.size()); |
158 | 158 |
159 WasmGlobal* global = &result.val->globals.back(); | 159 const WasmGlobal* global = &result.val->globals.back(); |
160 | 160 |
161 EXPECT_EQ(1, global->name_length); | 161 EXPECT_EQ(1, global->name_length); |
162 EXPECT_EQ(MachineType::Int32(), global->type); | 162 EXPECT_EQ(MachineType::Int32(), global->type); |
163 EXPECT_EQ(0, global->offset); | 163 EXPECT_EQ(0, global->offset); |
164 EXPECT_FALSE(global->exported); | 164 EXPECT_FALSE(global->exported); |
165 | 165 |
166 if (result.val) delete result.val; | 166 if (result.val) delete result.val; |
167 } | 167 } |
168 | 168 |
169 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); | 169 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 }; | 255 }; |
256 | 256 |
257 { | 257 { |
258 // Should decode to exactly two globals. | 258 // Should decode to exactly two globals. |
259 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 259 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
260 EXPECT_OK(result); | 260 EXPECT_OK(result); |
261 EXPECT_EQ(2, result.val->globals.size()); | 261 EXPECT_EQ(2, result.val->globals.size()); |
262 EXPECT_EQ(0, result.val->functions.size()); | 262 EXPECT_EQ(0, result.val->functions.size()); |
263 EXPECT_EQ(0, result.val->data_segments.size()); | 263 EXPECT_EQ(0, result.val->data_segments.size()); |
264 | 264 |
265 WasmGlobal* g0 = &result.val->globals[0]; | 265 const WasmGlobal* g0 = &result.val->globals[0]; |
266 WasmGlobal* g1 = &result.val->globals[1]; | 266 const WasmGlobal* g1 = &result.val->globals[1]; |
267 | 267 |
268 EXPECT_EQ(0, g0->name_length); | 268 EXPECT_EQ(0, g0->name_length); |
269 EXPECT_EQ(MachineType::Float32(), g0->type); | 269 EXPECT_EQ(MachineType::Float32(), g0->type); |
270 EXPECT_EQ(0, g0->offset); | 270 EXPECT_EQ(0, g0->offset); |
271 EXPECT_FALSE(g0->exported); | 271 EXPECT_FALSE(g0->exported); |
272 | 272 |
273 EXPECT_EQ(0, g1->name_length); | 273 EXPECT_EQ(0, g1->name_length); |
274 EXPECT_EQ(MachineType::Float64(), g1->type); | 274 EXPECT_EQ(MachineType::Float64(), g1->type); |
275 EXPECT_EQ(0, g1->offset); | 275 EXPECT_EQ(8, g1->offset); |
276 EXPECT_TRUE(g1->exported); | 276 EXPECT_TRUE(g1->exported); |
277 | 277 |
278 if (result.val) delete result.val; | 278 if (result.val) delete result.val; |
279 } | 279 } |
280 | 280 |
281 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); | 281 EXPECT_OFF_END_FAILURE(data, 1, sizeof(data)); |
282 } | 282 } |
283 | 283 |
284 TEST_F(WasmModuleVerifyTest, OneSignature) { | 284 TEST_F(WasmModuleVerifyTest, OneSignature) { |
285 { | 285 { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 { | 360 { |
361 // Should decode to exactly one function. | 361 // Should decode to exactly one function. |
362 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 362 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
363 EXPECT_OK(result); | 363 EXPECT_OK(result); |
364 EXPECT_EQ(0, result.val->globals.size()); | 364 EXPECT_EQ(0, result.val->globals.size()); |
365 EXPECT_EQ(1, result.val->signatures.size()); | 365 EXPECT_EQ(1, result.val->signatures.size()); |
366 EXPECT_EQ(1, result.val->functions.size()); | 366 EXPECT_EQ(1, result.val->functions.size()); |
367 EXPECT_EQ(0, result.val->data_segments.size()); | 367 EXPECT_EQ(0, result.val->data_segments.size()); |
368 EXPECT_EQ(0, result.val->function_table.size()); | 368 EXPECT_EQ(0, result.val->function_table.size()); |
369 | 369 |
370 WasmFunction* function = &result.val->functions.back(); | 370 const WasmFunction* function = &result.val->functions.back(); |
371 | 371 |
372 EXPECT_EQ(37, function->name_offset); | 372 EXPECT_EQ(37, function->name_offset); |
373 EXPECT_EQ(2, function->name_length); | 373 EXPECT_EQ(2, function->name_length); |
374 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 374 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
375 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 375 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
376 | 376 |
377 EXPECT_TRUE(function->exported); | 377 EXPECT_TRUE(function->exported); |
378 | 378 |
379 if (result.val) delete result.val; | 379 if (result.val) delete result.val; |
380 } | 380 } |
(...skipping 11 matching lines...) Expand all Loading... |
392 // func#0 ------------------------------------------------------ | 392 // func#0 ------------------------------------------------------ |
393 0, // no name, no locals | 393 0, // no name, no locals |
394 0, 0, // signature index | 394 0, 0, // signature index |
395 1, 0, // body size | 395 1, 0, // body size |
396 kExprNop // body | 396 kExprNop // body |
397 }; | 397 }; |
398 | 398 |
399 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 399 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
400 EXPECT_OK(result); | 400 EXPECT_OK(result); |
401 EXPECT_EQ(1, result.val->functions.size()); | 401 EXPECT_EQ(1, result.val->functions.size()); |
402 WasmFunction* function = &result.val->functions.back(); | 402 const WasmFunction* function = &result.val->functions.back(); |
403 | 403 |
404 EXPECT_EQ(0, function->name_length); | 404 EXPECT_EQ(0, function->name_length); |
405 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 405 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
406 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 406 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
407 | 407 |
408 EXPECT_FALSE(function->exported); | 408 EXPECT_FALSE(function->exported); |
409 | 409 |
410 if (result.val) delete result.val; | 410 if (result.val) delete result.val; |
411 } | 411 } |
412 | 412 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 SECTION(END, 0), | 444 SECTION(END, 0), |
445 }; | 445 }; |
446 | 446 |
447 { | 447 { |
448 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 448 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
449 EXPECT_OK(result); | 449 EXPECT_OK(result); |
450 EXPECT_EQ(1, result.val->globals.size()); | 450 EXPECT_EQ(1, result.val->globals.size()); |
451 EXPECT_EQ(1, result.val->functions.size()); | 451 EXPECT_EQ(1, result.val->functions.size()); |
452 EXPECT_EQ(1, result.val->data_segments.size()); | 452 EXPECT_EQ(1, result.val->data_segments.size()); |
453 | 453 |
454 WasmGlobal* global = &result.val->globals.back(); | 454 const WasmGlobal* global = &result.val->globals.back(); |
455 | 455 |
456 EXPECT_EQ(0, global->name_length); | 456 EXPECT_EQ(0, global->name_length); |
457 EXPECT_EQ(MachineType::Uint8(), global->type); | 457 EXPECT_EQ(MachineType::Uint8(), global->type); |
458 EXPECT_EQ(0, global->offset); | 458 EXPECT_EQ(0, global->offset); |
459 EXPECT_FALSE(global->exported); | 459 EXPECT_FALSE(global->exported); |
460 | 460 |
461 WasmFunction* function = &result.val->functions.back(); | 461 const WasmFunction* function = &result.val->functions.back(); |
462 | 462 |
463 EXPECT_EQ(kNameOffset, function->name_offset); | 463 EXPECT_EQ(kNameOffset, function->name_offset); |
464 EXPECT_EQ(2, function->name_length); | 464 EXPECT_EQ(2, function->name_length); |
465 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 465 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
466 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 466 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
467 | 467 |
468 EXPECT_FALSE(function->exported); | 468 EXPECT_FALSE(function->exported); |
469 | 469 |
470 WasmDataSegment* segment = &result.val->data_segments.back(); | 470 const WasmDataSegment* segment = &result.val->data_segments.back(); |
471 | 471 |
472 EXPECT_EQ(0x8b3ae, segment->dest_addr); | 472 EXPECT_EQ(0x8b3ae, segment->dest_addr); |
473 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); | 473 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); |
474 EXPECT_EQ(5, segment->source_size); | 474 EXPECT_EQ(5, segment->source_size); |
475 EXPECT_TRUE(segment->init); | 475 EXPECT_TRUE(segment->init); |
476 | 476 |
477 if (result.val) delete result.val; | 477 if (result.val) delete result.val; |
478 } | 478 } |
479 } | 479 } |
480 | 480 |
(...skipping 14 matching lines...) Expand all Loading... |
495 }; | 495 }; |
496 | 496 |
497 { | 497 { |
498 EXPECT_VERIFIES(data); | 498 EXPECT_VERIFIES(data); |
499 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 499 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
500 EXPECT_OK(result); | 500 EXPECT_OK(result); |
501 EXPECT_EQ(0, result.val->globals.size()); | 501 EXPECT_EQ(0, result.val->globals.size()); |
502 EXPECT_EQ(0, result.val->functions.size()); | 502 EXPECT_EQ(0, result.val->functions.size()); |
503 EXPECT_EQ(1, result.val->data_segments.size()); | 503 EXPECT_EQ(1, result.val->data_segments.size()); |
504 | 504 |
505 WasmDataSegment* segment = &result.val->data_segments.back(); | 505 const WasmDataSegment* segment = &result.val->data_segments.back(); |
506 | 506 |
507 EXPECT_EQ(0x9bbaa, segment->dest_addr); | 507 EXPECT_EQ(0x9bbaa, segment->dest_addr); |
508 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); | 508 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); |
509 EXPECT_EQ(3, segment->source_size); | 509 EXPECT_EQ(3, segment->source_size); |
510 EXPECT_TRUE(segment->init); | 510 EXPECT_TRUE(segment->init); |
511 | 511 |
512 if (result.val) delete result.val; | 512 if (result.val) delete result.val; |
513 } | 513 } |
514 | 514 |
515 EXPECT_OFF_END_FAILURE(data, 13, sizeof(data)); | 515 EXPECT_OFF_END_FAILURE(data, 13, sizeof(data)); |
(...skipping 30 matching lines...) Expand all Loading... |
546 10 // data bytes | 546 10 // data bytes |
547 }; | 547 }; |
548 | 548 |
549 { | 549 { |
550 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 550 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
551 EXPECT_OK(result); | 551 EXPECT_OK(result); |
552 EXPECT_EQ(0, result.val->globals.size()); | 552 EXPECT_EQ(0, result.val->globals.size()); |
553 EXPECT_EQ(0, result.val->functions.size()); | 553 EXPECT_EQ(0, result.val->functions.size()); |
554 EXPECT_EQ(2, result.val->data_segments.size()); | 554 EXPECT_EQ(2, result.val->data_segments.size()); |
555 | 555 |
556 WasmDataSegment* s0 = &result.val->data_segments[0]; | 556 const WasmDataSegment* s0 = &result.val->data_segments[0]; |
557 WasmDataSegment* s1 = &result.val->data_segments[1]; | 557 const WasmDataSegment* s1 = &result.val->data_segments[1]; |
558 | 558 |
559 EXPECT_EQ(0x7ffee, s0->dest_addr); | 559 EXPECT_EQ(0x7ffee, s0->dest_addr); |
560 EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset); | 560 EXPECT_EQ(kDataSegment0SourceOffset, s0->source_offset); |
561 EXPECT_EQ(4, s0->source_size); | 561 EXPECT_EQ(4, s0->source_size); |
562 EXPECT_TRUE(s0->init); | 562 EXPECT_TRUE(s0->init); |
563 | 563 |
564 EXPECT_EQ(0x6ddcc, s1->dest_addr); | 564 EXPECT_EQ(0x6ddcc, s1->dest_addr); |
565 EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset); | 565 EXPECT_EQ(kDataSegment1SourceOffset, s1->source_offset); |
566 EXPECT_EQ(10, s1->source_size); | 566 EXPECT_EQ(10, s1->source_size); |
567 EXPECT_TRUE(s1->init); | 567 EXPECT_TRUE(s1->init); |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 kMemI32, // memory type | 976 kMemI32, // memory type |
977 0, // exported | 977 0, // exported |
978 }; | 978 }; |
979 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 979 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
980 EXPECT_OK(result); | 980 EXPECT_OK(result); |
981 | 981 |
982 EXPECT_EQ(1, result.val->globals.size()); | 982 EXPECT_EQ(1, result.val->globals.size()); |
983 EXPECT_EQ(0, result.val->functions.size()); | 983 EXPECT_EQ(0, result.val->functions.size()); |
984 EXPECT_EQ(0, result.val->data_segments.size()); | 984 EXPECT_EQ(0, result.val->data_segments.size()); |
985 | 985 |
986 WasmGlobal* global = &result.val->globals.back(); | 986 const WasmGlobal* global = &result.val->globals.back(); |
987 | 987 |
988 EXPECT_EQ(0, global->name_length); | 988 EXPECT_EQ(0, global->name_length); |
989 EXPECT_EQ(MachineType::Int32(), global->type); | 989 EXPECT_EQ(MachineType::Int32(), global->type); |
990 EXPECT_EQ(0, global->offset); | 990 EXPECT_EQ(0, global->offset); |
991 EXPECT_FALSE(global->exported); | 991 EXPECT_FALSE(global->exported); |
992 | 992 |
993 if (result.val) delete result.val; | 993 if (result.val) delete result.val; |
994 } | 994 } |
995 | 995 |
996 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { | 996 TEST_F(WasmModuleVerifyTest, ImportTable_empty) { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1314 NO_LOCAL_NAMES, // -- | 1314 NO_LOCAL_NAMES, // -- |
1315 FOO_STRING, | 1315 FOO_STRING, |
1316 NO_LOCAL_NAMES, // -- | 1316 NO_LOCAL_NAMES, // -- |
1317 }; | 1317 }; |
1318 EXPECT_VERIFIES(data); | 1318 EXPECT_VERIFIES(data); |
1319 } | 1319 } |
1320 | 1320 |
1321 } // namespace wasm | 1321 } // namespace wasm |
1322 } // namespace internal | 1322 } // namespace internal |
1323 } // namespace v8 | 1323 } // namespace v8 |
OLD | NEW |