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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } | 59 } |
60 | 60 |
61 struct LocalTypePair { | 61 struct LocalTypePair { |
62 uint8_t code; | 62 uint8_t code; |
63 LocalType type; | 63 LocalType type; |
64 } kLocalTypes[] = {{kLocalI32, kAstI32}, | 64 } kLocalTypes[] = {{kLocalI32, kAstI32}, |
65 {kLocalI64, kAstI64}, | 65 {kLocalI64, kAstI64}, |
66 {kLocalF32, kAstF32}, | 66 {kLocalF32, kAstF32}, |
67 {kLocalF64, kAstF64}}; | 67 {kLocalF64, kAstF64}}; |
68 | 68 |
69 class WasmModuleVerifyTest : public TestWithZone { | 69 class WasmModuleVerifyTest : public TestWithIsolateAndZone { |
70 public: | 70 public: |
71 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { | 71 ModuleResult DecodeModule(const byte* module_start, const byte* module_end) { |
72 // Add the WASM magic and version number automatically. | 72 // Add the WASM magic and version number automatically. |
73 size_t size = static_cast<size_t>(module_end - module_start); | 73 size_t size = static_cast<size_t>(module_end - module_start); |
74 byte header[] = {WASM_MODULE_HEADER}; | 74 byte header[] = {WASM_MODULE_HEADER}; |
75 size_t total = sizeof(header) + size; | 75 size_t total = sizeof(header) + size; |
76 auto temp = new byte[total]; | 76 auto temp = new byte[total]; |
77 memcpy(temp, header, sizeof(header)); | 77 memcpy(temp, header, sizeof(header)); |
78 memcpy(temp + sizeof(header), module_start, size); | 78 memcpy(temp + sizeof(header), module_start, size); |
79 ModuleResult result = DecodeWasmModule(nullptr, zone(), temp, temp + total, | 79 ModuleResult result = DecodeWasmModule(isolate(), zone(), temp, |
80 false, kWasmOrigin); | 80 temp + total, false, kWasmOrigin); |
81 delete[] temp; | 81 delete[] temp; |
82 return result; | 82 return result; |
83 } | 83 } |
84 ModuleResult DecodeModuleNoHeader(const byte* module_start, | 84 ModuleResult DecodeModuleNoHeader(const byte* module_start, |
85 const byte* module_end) { | 85 const byte* module_end) { |
86 return DecodeWasmModule(nullptr, zone(), module_start, module_end, false, | 86 return DecodeWasmModule(isolate(), zone(), module_start, module_end, false, |
87 kWasmOrigin); | 87 kWasmOrigin); |
88 } | 88 } |
89 }; | 89 }; |
90 | 90 |
91 TEST_F(WasmModuleVerifyTest, WrongMagic) { | 91 TEST_F(WasmModuleVerifyTest, WrongMagic) { |
92 for (uint32_t x = 1; x; x <<= 1) { | 92 for (uint32_t x = 1; x; x <<= 1) { |
93 const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion), | 93 const byte data[] = {U32_LE(kWasmMagic ^ x), U32_LE(kWasmVersion), |
94 SECTION(END, 0)}; | 94 SECTION(END, 0)}; |
95 ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); | 95 ModuleResult result = DecodeModuleNoHeader(data, data + sizeof(data)); |
96 EXPECT_FALSE(result.ok()); | 96 EXPECT_FALSE(result.ok()); |
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 static const int kParamCount = 3; | 894 static const int kParamCount = 3; |
895 for (int i = 0; i < kParamCount; i++) { | 895 for (int i = 0; i < kParamCount; i++) { |
896 byte data[] = {kParamCount, kLocalI32, kLocalI32, kLocalI32, kLocalI32}; | 896 byte data[] = {kParamCount, kLocalI32, kLocalI32, kLocalI32, kLocalI32}; |
897 data[i + 2] = kLocalVoid; | 897 data[i + 2] = kLocalVoid; |
898 FunctionSig* sig = | 898 FunctionSig* sig = |
899 DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); | 899 DecodeWasmSignatureForTesting(zone(), data, data + arraysize(data)); |
900 EXPECT_EQ(nullptr, sig); | 900 EXPECT_EQ(nullptr, sig); |
901 } | 901 } |
902 } | 902 } |
903 | 903 |
904 | 904 class WasmFunctionVerifyTest : public TestWithIsolateAndZone {}; |
905 class WasmFunctionVerifyTest : public TestWithZone {}; | |
906 | |
907 | 905 |
908 TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { | 906 TEST_F(WasmFunctionVerifyTest, Ok_v_v_empty) { |
909 static const byte data[] = { | 907 static const byte data[] = { |
910 0, kLocalVoid, // signature | 908 0, kLocalVoid, // signature |
911 4, // locals | 909 4, // locals |
912 3, kLocalI32, // -- | 910 3, kLocalI32, // -- |
913 4, kLocalI64, // -- | 911 4, kLocalI64, // -- |
914 5, kLocalF32, // -- | 912 5, kLocalF32, // -- |
915 6, kLocalF64, // -- | 913 6, kLocalF64, // -- |
916 kExprNop // body | 914 kExprNop // body |
917 }; | 915 }; |
918 | 916 |
919 FunctionResult result = DecodeWasmFunction(nullptr, zone(), nullptr, data, | 917 FunctionResult result = DecodeWasmFunction(isolate(), zone(), nullptr, data, |
920 data + arraysize(data)); | 918 data + arraysize(data)); |
921 EXPECT_TRUE(result.ok()); | 919 EXPECT_TRUE(result.ok()); |
922 | 920 |
923 if (result.val && result.ok()) { | 921 if (result.val && result.ok()) { |
924 WasmFunction* function = result.val; | 922 WasmFunction* function = result.val; |
925 EXPECT_EQ(0, function->sig->parameter_count()); | 923 EXPECT_EQ(0, function->sig->parameter_count()); |
926 EXPECT_EQ(0, function->sig->return_count()); | 924 EXPECT_EQ(0, function->sig->return_count()); |
927 EXPECT_EQ(0, function->name_offset); | 925 EXPECT_EQ(0, function->name_offset); |
928 EXPECT_EQ(2, function->code_start_offset); | 926 EXPECT_EQ(2, function->code_start_offset); |
929 EXPECT_EQ(arraysize(data), function->code_end_offset); | 927 EXPECT_EQ(arraysize(data), function->code_end_offset); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 NO_LOCAL_NAMES, // -- | 1368 NO_LOCAL_NAMES, // -- |
1371 FOO_STRING, | 1369 FOO_STRING, |
1372 NO_LOCAL_NAMES, // -- | 1370 NO_LOCAL_NAMES, // -- |
1373 }; | 1371 }; |
1374 EXPECT_VERIFIES(data); | 1372 EXPECT_VERIFIES(data); |
1375 } | 1373 } |
1376 | 1374 |
1377 } // namespace wasm | 1375 } // namespace wasm |
1378 } // namespace internal | 1376 } // namespace internal |
1379 } // namespace v8 | 1377 } // namespace v8 |
OLD | NEW |