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 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 EXPECT_VERIFIES(data); | 675 EXPECT_VERIFIES(data); |
676 } else { | 676 } else { |
677 EXPECT_FAILURE(data); | 677 EXPECT_FAILURE(data); |
678 } | 678 } |
679 } | 679 } |
680 } | 680 } |
681 } | 681 } |
682 | 682 |
683 | 683 |
684 // To make below tests for indirect calls much shorter. | 684 // To make below tests for indirect calls much shorter. |
685 #define FUNCTION(sig_index, external) \ | 685 #define FUNCTION(sig_index, external) kDeclFunctionImport, SIG_INDEX(sig_index) |
686 kDeclFunctionImport, static_cast<byte>(sig_index), \ | |
687 static_cast<byte>(sig_index >> 8) | |
688 | |
689 | 686 |
690 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { | 687 TEST_F(WasmModuleVerifyTest, OneIndirectFunction) { |
691 static const byte data[] = { | 688 static const byte data[] = { |
692 // sig#0 ------------------------------------------------------- | 689 // sig#0 ------------------------------------------------------- |
693 kDeclSignatures, 1, 0, 0, // void -> void | 690 kDeclSignatures, 1, 0, 0, // void -> void |
694 // func#0 ------------------------------------------------------ | 691 // func#0 ------------------------------------------------------ |
695 kDeclFunctions, 1, FUNCTION(0, 0), | 692 kDeclFunctions, 1, FUNCTION(0, 0), |
696 // indirect table ---------------------------------------------- | 693 // indirect table ---------------------------------------------- |
697 kDeclFunctionTable, 1, 0, 0}; | 694 kDeclFunctionTable, 1, U32V_1(0)}; |
698 | 695 |
699 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 696 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
700 EXPECT_TRUE(result.ok()); | 697 EXPECT_TRUE(result.ok()); |
701 if (result.ok()) { | 698 if (result.ok()) { |
702 EXPECT_EQ(1, result.val->signatures.size()); | 699 EXPECT_EQ(1, result.val->signatures.size()); |
703 EXPECT_EQ(1, result.val->functions.size()); | 700 EXPECT_EQ(1, result.val->functions.size()); |
704 EXPECT_EQ(1, result.val->function_table.size()); | 701 EXPECT_EQ(1, result.val->function_table.size()); |
705 EXPECT_EQ(0, result.val->function_table[0]); | 702 EXPECT_EQ(0, result.val->function_table[0]); |
706 } | 703 } |
707 if (result.val) delete result.val; | 704 if (result.val) delete result.val; |
708 } | 705 } |
709 | 706 |
710 | 707 |
711 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { | 708 TEST_F(WasmModuleVerifyTest, MultipleIndirectFunctions) { |
712 static const byte data[] = { | 709 static const byte data[] = { |
713 // sig#0 ------------------------------------------------------- | 710 // sig#0 ------------------------------------------------------- |
714 kDeclSignatures, 2, 0, 0, // void -> void | 711 kDeclSignatures, 2, 0, 0, // void -> void |
715 0, kLocalI32, // void -> i32 | 712 0, kLocalI32, // void -> i32 |
716 // func#0 ------------------------------------------------------ | 713 // func#0 ------------------------------------------------------ |
717 kDeclFunctions, 4, FUNCTION(0, 1), // -- | 714 kDeclFunctions, 4, FUNCTION(0, 1), // -- |
718 FUNCTION(1, 1), // -- | 715 FUNCTION(1, 1), // -- |
719 FUNCTION(0, 1), // -- | 716 FUNCTION(0, 1), // -- |
720 FUNCTION(1, 1), // -- | 717 FUNCTION(1, 1), // -- |
721 // indirect table ---------------------------------------------- | 718 // indirect table ---------------------------------------------- |
722 kDeclFunctionTable, 8, | 719 kDeclFunctionTable, 8, |
723 U16_LE(0), // -- | 720 U32V_1(0), // -- |
724 U16_LE(1), // -- | 721 U32V_1(1), // -- |
725 U16_LE(2), // -- | 722 U32V_1(2), // -- |
726 U16_LE(3), // -- | 723 U32V_1(3), // -- |
727 U16_LE(0), // -- | 724 U32V_1(0), // -- |
728 U16_LE(1), // -- | 725 U32V_1(1), // -- |
729 U16_LE(2), // -- | 726 U32V_1(2), // -- |
730 U16_LE(3), // -- | 727 U32V_1(3), // -- |
731 }; | 728 }; |
732 | 729 |
733 ModuleResult result = DecodeModule(data, data + arraysize(data)); | 730 ModuleResult result = DecodeModule(data, data + arraysize(data)); |
734 EXPECT_TRUE(result.ok()); | 731 EXPECT_TRUE(result.ok()); |
735 if (result.ok()) { | 732 if (result.ok()) { |
736 EXPECT_EQ(2, result.val->signatures.size()); | 733 EXPECT_EQ(2, result.val->signatures.size()); |
737 EXPECT_EQ(4, result.val->functions.size()); | 734 EXPECT_EQ(4, result.val->functions.size()); |
738 EXPECT_EQ(8, result.val->function_table.size()); | 735 EXPECT_EQ(8, result.val->function_table.size()); |
739 for (int i = 0; i < 8; i++) { | 736 for (int i = 0; i < 8; i++) { |
740 EXPECT_EQ(i & 3, result.val->function_table[i]); | 737 EXPECT_EQ(i & 3, result.val->function_table[i]); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 EXPECT_FAILURE(data); | 1078 EXPECT_FAILURE(data); |
1082 } | 1079 } |
1083 | 1080 |
1084 TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) { | 1081 TEST_F(WasmModuleVerifyTest, ImportTable_one_sig) { |
1085 static const byte data[] = { | 1082 static const byte data[] = { |
1086 kDeclSignatures, | 1083 kDeclSignatures, |
1087 1, | 1084 1, |
1088 VOID_VOID_SIG, | 1085 VOID_VOID_SIG, |
1089 kDeclImportTable, | 1086 kDeclImportTable, |
1090 1, // -- | 1087 1, // -- |
1091 SIG_INDEX(0), // sig index | 1088 U32V_1(0), // sig index |
1092 NAME_OFFSET(1), // module name | 1089 NAME_OFFSET(1), // module name |
1093 NAME_OFFSET(1) // function name | 1090 NAME_OFFSET(1) // function name |
1094 }; | 1091 }; |
1095 EXPECT_VERIFIES(data); | 1092 EXPECT_VERIFIES(data); |
1096 } | 1093 } |
1097 | 1094 |
1098 TEST_F(WasmModuleVerifyTest, ImportTable_off_end) { | 1095 TEST_F(WasmModuleVerifyTest, ImportTable_off_end) { |
1099 static const byte data[] = { | 1096 static const byte data[] = { |
1100 kDeclSignatures, 1, VOID_VOID_SIG, kDeclImportTable, 1, | 1097 kDeclSignatures, 1, VOID_VOID_SIG, kDeclImportTable, 1, |
1101 SIG_INDEX(0), // sig index | 1098 SIG_INDEX(0), // sig index |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 for (int length = 13; length < sizeof(data); length++) { | 1202 for (int length = 13; length < sizeof(data); length++) { |
1206 ModuleResult result = DecodeModule(data, data + length); | 1203 ModuleResult result = DecodeModule(data, data + length); |
1207 EXPECT_FALSE(result.ok()); | 1204 EXPECT_FALSE(result.ok()); |
1208 if (result.val) delete result.val; | 1205 if (result.val) delete result.val; |
1209 } | 1206 } |
1210 } | 1207 } |
1211 | 1208 |
1212 } // namespace wasm | 1209 } // namespace wasm |
1213 } // namespace internal | 1210 } // namespace internal |
1214 } // namespace v8 | 1211 } // namespace v8 |
OLD | NEW |