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/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "test/common/wasm/test-signatures.h" | 9 #include "test/common/wasm/test-signatures.h" |
10 | 10 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (types[0] != ret_type || types[1] != param_type) { | 194 if (types[0] != ret_type || types[1] != param_type) { |
195 // Test signature mismatch. | 195 // Test signature mismatch. |
196 FunctionSig sig(1, 1, types); | 196 FunctionSig sig(1, 1, types); |
197 EXPECT_FAILURE_SC(&sig, code); | 197 EXPECT_FAILURE_SC(&sig, code); |
198 } | 198 } |
199 } | 199 } |
200 } | 200 } |
201 } | 201 } |
202 }; | 202 }; |
203 | 203 |
| 204 namespace { |
| 205 // A helper for tests that require a module environment for functions, |
| 206 // globals, or memories. |
| 207 class TestModuleEnv : public ModuleEnv { |
| 208 public: |
| 209 explicit TestModuleEnv(ModuleOrigin origin = kWasmOrigin) |
| 210 : ModuleEnv(&mod, nullptr) { |
| 211 mod.origin = origin; |
| 212 } |
| 213 byte AddGlobal(ValueType type, bool mutability = true) { |
| 214 mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false}); |
| 215 CHECK(mod.globals.size() <= 127); |
| 216 return static_cast<byte>(mod.globals.size() - 1); |
| 217 } |
| 218 byte AddSignature(FunctionSig* sig) { |
| 219 mod.signatures.push_back(sig); |
| 220 CHECK(mod.signatures.size() <= 127); |
| 221 return static_cast<byte>(mod.signatures.size() - 1); |
| 222 } |
| 223 byte AddFunction(FunctionSig* sig) { |
| 224 mod.functions.push_back({sig, // sig |
| 225 0, // func_index |
| 226 0, // sig_index |
| 227 0, // name_offset |
| 228 0, // name_length |
| 229 0, // code_start_offset |
| 230 0, // code_end_offset |
| 231 false, // import |
| 232 false}); // export |
| 233 CHECK(mod.functions.size() <= 127); |
| 234 return static_cast<byte>(mod.functions.size() - 1); |
| 235 } |
| 236 byte AddImport(FunctionSig* sig) { |
| 237 byte result = AddFunction(sig); |
| 238 mod.functions[result].imported = true; |
| 239 return result; |
| 240 } |
| 241 |
| 242 void InitializeMemory() { |
| 243 mod.has_memory = true; |
| 244 mod.min_mem_pages = 1; |
| 245 mod.max_mem_pages = 100; |
| 246 } |
| 247 |
| 248 void InitializeFunctionTable() { |
| 249 mod.function_tables.push_back( |
| 250 {0, 0, true, std::vector<int32_t>(), false, false, SignatureMap()}); |
| 251 } |
| 252 |
| 253 private: |
| 254 WasmModule mod; |
| 255 }; |
| 256 } // namespace |
| 257 |
204 TEST_F(FunctionBodyDecoderTest, Int32Const1) { | 258 TEST_F(FunctionBodyDecoderTest, Int32Const1) { |
205 byte code[] = {kExprI32Const, 0}; | 259 byte code[] = {kExprI32Const, 0}; |
206 for (int i = -64; i <= 63; i++) { | 260 for (int i = -64; i <= 63; i++) { |
207 code[1] = static_cast<byte>(i & 0x7F); | 261 code[1] = static_cast<byte>(i & 0x7F); |
208 EXPECT_VERIFIES_C(i_i, code); | 262 EXPECT_VERIFIES_C(i_i, code); |
209 } | 263 } |
210 } | 264 } |
211 | 265 |
212 TEST_F(FunctionBodyDecoderTest, EmptyFunction) { | 266 TEST_F(FunctionBodyDecoderTest, EmptyFunction) { |
213 byte code[] = {0}; | 267 byte code[] = {0}; |
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 TestUnop(kExprI32UConvertF64, kWasmI32, kWasmF64); | 1070 TestUnop(kExprI32UConvertF64, kWasmI32, kWasmF64); |
1017 TestUnop(kExprF64SConvertI32, kWasmF64, kWasmI32); | 1071 TestUnop(kExprF64SConvertI32, kWasmF64, kWasmI32); |
1018 TestUnop(kExprF64UConvertI32, kWasmF64, kWasmI32); | 1072 TestUnop(kExprF64UConvertI32, kWasmF64, kWasmI32); |
1019 TestUnop(kExprF64ConvertF32, kWasmF64, kWasmF32); | 1073 TestUnop(kExprF64ConvertF32, kWasmF64, kWasmF32); |
1020 TestUnop(kExprF32SConvertI32, kWasmF32, kWasmI32); | 1074 TestUnop(kExprF32SConvertI32, kWasmF32, kWasmI32); |
1021 TestUnop(kExprF32UConvertI32, kWasmF32, kWasmI32); | 1075 TestUnop(kExprF32UConvertI32, kWasmF32, kWasmI32); |
1022 TestUnop(kExprF32ConvertF64, kWasmF32, kWasmF64); | 1076 TestUnop(kExprF32ConvertF64, kWasmF32, kWasmF64); |
1023 } | 1077 } |
1024 | 1078 |
1025 TEST_F(FunctionBodyDecoderTest, MacrosStmt) { | 1079 TEST_F(FunctionBodyDecoderTest, MacrosStmt) { |
| 1080 TestModuleEnv module_env; |
| 1081 module = &module_env; |
| 1082 module_env.InitializeMemory(); |
1026 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); | 1083 EXPECT_VERIFIES(v_i, WASM_SET_LOCAL(0, WASM_I32V_3(87348))); |
1027 EXPECT_VERIFIES(v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(24), | 1084 EXPECT_VERIFIES(v_i, WASM_STORE_MEM(MachineType::Int32(), WASM_I32V_1(24), |
1028 WASM_I32V_1(40))); | 1085 WASM_I32V_1(40))); |
1029 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); | 1086 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); |
1030 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); | 1087 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); |
1031 EXPECT_VERIFIES(v_v, WASM_NOP); | 1088 EXPECT_VERIFIES(v_v, WASM_NOP); |
1032 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); | 1089 EXPECT_VERIFIES(v_v, B1(WASM_NOP)); |
1033 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); | 1090 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_NOP)); |
1034 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); | 1091 EXPECT_VERIFIES(v_v, WASM_LOOP(WASM_BR(0))); |
1035 } | 1092 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 TestBinop(kExpr##name, sig); \ | 1209 TestBinop(kExpr##name, sig); \ |
1153 } \ | 1210 } \ |
1154 } | 1211 } |
1155 | 1212 |
1156 FOREACH_SIMPLE_OPCODE(DECODE_TEST); | 1213 FOREACH_SIMPLE_OPCODE(DECODE_TEST); |
1157 | 1214 |
1158 #undef DECODE_TEST | 1215 #undef DECODE_TEST |
1159 } | 1216 } |
1160 | 1217 |
1161 TEST_F(FunctionBodyDecoderTest, MemorySize) { | 1218 TEST_F(FunctionBodyDecoderTest, MemorySize) { |
| 1219 TestModuleEnv module_env; |
| 1220 module = &module_env; |
| 1221 module_env.InitializeMemory(); |
1162 byte code[] = {kExprMemorySize, 0}; | 1222 byte code[] = {kExprMemorySize, 0}; |
1163 EXPECT_VERIFIES_C(i_i, code); | 1223 EXPECT_VERIFIES_C(i_i, code); |
1164 EXPECT_FAILURE_C(f_ff, code); | 1224 EXPECT_FAILURE_C(f_ff, code); |
1165 } | 1225 } |
1166 | 1226 |
1167 TEST_F(FunctionBodyDecoderTest, LoadMemOffset) { | 1227 TEST_F(FunctionBodyDecoderTest, LoadMemOffset) { |
| 1228 TestModuleEnv module_env; |
| 1229 module = &module_env; |
| 1230 module_env.InitializeMemory(); |
1168 for (int offset = 0; offset < 128; offset += 7) { | 1231 for (int offset = 0; offset < 128; offset += 7) { |
1169 byte code[] = {kExprI32Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, | 1232 byte code[] = {kExprI32Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, |
1170 static_cast<byte>(offset)}; | 1233 static_cast<byte>(offset)}; |
1171 EXPECT_VERIFIES_C(i_i, code); | 1234 EXPECT_VERIFIES_C(i_i, code); |
1172 } | 1235 } |
1173 } | 1236 } |
1174 | 1237 |
1175 TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) { | 1238 TEST_F(FunctionBodyDecoderTest, LoadMemAlignment) { |
| 1239 TestModuleEnv module_env; |
| 1240 module = &module_env; |
| 1241 module_env.InitializeMemory(); |
1176 struct { | 1242 struct { |
1177 WasmOpcode instruction; | 1243 WasmOpcode instruction; |
1178 uint32_t maximum_aligment; | 1244 uint32_t maximum_aligment; |
1179 } values[] = { | 1245 } values[] = { |
1180 {kExprI32LoadMem8U, 0}, // -- | 1246 {kExprI32LoadMem8U, 0}, // -- |
1181 {kExprI32LoadMem8S, 0}, // -- | 1247 {kExprI32LoadMem8S, 0}, // -- |
1182 {kExprI32LoadMem16U, 1}, // -- | 1248 {kExprI32LoadMem16U, 1}, // -- |
1183 {kExprI32LoadMem16S, 1}, // -- | 1249 {kExprI32LoadMem16S, 1}, // -- |
1184 {kExprI64LoadMem8U, 0}, // -- | 1250 {kExprI64LoadMem8U, 0}, // -- |
1185 {kExprI64LoadMem8S, 0}, // -- | 1251 {kExprI64LoadMem8S, 0}, // -- |
(...skipping 14 matching lines...) Expand all Loading... |
1200 if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { | 1266 if (static_cast<uint32_t>(alignment) <= values[i].maximum_aligment) { |
1201 EXPECT_VERIFIES_C(v_i, code); | 1267 EXPECT_VERIFIES_C(v_i, code); |
1202 } else { | 1268 } else { |
1203 EXPECT_FAILURE_C(v_i, code); | 1269 EXPECT_FAILURE_C(v_i, code); |
1204 } | 1270 } |
1205 } | 1271 } |
1206 } | 1272 } |
1207 } | 1273 } |
1208 | 1274 |
1209 TEST_F(FunctionBodyDecoderTest, StoreMemOffset) { | 1275 TEST_F(FunctionBodyDecoderTest, StoreMemOffset) { |
| 1276 TestModuleEnv module_env; |
| 1277 module = &module_env; |
| 1278 module_env.InitializeMemory(); |
1210 for (int offset = 0; offset < 128; offset += 7) { | 1279 for (int offset = 0; offset < 128; offset += 7) { |
1211 byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, | 1280 byte code[] = {WASM_STORE_MEM_OFFSET(MachineType::Int32(), offset, |
1212 WASM_ZERO, WASM_ZERO)}; | 1281 WASM_ZERO, WASM_ZERO)}; |
1213 EXPECT_VERIFIES_C(v_i, code); | 1282 EXPECT_VERIFIES_C(v_i, code); |
1214 } | 1283 } |
1215 } | 1284 } |
1216 | 1285 |
1217 TEST_F(FunctionBodyDecoderTest, StoreMemOffset_void) { | 1286 TEST_F(FunctionBodyDecoderTest, StoreMemOffset_void) { |
| 1287 TestModuleEnv module_env; |
| 1288 module = &module_env; |
| 1289 module_env.InitializeMemory(); |
1218 EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO, | 1290 EXPECT_FAILURE(i_i, WASM_STORE_MEM_OFFSET(MachineType::Int32(), 0, WASM_ZERO, |
1219 WASM_ZERO)); | 1291 WASM_ZERO)); |
1220 } | 1292 } |
1221 | 1293 |
1222 #define BYTE0(x) ((x)&0x7F) | 1294 #define BYTE0(x) ((x)&0x7F) |
1223 #define BYTE1(x) ((x >> 7) & 0x7F) | 1295 #define BYTE1(x) ((x >> 7) & 0x7F) |
1224 #define BYTE2(x) ((x >> 14) & 0x7F) | 1296 #define BYTE2(x) ((x >> 14) & 0x7F) |
1225 #define BYTE3(x) ((x >> 21) & 0x7F) | 1297 #define BYTE3(x) ((x >> 21) & 0x7F) |
1226 | 1298 |
1227 #define VARINT1(x) BYTE0(x) | 1299 #define VARINT1(x) BYTE0(x) |
1228 #define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x) | 1300 #define VARINT2(x) BYTE0(x) | 0x80, BYTE1(x) |
1229 #define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 1301 #define VARINT3(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) |
1230 #define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x) | 1302 #define VARINT4(x) BYTE0(x) | 0x80, BYTE1(x) | 0x80, BYTE2(x) | 0x80, BYTE3(x) |
1231 | 1303 |
1232 TEST_F(FunctionBodyDecoderTest, LoadMemOffset_varint) { | 1304 TEST_F(FunctionBodyDecoderTest, LoadMemOffset_varint) { |
| 1305 TestModuleEnv module_env; |
| 1306 module = &module_env; |
| 1307 module_env.InitializeMemory(); |
1233 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1308 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1234 VARINT1(0x45)); | 1309 VARINT1(0x45)); |
1235 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1310 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1236 VARINT2(0x3999)); | 1311 VARINT2(0x3999)); |
1237 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1312 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1238 VARINT3(0x344445)); | 1313 VARINT3(0x344445)); |
1239 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, | 1314 EXPECT_VERIFIES(i_i, WASM_ZERO, kExprI32LoadMem, ZERO_ALIGNMENT, |
1240 VARINT4(0x36666667)); | 1315 VARINT4(0x36666667)); |
1241 } | 1316 } |
1242 | 1317 |
1243 TEST_F(FunctionBodyDecoderTest, StoreMemOffset_varint) { | 1318 TEST_F(FunctionBodyDecoderTest, StoreMemOffset_varint) { |
| 1319 TestModuleEnv module_env; |
| 1320 module = &module_env; |
| 1321 module_env.InitializeMemory(); |
1244 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1322 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1245 VARINT1(0x33)); | 1323 VARINT1(0x33)); |
1246 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1324 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1247 VARINT2(0x1111)); | 1325 VARINT2(0x1111)); |
1248 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1326 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1249 VARINT3(0x222222)); | 1327 VARINT3(0x222222)); |
1250 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, | 1328 EXPECT_VERIFIES(v_i, WASM_ZERO, WASM_ZERO, kExprI32StoreMem, ZERO_ALIGNMENT, |
1251 VARINT4(0x44444444)); | 1329 VARINT4(0x44444444)); |
1252 } | 1330 } |
1253 | 1331 |
1254 TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) { | 1332 TEST_F(FunctionBodyDecoderTest, AllLoadMemCombinations) { |
| 1333 TestModuleEnv module_env; |
| 1334 module = &module_env; |
| 1335 module_env.InitializeMemory(); |
1255 for (size_t i = 0; i < arraysize(kValueTypes); i++) { | 1336 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1256 ValueType local_type = kValueTypes[i]; | 1337 ValueType local_type = kValueTypes[i]; |
1257 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1338 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1258 MachineType mem_type = machineTypes[j]; | 1339 MachineType mem_type = machineTypes[j]; |
1259 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; | 1340 byte code[] = {WASM_LOAD_MEM(mem_type, WASM_ZERO)}; |
1260 FunctionSig sig(1, 0, &local_type); | 1341 FunctionSig sig(1, 0, &local_type); |
1261 if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) { | 1342 if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) { |
1262 EXPECT_VERIFIES_SC(&sig, code); | 1343 EXPECT_VERIFIES_SC(&sig, code); |
1263 } else { | 1344 } else { |
1264 EXPECT_FAILURE_SC(&sig, code); | 1345 EXPECT_FAILURE_SC(&sig, code); |
1265 } | 1346 } |
1266 } | 1347 } |
1267 } | 1348 } |
1268 } | 1349 } |
1269 | 1350 |
1270 TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) { | 1351 TEST_F(FunctionBodyDecoderTest, AllStoreMemCombinations) { |
| 1352 TestModuleEnv module_env; |
| 1353 module = &module_env; |
| 1354 module_env.InitializeMemory(); |
1271 for (size_t i = 0; i < arraysize(kValueTypes); i++) { | 1355 for (size_t i = 0; i < arraysize(kValueTypes); i++) { |
1272 ValueType local_type = kValueTypes[i]; | 1356 ValueType local_type = kValueTypes[i]; |
1273 for (size_t j = 0; j < arraysize(machineTypes); j++) { | 1357 for (size_t j = 0; j < arraysize(machineTypes); j++) { |
1274 MachineType mem_type = machineTypes[j]; | 1358 MachineType mem_type = machineTypes[j]; |
1275 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; | 1359 byte code[] = {WASM_STORE_MEM(mem_type, WASM_ZERO, WASM_GET_LOCAL(0))}; |
1276 FunctionSig sig(0, 1, &local_type); | 1360 FunctionSig sig(0, 1, &local_type); |
1277 if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) { | 1361 if (local_type == WasmOpcodes::ValueTypeFor(mem_type)) { |
1278 EXPECT_VERIFIES_SC(&sig, code); | 1362 EXPECT_VERIFIES_SC(&sig, code); |
1279 } else { | 1363 } else { |
1280 EXPECT_FAILURE_SC(&sig, code); | 1364 EXPECT_FAILURE_SC(&sig, code); |
1281 } | 1365 } |
1282 } | 1366 } |
1283 } | 1367 } |
1284 } | 1368 } |
1285 | 1369 |
1286 namespace { | |
1287 // A helper for tests that require a module environment for functions and | |
1288 // globals. | |
1289 class TestModuleEnv : public ModuleEnv { | |
1290 public: | |
1291 explicit TestModuleEnv(ModuleOrigin origin = kWasmOrigin) | |
1292 : ModuleEnv(&mod, nullptr) { | |
1293 mod.origin = origin; | |
1294 } | |
1295 byte AddGlobal(ValueType type, bool mutability = true) { | |
1296 mod.globals.push_back({type, mutability, WasmInitExpr(), 0, false, false}); | |
1297 CHECK(mod.globals.size() <= 127); | |
1298 return static_cast<byte>(mod.globals.size() - 1); | |
1299 } | |
1300 byte AddSignature(FunctionSig* sig) { | |
1301 mod.signatures.push_back(sig); | |
1302 CHECK(mod.signatures.size() <= 127); | |
1303 return static_cast<byte>(mod.signatures.size() - 1); | |
1304 } | |
1305 byte AddFunction(FunctionSig* sig) { | |
1306 mod.functions.push_back({sig, // sig | |
1307 0, // func_index | |
1308 0, // sig_index | |
1309 0, // name_offset | |
1310 0, // name_length | |
1311 0, // code_start_offset | |
1312 0, // code_end_offset | |
1313 false, // import | |
1314 false}); // export | |
1315 CHECK(mod.functions.size() <= 127); | |
1316 return static_cast<byte>(mod.functions.size() - 1); | |
1317 } | |
1318 byte AddImport(FunctionSig* sig) { | |
1319 byte result = AddFunction(sig); | |
1320 mod.functions[result].imported = true; | |
1321 return result; | |
1322 } | |
1323 | |
1324 void InitializeFunctionTable() { | |
1325 mod.function_tables.push_back( | |
1326 {0, 0, true, std::vector<int32_t>(), false, false, SignatureMap()}); | |
1327 } | |
1328 | |
1329 private: | |
1330 WasmModule mod; | |
1331 }; | |
1332 } // namespace | |
1333 | |
1334 TEST_F(FunctionBodyDecoderTest, SimpleCalls) { | 1370 TEST_F(FunctionBodyDecoderTest, SimpleCalls) { |
1335 FunctionSig* sig = sigs.i_i(); | 1371 FunctionSig* sig = sigs.i_i(); |
1336 TestModuleEnv module_env; | 1372 TestModuleEnv module_env; |
1337 module = &module_env; | 1373 module = &module_env; |
1338 | 1374 |
1339 module_env.AddFunction(sigs.i_v()); | 1375 module_env.AddFunction(sigs.i_v()); |
1340 module_env.AddFunction(sigs.i_i()); | 1376 module_env.AddFunction(sigs.i_i()); |
1341 module_env.AddFunction(sigs.i_ii()); | 1377 module_env.AddFunction(sigs.i_ii()); |
1342 | 1378 |
1343 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); | 1379 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(0)); |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1658 } else { | 1694 } else { |
1659 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); | 1695 EXPECT_FAILURE_S(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); |
1660 } | 1696 } |
1661 } | 1697 } |
1662 } | 1698 } |
1663 } | 1699 } |
1664 | 1700 |
1665 TEST_F(FunctionBodyDecoderTest, WasmGrowMemory) { | 1701 TEST_F(FunctionBodyDecoderTest, WasmGrowMemory) { |
1666 TestModuleEnv module_env; | 1702 TestModuleEnv module_env; |
1667 module = &module_env; | 1703 module = &module_env; |
| 1704 module_env.InitializeMemory(); |
1668 | 1705 |
1669 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; | 1706 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; |
1670 EXPECT_VERIFIES_C(i_i, code); | 1707 EXPECT_VERIFIES_C(i_i, code); |
1671 EXPECT_FAILURE_C(i_d, code); | 1708 EXPECT_FAILURE_C(i_d, code); |
1672 } | 1709 } |
1673 | 1710 |
1674 TEST_F(FunctionBodyDecoderTest, AsmJsGrowMemory) { | 1711 TEST_F(FunctionBodyDecoderTest, AsmJsGrowMemory) { |
1675 TestModuleEnv module_env(kAsmJsOrigin); | 1712 TestModuleEnv module_env(kAsmJsOrigin); |
1676 module = &module_env; | 1713 module = &module_env; |
| 1714 module_env.InitializeMemory(); |
1677 | 1715 |
1678 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; | 1716 byte code[] = {WASM_GET_LOCAL(0), kExprGrowMemory, 0}; |
1679 EXPECT_FAILURE_C(i_i, code); | 1717 EXPECT_FAILURE_C(i_i, code); |
1680 } | 1718 } |
1681 | 1719 |
1682 TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) { | 1720 TEST_F(FunctionBodyDecoderTest, AsmJsBinOpsCheckOrigin) { |
1683 ValueType float32int32float32[] = {kWasmF32, kWasmI32, kWasmF32}; | 1721 ValueType float32int32float32[] = {kWasmF32, kWasmI32, kWasmF32}; |
1684 FunctionSig sig_f_if(1, 2, float32int32float32); | 1722 FunctionSig sig_f_if(1, 2, float32int32float32); |
1685 ValueType float64int32float64[] = {kWasmF64, kWasmI32, kWasmF64}; | 1723 ValueType float64int32float64[] = {kWasmF64, kWasmI32, kWasmF64}; |
1686 FunctionSig sig_d_id(1, 2, float64int32float64); | 1724 FunctionSig sig_d_id(1, 2, float64int32float64); |
(...skipping 11 matching lines...) Expand all Loading... |
1698 {kExprI32AsmjsStoreMem8, sigs.i_ii()}, | 1736 {kExprI32AsmjsStoreMem8, sigs.i_ii()}, |
1699 {kExprI32AsmjsStoreMem16, sigs.i_ii()}, | 1737 {kExprI32AsmjsStoreMem16, sigs.i_ii()}, |
1700 {kExprI32AsmjsStoreMem, sigs.i_ii()}, | 1738 {kExprI32AsmjsStoreMem, sigs.i_ii()}, |
1701 {kExprF32AsmjsStoreMem, &sig_f_if}, | 1739 {kExprF32AsmjsStoreMem, &sig_f_if}, |
1702 {kExprF64AsmjsStoreMem, &sig_d_id}, | 1740 {kExprF64AsmjsStoreMem, &sig_d_id}, |
1703 }; | 1741 }; |
1704 | 1742 |
1705 { | 1743 { |
1706 TestModuleEnv module_env(kAsmJsOrigin); | 1744 TestModuleEnv module_env(kAsmJsOrigin); |
1707 module = &module_env; | 1745 module = &module_env; |
| 1746 module_env.InitializeMemory(); |
1708 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { | 1747 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { |
1709 TestBinop(AsmJsBinOps[i].op, AsmJsBinOps[i].sig); | 1748 TestBinop(AsmJsBinOps[i].op, AsmJsBinOps[i].sig); |
1710 } | 1749 } |
1711 } | 1750 } |
1712 | 1751 |
1713 { | 1752 { |
1714 TestModuleEnv module_env; | 1753 TestModuleEnv module_env; |
1715 module = &module_env; | 1754 module = &module_env; |
| 1755 module_env.InitializeMemory(); |
1716 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { | 1756 for (size_t i = 0; i < arraysize(AsmJsBinOps); i++) { |
1717 byte code[] = { | 1757 byte code[] = { |
1718 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; | 1758 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; |
1719 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); | 1759 EXPECT_FAILURE_SC(AsmJsBinOps[i].sig, code); |
1720 } | 1760 } |
1721 } | 1761 } |
1722 } | 1762 } |
1723 | 1763 |
1724 TEST_F(FunctionBodyDecoderTest, AsmJsUnOpsCheckOrigin) { | 1764 TEST_F(FunctionBodyDecoderTest, AsmJsUnOpsCheckOrigin) { |
1725 ValueType float32int32[] = {kWasmF32, kWasmI32}; | 1765 ValueType float32int32[] = {kWasmF32, kWasmI32}; |
(...skipping 18 matching lines...) Expand all Loading... |
1744 {kExprI32AsmjsLoadMem, sigs.i_i()}, | 1784 {kExprI32AsmjsLoadMem, sigs.i_i()}, |
1745 {kExprF32AsmjsLoadMem, &sig_f_i}, | 1785 {kExprF32AsmjsLoadMem, &sig_f_i}, |
1746 {kExprF64AsmjsLoadMem, &sig_d_i}, | 1786 {kExprF64AsmjsLoadMem, &sig_d_i}, |
1747 {kExprI32AsmjsSConvertF32, sigs.i_f()}, | 1787 {kExprI32AsmjsSConvertF32, sigs.i_f()}, |
1748 {kExprI32AsmjsUConvertF32, sigs.i_f()}, | 1788 {kExprI32AsmjsUConvertF32, sigs.i_f()}, |
1749 {kExprI32AsmjsSConvertF64, sigs.i_d()}, | 1789 {kExprI32AsmjsSConvertF64, sigs.i_d()}, |
1750 {kExprI32AsmjsUConvertF64, sigs.i_d()}}; | 1790 {kExprI32AsmjsUConvertF64, sigs.i_d()}}; |
1751 { | 1791 { |
1752 TestModuleEnv module_env(kAsmJsOrigin); | 1792 TestModuleEnv module_env(kAsmJsOrigin); |
1753 module = &module_env; | 1793 module = &module_env; |
| 1794 module_env.InitializeMemory(); |
1754 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { | 1795 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { |
1755 TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig); | 1796 TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig); |
1756 } | 1797 } |
1757 } | 1798 } |
1758 | 1799 |
1759 { | 1800 { |
1760 TestModuleEnv module_env; | 1801 TestModuleEnv module_env; |
1761 module = &module_env; | 1802 module = &module_env; |
| 1803 module_env.InitializeMemory(); |
1762 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { | 1804 for (size_t i = 0; i < arraysize(AsmJsUnOps); i++) { |
1763 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; | 1805 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))}; |
1764 EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); | 1806 EXPECT_FAILURE_SC(AsmJsUnOps[i].sig, code); |
1765 } | 1807 } |
1766 } | 1808 } |
1767 } | 1809 } |
1768 | 1810 |
1769 TEST_F(FunctionBodyDecoderTest, BreakEnd) { | 1811 TEST_F(FunctionBodyDecoderTest, BreakEnd) { |
1770 EXPECT_VERIFIES( | 1812 EXPECT_VERIFIES( |
1771 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); | 1813 i_i, WASM_BLOCK_I(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); |
(...skipping 951 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2723 iter.next(); | 2765 iter.next(); |
2724 EXPECT_TRUE(iter.has_next()); | 2766 EXPECT_TRUE(iter.has_next()); |
2725 EXPECT_EQ(kExprI32Const, iter.current()); | 2767 EXPECT_EQ(kExprI32Const, iter.current()); |
2726 iter.next(); | 2768 iter.next(); |
2727 EXPECT_FALSE(iter.has_next()); | 2769 EXPECT_FALSE(iter.has_next()); |
2728 } | 2770 } |
2729 | 2771 |
2730 } // namespace wasm | 2772 } // namespace wasm |
2731 } // namespace internal | 2773 } // namespace internal |
2732 } // namespace v8 | 2774 } // namespace v8 |
OLD | NEW |