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 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace wasm { | 13 namespace wasm { |
14 | 14 |
15 #define EMPTY_FUNCTION(sig_index) 0, SIG_INDEX(sig_index), U16_LE(0) | 15 #define EMPTY_FUNCTION(sig_index) 0, SIG_INDEX(sig_index), U16_LE(0) |
16 #define EMPTY_FUNCTION_SIZE ((size_t)5) | 16 #define SIZEOF_EMPTY_FUNCTION ((size_t)5) |
17 #define EMPTY_BODY 0 | 17 #define EMPTY_BODY 0 |
18 #define SIZEOF_EMPTY_BODY ((size_t)1) | 18 #define SIZEOF_EMPTY_BODY ((size_t)1) |
19 #define NOP_BODY 2, 0, kExprNop | 19 #define NOP_BODY 2, 0, kExprNop |
20 #define SIZEOF_NOP_BODY ((size_t)3) | 20 #define SIZEOF_NOP_BODY ((size_t)3) |
21 | 21 |
22 #define SIG_ENTRY_i_i SIG_ENTRY_x_x(kLocalI32, kLocalI32) | 22 #define SIG_ENTRY_i_i SIG_ENTRY_x_x(kLocalI32, kLocalI32) |
23 | 23 |
24 #define UNKNOWN_EMPTY_SECTION_NAME 1, '\0' | 24 #define UNKNOWN_EMPTY_SECTION_NAME 1, '\0' |
25 #define UNKNOWN_SECTION_NAME 4, 'l', 'u', 'l', 'z' | 25 #define UNKNOWN_SECTION_NAME 4, 'l', 'u', 'l', 'z' |
26 | 26 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 // func#0 ------------------------------------------------------ | 327 // func#0 ------------------------------------------------------ |
328 SIG_INDEX(0), // signature index | 328 SIG_INDEX(0), // signature index |
329 NO_NAME, // name length | 329 NO_NAME, // name length |
330 U32_LE(0), // code start offset | 330 U32_LE(0), // code start offset |
331 U32_LE(0), // code end offset | 331 U32_LE(0), // code end offset |
332 U16_LE(899), // local int32 count | 332 U16_LE(899), // local int32 count |
333 U16_LE(799), // local int64 count | 333 U16_LE(799), // local int64 count |
334 U16_LE(699), // local float32 count | 334 U16_LE(699), // local float32 count |
335 U16_LE(599), // local float64 count | 335 U16_LE(599), // local float64 count |
336 0, // exported | 336 0, // exported |
337 1 // external | 337 0 // external |
338 }; | 338 }; |
339 | 339 |
340 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 340 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
341 EXPECT_FALSE(result.ok()); | 341 EXPECT_FALSE(result.ok()); |
342 if (result.val) delete result.val; | 342 if (result.val) delete result.val; |
343 } | 343 } |
344 | 344 |
345 TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) { | 345 TEST_F(WasmModuleVerifyTest, OneEmptyVoidVoidFunction) { |
346 const int kCodeStartOffset = 49; | 346 const int kCodeStartOffset = 49; |
347 const int kCodeEndOffset = kCodeStartOffset + 1; | 347 const int kCodeEndOffset = kCodeStartOffset + 1; |
(...skipping 30 matching lines...) Expand all Loading... |
378 EXPECT_EQ(2, function->name_length); | 378 EXPECT_EQ(2, function->name_length); |
379 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 379 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
380 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 380 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
381 | 381 |
382 EXPECT_EQ(1466, function->local_i32_count); | 382 EXPECT_EQ(1466, function->local_i32_count); |
383 EXPECT_EQ(1355, function->local_i64_count); | 383 EXPECT_EQ(1355, function->local_i64_count); |
384 EXPECT_EQ(1244, function->local_f32_count); | 384 EXPECT_EQ(1244, function->local_f32_count); |
385 EXPECT_EQ(1133, function->local_f64_count); | 385 EXPECT_EQ(1133, function->local_f64_count); |
386 | 386 |
387 EXPECT_TRUE(function->exported); | 387 EXPECT_TRUE(function->exported); |
388 EXPECT_FALSE(function->external); | |
389 | 388 |
390 if (result.val) delete result.val; | 389 if (result.val) delete result.val; |
391 } | 390 } |
392 | 391 |
393 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); | 392 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); |
394 } | 393 } |
395 | 394 |
396 TEST_F(WasmModuleVerifyTest, OneFunctionImported) { | |
397 static const byte data[] = { | |
398 // signatures | |
399 SIGNATURES_SECTION_VOID_VOID, | |
400 // functions | |
401 SECTION(OLD_FUNCTIONS, 4), 1, | |
402 // func#0 ------------------------------------------------------ | |
403 kDeclFunctionImport, // no name, no locals, imported | |
404 SIG_INDEX(0), | |
405 }; | |
406 | |
407 ModuleResult result = DecodeModule(data, data + arraysize(data)); | |
408 EXPECT_OK(result); | |
409 EXPECT_EQ(1, result.val->functions.size()); | |
410 WasmFunction* function = &result.val->functions.back(); | |
411 | |
412 EXPECT_EQ(0, function->name_length); | |
413 EXPECT_EQ(0, function->code_start_offset); | |
414 EXPECT_EQ(0, function->code_end_offset); | |
415 | |
416 EXPECT_EQ(0, function->local_i32_count); | |
417 EXPECT_EQ(0, function->local_i64_count); | |
418 EXPECT_EQ(0, function->local_f32_count); | |
419 EXPECT_EQ(0, function->local_f64_count); | |
420 | |
421 EXPECT_FALSE(function->exported); | |
422 EXPECT_TRUE(function->external); | |
423 | |
424 if (result.val) delete result.val; | |
425 } | |
426 | |
427 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { | 395 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody) { |
428 static const byte kCodeStartOffset = 38; | 396 static const byte kCodeStartOffset = 38; |
429 static const byte kCodeEndOffset = kCodeStartOffset + 1; | 397 static const byte kCodeEndOffset = kCodeStartOffset + 1; |
430 | 398 |
431 static const byte data[] = { | 399 static const byte data[] = { |
432 SIGNATURES_SECTION_VOID_VOID, // -- | 400 SIGNATURES_SECTION_VOID_VOID, // -- |
433 SECTION(OLD_FUNCTIONS, 7), 1, | 401 SECTION(OLD_FUNCTIONS, 7), 1, |
434 // func#0 ------------------------------------------------------ | 402 // func#0 ------------------------------------------------------ |
435 0, // no name, no locals | 403 0, // no name, no locals |
436 0, 0, // signature index | 404 0, 0, // signature index |
437 1, 0, // body size | 405 1, 0, // body size |
438 kExprNop // body | 406 kExprNop // body |
439 }; | 407 }; |
440 | 408 |
441 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 409 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
442 EXPECT_OK(result); | 410 EXPECT_OK(result); |
443 EXPECT_EQ(1, result.val->functions.size()); | 411 EXPECT_EQ(1, result.val->functions.size()); |
444 WasmFunction* function = &result.val->functions.back(); | 412 WasmFunction* function = &result.val->functions.back(); |
445 | 413 |
446 EXPECT_EQ(0, function->name_length); | 414 EXPECT_EQ(0, function->name_length); |
447 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 415 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
448 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 416 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
449 | 417 |
450 EXPECT_EQ(0, function->local_i32_count); | 418 EXPECT_EQ(0, function->local_i32_count); |
451 EXPECT_EQ(0, function->local_i64_count); | 419 EXPECT_EQ(0, function->local_i64_count); |
452 EXPECT_EQ(0, function->local_f32_count); | 420 EXPECT_EQ(0, function->local_f32_count); |
453 EXPECT_EQ(0, function->local_f64_count); | 421 EXPECT_EQ(0, function->local_f64_count); |
454 | 422 |
455 EXPECT_FALSE(function->exported); | 423 EXPECT_FALSE(function->exported); |
456 EXPECT_FALSE(function->external); | |
457 | 424 |
458 if (result.val) delete result.val; | 425 if (result.val) delete result.val; |
459 } | 426 } |
460 | 427 |
461 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) { | 428 TEST_F(WasmModuleVerifyTest, OneFunctionWithNopBody_WithLocals) { |
462 static const byte kCodeStartOffset = 46; | 429 static const byte kCodeStartOffset = 46; |
463 static const byte kCodeEndOffset = kCodeStartOffset + 1; | 430 static const byte kCodeEndOffset = kCodeStartOffset + 1; |
464 | 431 |
465 static const byte data[] = { | 432 static const byte data[] = { |
466 SIGNATURES_SECTION_VOID_VOID, // -- | 433 SIGNATURES_SECTION_VOID_VOID, // -- |
(...skipping 16 matching lines...) Expand all Loading... |
483 EXPECT_EQ(0, function->name_length); | 450 EXPECT_EQ(0, function->name_length); |
484 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 451 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
485 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 452 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
486 | 453 |
487 EXPECT_EQ(513, function->local_i32_count); | 454 EXPECT_EQ(513, function->local_i32_count); |
488 EXPECT_EQ(1027, function->local_i64_count); | 455 EXPECT_EQ(1027, function->local_i64_count); |
489 EXPECT_EQ(1541, function->local_f32_count); | 456 EXPECT_EQ(1541, function->local_f32_count); |
490 EXPECT_EQ(2055, function->local_f64_count); | 457 EXPECT_EQ(2055, function->local_f64_count); |
491 | 458 |
492 EXPECT_FALSE(function->exported); | 459 EXPECT_FALSE(function->exported); |
493 EXPECT_FALSE(function->external); | |
494 | 460 |
495 if (result.val) delete result.val; | 461 if (result.val) delete result.val; |
496 } | 462 } |
497 | 463 |
498 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { | 464 TEST_F(WasmModuleVerifyTest, OneGlobalOneFunctionWithNopBodyOneDataSegment) { |
499 static const byte kNameOffset = 49; | 465 static const byte kNameOffset = 49; |
500 static const byte kCodeStartOffset = 61; | 466 static const byte kCodeStartOffset = 61; |
501 static const byte kCodeEndOffset = kCodeStartOffset + 3; | 467 static const byte kCodeEndOffset = kCodeStartOffset + 3; |
502 static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22; | 468 static const byte kDataSegmentSourceOffset = kCodeEndOffset + 22; |
503 | 469 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 EXPECT_FALSE(global->exported); | 514 EXPECT_FALSE(global->exported); |
549 | 515 |
550 WasmFunction* function = &result.val->functions.back(); | 516 WasmFunction* function = &result.val->functions.back(); |
551 | 517 |
552 EXPECT_EQ(kNameOffset, function->name_offset); | 518 EXPECT_EQ(kNameOffset, function->name_offset); |
553 EXPECT_EQ(2, function->name_length); | 519 EXPECT_EQ(2, function->name_length); |
554 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); | 520 EXPECT_EQ(kCodeStartOffset, function->code_start_offset); |
555 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); | 521 EXPECT_EQ(kCodeEndOffset, function->code_end_offset); |
556 | 522 |
557 EXPECT_FALSE(function->exported); | 523 EXPECT_FALSE(function->exported); |
558 EXPECT_FALSE(function->external); | |
559 | 524 |
560 WasmDataSegment* segment = &result.val->data_segments.back(); | 525 WasmDataSegment* segment = &result.val->data_segments.back(); |
561 | 526 |
562 EXPECT_EQ(0x8b3ae, segment->dest_addr); | 527 EXPECT_EQ(0x8b3ae, segment->dest_addr); |
563 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); | 528 EXPECT_EQ(kDataSegmentSourceOffset, segment->source_offset); |
564 EXPECT_EQ(5, segment->source_size); | 529 EXPECT_EQ(5, segment->source_size); |
565 EXPECT_TRUE(segment->init); | 530 EXPECT_TRUE(segment->init); |
566 | 531 |
567 if (result.val) delete result.val; | 532 if (result.val) delete result.val; |
568 } | 533 } |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 | 649 |
685 if (dest_addr <= (mem_size - source_size)) { | 650 if (dest_addr <= (mem_size - source_size)) { |
686 EXPECT_VERIFIES(data); | 651 EXPECT_VERIFIES(data); |
687 } else { | 652 } else { |
688 EXPECT_FAILURE(data); | 653 EXPECT_FAILURE(data); |
689 } | 654 } |
690 } | 655 } |
691 } | 656 } |
692 } | 657 } |
693 | 658 |
694 // To make below tests for indirect calls much shorter. | |
695 #define FUNCTION(sig_index, external) kDeclFunctionImport, SIG_INDEX(sig_index) | |
696 | |
697 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { | 659 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { |
698 static const byte data[] = { | 660 static const byte data[] = { |
699 // sig#0 ------------------------------------------------------- | 661 // sig#0 ------------------------------------------------------- |
700 SIGNATURES_SECTION_VOID_VOID, | 662 SIGNATURES_SECTION_VOID_VOID, |
701 // func#0 ------------------------------------------------------ | 663 // func#0 ------------------------------------------------------ |
702 SECTION(OLD_FUNCTIONS, 4), 1, FUNCTION(0, 0), | 664 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), 1, // -- |
| 665 EMPTY_FUNCTION(0), |
703 // indirect table ---------------------------------------------- | 666 // indirect table ---------------------------------------------- |
704 SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)}; | 667 SECTION(FUNCTION_TABLE, 2), 1, U32V_1(0)}; |
705 | 668 |
706 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 669 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
707 EXPECT_OK(result); | 670 EXPECT_OK(result); |
708 if (result.ok()) { | 671 if (result.ok()) { |
709 EXPECT_EQ(1, result.val->signatures.size()); | 672 EXPECT_EQ(1, result.val->signatures.size()); |
710 EXPECT_EQ(1, result.val->functions.size()); | 673 EXPECT_EQ(1, result.val->functions.size()); |
711 EXPECT_EQ(1, result.val->function_table.size()); | 674 EXPECT_EQ(1, result.val->function_table.size()); |
712 EXPECT_EQ(0, result.val->function_table[0]); | 675 EXPECT_EQ(0, result.val->function_table[0]); |
713 } | 676 } |
714 if (result.val) delete result.val; | 677 if (result.val) delete result.val; |
715 } | 678 } |
716 | 679 |
717 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { | 680 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { |
718 static const byte data[] = { | 681 static const byte data[] = { |
719 // sig#0 ------------------------------------------------------- | 682 // sig#0 ------------------------------------------------------- |
720 SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), | 683 SECTION(SIGNATURES, 1 + SIZEOF_SIG_ENTRY_v_v + SIZEOF_SIG_ENTRY_v_x), |
721 2, // -- | 684 2, // -- |
722 SIG_ENTRY_v_v, // void -> void | 685 SIG_ENTRY_v_v, // void -> void |
723 SIG_ENTRY_v_x(kLocalI32), // void -> i32 | 686 SIG_ENTRY_v_x(kLocalI32), // void -> i32 |
724 // func#0 ------------------------------------------------------ | 687 // func#0 ------------------------------------------------------ |
725 SECTION(OLD_FUNCTIONS, 13), 4, FUNCTION(0, 1), // -- | 688 SECTION(OLD_FUNCTIONS, 1 + 4 * SIZEOF_EMPTY_FUNCTION), 4, // -- |
726 FUNCTION(1, 1), // -- | 689 EMPTY_FUNCTION(0), // -- |
727 FUNCTION(0, 1), // -- | 690 EMPTY_FUNCTION(1), // -- |
728 FUNCTION(1, 1), // -- | 691 EMPTY_FUNCTION(0), // -- |
| 692 EMPTY_FUNCTION(1), // -- |
729 // indirect table ---------------------------------------------- | 693 // indirect table ---------------------------------------------- |
730 SECTION(FUNCTION_TABLE, 9), 8, | 694 SECTION(FUNCTION_TABLE, 9), 8, |
731 U32V_1(0), // -- | 695 U32V_1(0), // -- |
732 U32V_1(1), // -- | 696 U32V_1(1), // -- |
733 U32V_1(2), // -- | 697 U32V_1(2), // -- |
734 U32V_1(3), // -- | 698 U32V_1(3), // -- |
735 U32V_1(0), // -- | 699 U32V_1(0), // -- |
736 U32V_1(1), // -- | 700 U32V_1(1), // -- |
737 U32V_1(2), // -- | 701 U32V_1(2), // -- |
738 U32V_1(3), // -- | 702 U32V_1(3), // -- |
(...skipping 21 matching lines...) Expand all Loading... |
760 }; | 724 }; |
761 | 725 |
762 EXPECT_FAILURE(data); | 726 EXPECT_FAILURE(data); |
763 } | 727 } |
764 | 728 |
765 TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) { | 729 TEST_F(WasmModuleVerifyTest, IndirectFunctionInvalidIndex) { |
766 static const byte data[] = { | 730 static const byte data[] = { |
767 // sig#0 ------------------------------------------------------- | 731 // sig#0 ------------------------------------------------------- |
768 SIGNATURES_SECTION_VOID_VOID, | 732 SIGNATURES_SECTION_VOID_VOID, |
769 // functions --------------------------------------------------- | 733 // functions --------------------------------------------------- |
770 SECTION(OLD_FUNCTIONS, 4), 1, FUNCTION(0, 1), | 734 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), 1, // -- |
| 735 EMPTY_FUNCTION(0), |
771 // indirect table ---------------------------------------------- | 736 // indirect table ---------------------------------------------- |
772 SECTION(FUNCTION_TABLE, 3), 1, 1, 0, | 737 SECTION(FUNCTION_TABLE, 3), 1, 1, 0, |
773 }; | 738 }; |
774 | 739 |
775 EXPECT_FAILURE(data); | 740 EXPECT_FAILURE(data); |
776 } | 741 } |
777 | 742 |
778 class WasmSignatureDecodeTest : public TestWithZone {}; | 743 class WasmSignatureDecodeTest : public TestWithZone {}; |
779 | 744 |
780 TEST_F(WasmSignatureDecodeTest, Ok_v_v) { | 745 TEST_F(WasmSignatureDecodeTest, Ok_v_v) { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 EXPECT_OK(result); | 887 EXPECT_OK(result); |
923 | 888 |
924 if (result.val && result.ok()) { | 889 if (result.val && result.ok()) { |
925 WasmFunction* function = result.val; | 890 WasmFunction* function = result.val; |
926 EXPECT_EQ(0, function->sig->parameter_count()); | 891 EXPECT_EQ(0, function->sig->parameter_count()); |
927 EXPECT_EQ(0, function->sig->return_count()); | 892 EXPECT_EQ(0, function->sig->return_count()); |
928 EXPECT_EQ(0, function->name_offset); | 893 EXPECT_EQ(0, function->name_offset); |
929 EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset); | 894 EXPECT_EQ(SIZEOF_SIG_ENTRY_v_v, function->code_start_offset); |
930 EXPECT_EQ(arraysize(data), function->code_end_offset); | 895 EXPECT_EQ(arraysize(data), function->code_end_offset); |
931 // TODO(titzer): verify encoding of local declarations | 896 // TODO(titzer): verify encoding of local declarations |
932 EXPECT_FALSE(function->external); | |
933 EXPECT_FALSE(function->exported); | 897 EXPECT_FALSE(function->exported); |
934 } | 898 } |
935 | 899 |
936 if (result.val) delete result.val; | 900 if (result.val) delete result.val; |
937 } | 901 } |
938 | 902 |
939 TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) { | 903 TEST_F(WasmModuleVerifyTest, SectionWithoutNameLength) { |
940 const byte data[] = {1}; | 904 const byte data[] = {1}; |
941 EXPECT_FAILURE(data); | 905 EXPECT_FAILURE(data); |
942 } | 906 } |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1158 'f', // function name | 1122 'f', // function name |
1159 }; | 1123 }; |
1160 | 1124 |
1161 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); | 1125 EXPECT_OFF_END_FAILURE(data, 16, sizeof(data)); |
1162 } | 1126 } |
1163 | 1127 |
1164 TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { | 1128 TEST_F(WasmModuleVerifyTest, ExportTable_empty1) { |
1165 static const byte data[] = { | 1129 static const byte data[] = { |
1166 // signatures | 1130 // signatures |
1167 SIGNATURES_SECTION_VOID_VOID, | 1131 SIGNATURES_SECTION_VOID_VOID, |
1168 SECTION(OLD_FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE), | 1132 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
1169 1, | 1133 1, |
1170 EMPTY_FUNCTION(0), | 1134 EMPTY_FUNCTION(0), |
1171 SECTION(EXPORT_TABLE, 1), | 1135 SECTION(EXPORT_TABLE, 1), |
1172 0 // -- | 1136 0 // -- |
1173 }; | 1137 }; |
1174 EXPECT_VERIFIES(data); | 1138 EXPECT_VERIFIES(data); |
1175 } | 1139 } |
1176 | 1140 |
1177 TEST_F(WasmModuleVerifyTest, ExportTable_empty2) { | 1141 TEST_F(WasmModuleVerifyTest, ExportTable_empty2) { |
1178 static const byte data[] = { | 1142 static const byte data[] = { |
(...skipping 13 matching lines...) Expand all Loading... |
1192 | 1156 |
1193 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) { | 1157 TEST_F(WasmModuleVerifyTest, ExportTable_NoFunctions2) { |
1194 static const byte data[] = {SECTION(EXPORT_TABLE, 1), 0}; | 1158 static const byte data[] = {SECTION(EXPORT_TABLE, 1), 0}; |
1195 EXPECT_FAILURE(data); | 1159 EXPECT_FAILURE(data); |
1196 } | 1160 } |
1197 | 1161 |
1198 TEST_F(WasmModuleVerifyTest, ExportTableOne) { | 1162 TEST_F(WasmModuleVerifyTest, ExportTableOne) { |
1199 static const byte data[] = { | 1163 static const byte data[] = { |
1200 // signatures | 1164 // signatures |
1201 SIGNATURES_SECTION_VOID_VOID, | 1165 SIGNATURES_SECTION_VOID_VOID, |
1202 SECTION(OLD_FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE), | 1166 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
1203 1, // functions | 1167 1, // functions |
1204 EMPTY_FUNCTION(0), // -- | 1168 EMPTY_FUNCTION(0), // -- |
1205 SECTION(EXPORT_TABLE, 3), | 1169 SECTION(EXPORT_TABLE, 3), |
1206 1, // exports | 1170 1, // exports |
1207 FUNC_INDEX(0), // -- | 1171 FUNC_INDEX(0), // -- |
1208 NO_NAME // -- | 1172 NO_NAME // -- |
1209 }; | 1173 }; |
1210 EXPECT_VERIFIES(data); | 1174 EXPECT_VERIFIES(data); |
1211 } | 1175 } |
1212 | 1176 |
1213 TEST_F(WasmModuleVerifyTest, ExportTableTwo) { | 1177 TEST_F(WasmModuleVerifyTest, ExportTableTwo) { |
1214 static const byte data[] = { | 1178 static const byte data[] = { |
1215 // signatures | 1179 // signatures |
1216 SIGNATURES_SECTION_VOID_VOID, | 1180 SIGNATURES_SECTION_VOID_VOID, |
1217 SECTION(OLD_FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE), | 1181 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
1218 1, // functions | 1182 1, // functions |
1219 EMPTY_FUNCTION(0), // -- | 1183 EMPTY_FUNCTION(0), // -- |
1220 SECTION(EXPORT_TABLE, 12), | 1184 SECTION(EXPORT_TABLE, 12), |
1221 2, // exports | 1185 2, // exports |
1222 FUNC_INDEX(0), // -- | 1186 FUNC_INDEX(0), // -- |
1223 NAME_LENGTH(4), | 1187 NAME_LENGTH(4), |
1224 'n', | 1188 'n', |
1225 'a', | 1189 'a', |
1226 'm', | 1190 'm', |
1227 'e', // -- | 1191 'e', // -- |
1228 FUNC_INDEX(0), // -- | 1192 FUNC_INDEX(0), // -- |
1229 NAME_LENGTH(3), | 1193 NAME_LENGTH(3), |
1230 'n', | 1194 'n', |
1231 'o', | 1195 'o', |
1232 'm' // -- | 1196 'm' // -- |
1233 }; | 1197 }; |
1234 EXPECT_VERIFIES(data); | 1198 EXPECT_VERIFIES(data); |
1235 } | 1199 } |
1236 | 1200 |
1237 TEST_F(WasmModuleVerifyTest, ExportTableThree) { | 1201 TEST_F(WasmModuleVerifyTest, ExportTableThree) { |
1238 static const byte data[] = { | 1202 static const byte data[] = { |
1239 // signatures | 1203 // signatures |
1240 SIGNATURES_SECTION_VOID_VOID, | 1204 SIGNATURES_SECTION_VOID_VOID, |
1241 SECTION(OLD_FUNCTIONS, 1 + 3 * EMPTY_FUNCTION_SIZE), | 1205 SECTION(OLD_FUNCTIONS, 1 + 3 * SIZEOF_EMPTY_FUNCTION), |
1242 3, // functions | 1206 3, // functions |
1243 EMPTY_FUNCTION(0), // -- | 1207 EMPTY_FUNCTION(0), // -- |
1244 EMPTY_FUNCTION(0), // -- | 1208 EMPTY_FUNCTION(0), // -- |
1245 EMPTY_FUNCTION(0), // -- | 1209 EMPTY_FUNCTION(0), // -- |
1246 SECTION(EXPORT_TABLE, 10), | 1210 SECTION(EXPORT_TABLE, 10), |
1247 3, // exports | 1211 3, // exports |
1248 FUNC_INDEX(0), // -- | 1212 FUNC_INDEX(0), // -- |
1249 NAME_LENGTH(1), | 1213 NAME_LENGTH(1), |
1250 'a', // -- | 1214 'a', // -- |
1251 FUNC_INDEX(1), // -- | 1215 FUNC_INDEX(1), // -- |
1252 NAME_LENGTH(1), | 1216 NAME_LENGTH(1), |
1253 'b', // -- | 1217 'b', // -- |
1254 FUNC_INDEX(2), // -- | 1218 FUNC_INDEX(2), // -- |
1255 NAME_LENGTH(1), | 1219 NAME_LENGTH(1), |
1256 'c' // -- | 1220 'c' // -- |
1257 }; | 1221 }; |
1258 EXPECT_VERIFIES(data); | 1222 EXPECT_VERIFIES(data); |
1259 } | 1223 } |
1260 | 1224 |
1261 TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) { | 1225 TEST_F(WasmModuleVerifyTest, ExportTableThreeOne) { |
1262 for (int i = 0; i < 6; i++) { | 1226 for (int i = 0; i < 6; i++) { |
1263 const byte data[] = { | 1227 const byte data[] = { |
1264 // signatures | 1228 // signatures |
1265 SIGNATURES_SECTION_VOID_VOID, | 1229 SIGNATURES_SECTION_VOID_VOID, |
1266 SECTION(OLD_FUNCTIONS, 1 + 3 * EMPTY_FUNCTION_SIZE), | 1230 SECTION(OLD_FUNCTIONS, 1 + 3 * SIZEOF_EMPTY_FUNCTION), |
1267 3, // functions | 1231 3, // functions |
1268 EMPTY_FUNCTION(0), // -- | 1232 EMPTY_FUNCTION(0), // -- |
1269 EMPTY_FUNCTION(0), // -- | 1233 EMPTY_FUNCTION(0), // -- |
1270 EMPTY_FUNCTION(0), // -- | 1234 EMPTY_FUNCTION(0), // -- |
1271 SECTION(EXPORT_TABLE, 5), | 1235 SECTION(EXPORT_TABLE, 5), |
1272 1, // exports | 1236 1, // exports |
1273 FUNC_INDEX(i), // -- | 1237 FUNC_INDEX(i), // -- |
1274 NAME_LENGTH(2), | 1238 NAME_LENGTH(2), |
1275 'e', | 1239 'e', |
1276 'x', // -- | 1240 'x', // -- |
1277 }; | 1241 }; |
1278 | 1242 |
1279 if (i < 3) { | 1243 if (i < 3) { |
1280 EXPECT_VERIFIES(data); | 1244 EXPECT_VERIFIES(data); |
1281 } else { | 1245 } else { |
1282 EXPECT_FAILURE(data); | 1246 EXPECT_FAILURE(data); |
1283 } | 1247 } |
1284 } | 1248 } |
1285 } | 1249 } |
1286 | 1250 |
1287 TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) { | 1251 TEST_F(WasmModuleVerifyTest, ExportTableOne_off_end) { |
1288 static const byte data[] = { | 1252 static const byte data[] = { |
1289 // signatures | 1253 // signatures |
1290 SIGNATURES_SECTION_VOID_VOID, | 1254 SIGNATURES_SECTION_VOID_VOID, |
1291 SECTION(OLD_FUNCTIONS, 1 + EMPTY_FUNCTION_SIZE), | 1255 SECTION(OLD_FUNCTIONS, 1 + SIZEOF_EMPTY_FUNCTION), |
1292 1, // functions | 1256 1, // functions |
1293 EMPTY_FUNCTION(0), // -- | 1257 EMPTY_FUNCTION(0), // -- |
1294 SECTION(EXPORT_TABLE, 1 + 6), | 1258 SECTION(EXPORT_TABLE, 1 + 6), |
1295 1, // exports | 1259 1, // exports |
1296 FUNC_INDEX(0), // -- | 1260 FUNC_INDEX(0), // -- |
1297 NO_NAME // -- | 1261 NO_NAME // -- |
1298 }; | 1262 }; |
1299 | 1263 |
1300 for (int length = 33; length < sizeof(data); length++) { | 1264 for (int length = 33; length < sizeof(data); length++) { |
1301 ModuleResult result = DecodeModule(data, data + length); | 1265 ModuleResult result = DecodeModule(data, data + length); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1405 NO_LOCAL_NAMES, // -- | 1369 NO_LOCAL_NAMES, // -- |
1406 FOO_STRING, | 1370 FOO_STRING, |
1407 NO_LOCAL_NAMES, // -- | 1371 NO_LOCAL_NAMES, // -- |
1408 }; | 1372 }; |
1409 EXPECT_VERIFIES(data); | 1373 EXPECT_VERIFIES(data); |
1410 } | 1374 } |
1411 | 1375 |
1412 } // namespace wasm | 1376 } // namespace wasm |
1413 } // namespace internal | 1377 } // namespace internal |
1414 } // namespace v8 | 1378 } // namespace v8 |
OLD | NEW |