Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Side by Side Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 1709653002: [wasm] Add support for import section. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: delete the import_code vector Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/cctest/wasm/test-signatures.h" 9 #include "test/cctest/wasm/test-signatures.h"
10 10
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 // globals. 1185 // globals.
1186 class TestModuleEnv : public ModuleEnv { 1186 class TestModuleEnv : public ModuleEnv {
1187 public: 1187 public:
1188 TestModuleEnv() { 1188 TestModuleEnv() {
1189 instance = nullptr; 1189 instance = nullptr;
1190 module = &mod; 1190 module = &mod;
1191 linker = nullptr; 1191 linker = nullptr;
1192 mod.globals = new std::vector<WasmGlobal>; 1192 mod.globals = new std::vector<WasmGlobal>;
1193 mod.signatures = new std::vector<FunctionSig*>; 1193 mod.signatures = new std::vector<FunctionSig*>;
1194 mod.functions = new std::vector<WasmFunction>; 1194 mod.functions = new std::vector<WasmFunction>;
1195 mod.import_table = new std::vector<WasmImport>;
1195 } 1196 }
1196 byte AddGlobal(MachineType mem_type) { 1197 byte AddGlobal(MachineType mem_type) {
1197 mod.globals->push_back({0, mem_type, 0, false}); 1198 mod.globals->push_back({0, mem_type, 0, false});
1198 CHECK(mod.globals->size() <= 127); 1199 CHECK(mod.globals->size() <= 127);
1199 return static_cast<byte>(mod.globals->size() - 1); 1200 return static_cast<byte>(mod.globals->size() - 1);
1200 } 1201 }
1201 byte AddSignature(FunctionSig* sig) { 1202 byte AddSignature(FunctionSig* sig) {
1202 mod.signatures->push_back(sig); 1203 mod.signatures->push_back(sig);
1203 CHECK(mod.signatures->size() <= 127); 1204 CHECK(mod.signatures->size() <= 127);
1204 return static_cast<byte>(mod.signatures->size() - 1); 1205 return static_cast<byte>(mod.signatures->size() - 1);
1205 } 1206 }
1206 byte AddFunction(FunctionSig* sig) { 1207 byte AddFunction(FunctionSig* sig) {
1207 mod.functions->push_back({sig, 0, 0, 0, 0, 0, 0, 0, false, false}); 1208 mod.functions->push_back({sig, 0, 0, 0, 0, 0, 0, 0, false, false});
1208 CHECK(mod.functions->size() <= 127); 1209 CHECK(mod.functions->size() <= 127);
1209 return static_cast<byte>(mod.functions->size() - 1); 1210 return static_cast<byte>(mod.functions->size() - 1);
1210 } 1211 }
1212 byte AddImport(FunctionSig* sig) {
1213 mod.import_table->push_back({sig, 0, 0});
1214 CHECK(mod.import_table->size() <= 127);
1215 return static_cast<byte>(mod.import_table->size() - 1);
1216 }
1211 1217
1212 private: 1218 private:
1213 WasmModule mod; 1219 WasmModule mod;
1214 }; 1220 };
1215 } // namespace 1221 } // namespace
1216 1222
1217 1223
1218 TEST_F(WasmDecoderTest, SimpleCalls) { 1224 TEST_F(WasmDecoderTest, SimpleCalls) {
1219 FunctionEnv* env = &env_i_i; 1225 FunctionEnv* env = &env_i_i;
1220 TestModuleEnv module_env; 1226 TestModuleEnv module_env;
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I64(27))); 1363 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_I64(27)));
1358 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); 1364 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2)));
1359 1365
1360 byte f1 = module_env.AddFunction(sigs.i_d()); 1366 byte f1 = module_env.AddFunction(sigs.i_d());
1361 1367
1362 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16))); 1368 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I8(16)));
1363 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64(16))); 1369 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_I64(16)));
1364 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6))); 1370 EXPECT_FAILURE_INLINE(env, WASM_CALL_INDIRECT(f1, WASM_ZERO, WASM_F32(17.6)));
1365 } 1371 }
1366 1372
1373 TEST_F(WasmDecoderTest, SimpleImportCalls) {
1374 FunctionEnv* env = &env_i_i;
1375 TestModuleEnv module_env;
1376 env->module = &module_env;
1377
1378 byte f0 = module_env.AddImport(sigs.i_v());
1379 byte f1 = module_env.AddImport(sigs.i_i());
1380 byte f2 = module_env.AddImport(sigs.i_ii());
1381
1382 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT0(f0));
1383 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(22)));
1384 EXPECT_VERIFIES_INLINE(env, WASM_CALL_IMPORT(f2, WASM_I8(32), WASM_I8(72)));
1385 }
1386
1387 TEST_F(WasmDecoderTest, ImportCallsWithMismatchedSigs3) {
1388 FunctionEnv* env = &env_i_i;
1389 TestModuleEnv module_env;
1390 env->module = &module_env;
1391
1392 byte f0 = module_env.AddImport(sigs.i_f());
1393
1394 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f0));
1395 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I8(17)));
1396 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_I64(27)));
1397 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f0, WASM_F64(37.2)));
1398
1399 byte f1 = module_env.AddImport(sigs.i_d());
1400
1401 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT0(f1));
1402 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I8(16)));
1403 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_I64(16)));
1404 EXPECT_FAILURE_INLINE(env, WASM_CALL_IMPORT(f1, WASM_F32(17.6)));
1405 }
1367 1406
1368 TEST_F(WasmDecoderTest, Int32Globals) { 1407 TEST_F(WasmDecoderTest, Int32Globals) {
1369 FunctionEnv* env = &env_i_i; 1408 FunctionEnv* env = &env_i_i;
1370 TestModuleEnv module_env; 1409 TestModuleEnv module_env;
1371 env->module = &module_env; 1410 env->module = &module_env;
1372 1411
1373 module_env.AddGlobal(MachineType::Int8()); 1412 module_env.AddGlobal(MachineType::Int8());
1374 module_env.AddGlobal(MachineType::Uint8()); 1413 module_env.AddGlobal(MachineType::Uint8());
1375 module_env.AddGlobal(MachineType::Int16()); 1414 module_env.AddGlobal(MachineType::Int16());
1376 module_env.AddGlobal(MachineType::Uint16()); 1415 module_env.AddGlobal(MachineType::Uint16());
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 EXPECT_LENGTH(2, kExprI8Const); 2019 EXPECT_LENGTH(2, kExprI8Const);
1981 EXPECT_LENGTH(5, kExprI32Const); 2020 EXPECT_LENGTH(5, kExprI32Const);
1982 EXPECT_LENGTH(5, kExprF32Const); 2021 EXPECT_LENGTH(5, kExprF32Const);
1983 EXPECT_LENGTH(9, kExprI64Const); 2022 EXPECT_LENGTH(9, kExprI64Const);
1984 EXPECT_LENGTH(9, kExprF64Const); 2023 EXPECT_LENGTH(9, kExprF64Const);
1985 EXPECT_LENGTH(2, kExprGetLocal); 2024 EXPECT_LENGTH(2, kExprGetLocal);
1986 EXPECT_LENGTH(2, kExprSetLocal); 2025 EXPECT_LENGTH(2, kExprSetLocal);
1987 EXPECT_LENGTH(2, kExprLoadGlobal); 2026 EXPECT_LENGTH(2, kExprLoadGlobal);
1988 EXPECT_LENGTH(2, kExprStoreGlobal); 2027 EXPECT_LENGTH(2, kExprStoreGlobal);
1989 EXPECT_LENGTH(2, kExprCallFunction); 2028 EXPECT_LENGTH(2, kExprCallFunction);
2029 EXPECT_LENGTH(2, kExprCallImport);
1990 EXPECT_LENGTH(2, kExprCallIndirect); 2030 EXPECT_LENGTH(2, kExprCallIndirect);
1991 EXPECT_LENGTH(1, kExprIf); 2031 EXPECT_LENGTH(1, kExprIf);
1992 EXPECT_LENGTH(1, kExprIfElse); 2032 EXPECT_LENGTH(1, kExprIfElse);
1993 EXPECT_LENGTH(2, kExprBlock); 2033 EXPECT_LENGTH(2, kExprBlock);
1994 EXPECT_LENGTH(2, kExprLoop); 2034 EXPECT_LENGTH(2, kExprLoop);
1995 EXPECT_LENGTH(2, kExprBr); 2035 EXPECT_LENGTH(2, kExprBr);
1996 EXPECT_LENGTH(2, kExprBrIf); 2036 EXPECT_LENGTH(2, kExprBrIf);
1997 } 2037 }
1998 2038
1999 2039
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
2230 2270
2231 TEST_F(WasmOpcodeArityTest, Calls) { 2271 TEST_F(WasmOpcodeArityTest, Calls) {
2232 TestSignatures sigs; 2272 TestSignatures sigs;
2233 TestModuleEnv module; 2273 TestModuleEnv module;
2234 module.AddFunction(sigs.i_ii()); 2274 module.AddFunction(sigs.i_ii());
2235 module.AddFunction(sigs.i_i()); 2275 module.AddFunction(sigs.i_i());
2236 2276
2237 module.AddSignature(sigs.f_ff()); 2277 module.AddSignature(sigs.f_ff());
2238 module.AddSignature(sigs.i_d()); 2278 module.AddSignature(sigs.i_d());
2239 2279
2280 module.AddImport(sigs.f_ff());
2281 module.AddImport(sigs.i_d());
2282
2240 { 2283 {
2241 FunctionEnv env; 2284 FunctionEnv env;
2242 WasmDecoderTest::init_env(&env, sigs.i_ii()); 2285 WasmDecoderTest::init_env(&env, sigs.i_ii());
2243 env.module = &module; 2286 env.module = &module;
2244 2287
2245 EXPECT_ARITY(2, kExprCallFunction, 0); 2288 EXPECT_ARITY(2, kExprCallFunction, 0);
2289 EXPECT_ARITY(2, kExprCallImport, 0);
2246 EXPECT_ARITY(3, kExprCallIndirect, 0); 2290 EXPECT_ARITY(3, kExprCallIndirect, 0);
2247 EXPECT_ARITY(1, kExprBr); 2291 EXPECT_ARITY(1, kExprBr);
2248 EXPECT_ARITY(2, kExprBrIf); 2292 EXPECT_ARITY(2, kExprBrIf);
2249 } 2293 }
2250 2294
2251 { 2295 {
2252 FunctionEnv env; 2296 FunctionEnv env;
2253 WasmDecoderTest::init_env(&env, sigs.v_v()); 2297 WasmDecoderTest::init_env(&env, sigs.v_v());
2254 env.module = &module; 2298 env.module = &module;
2255 2299
2256 EXPECT_ARITY(1, kExprCallFunction, 1); 2300 EXPECT_ARITY(1, kExprCallFunction, 1);
2301 EXPECT_ARITY(1, kExprCallImport, 1);
2257 EXPECT_ARITY(2, kExprCallIndirect, 1); 2302 EXPECT_ARITY(2, kExprCallIndirect, 1);
2258 EXPECT_ARITY(1, kExprBr); 2303 EXPECT_ARITY(1, kExprBr);
2259 EXPECT_ARITY(2, kExprBrIf); 2304 EXPECT_ARITY(2, kExprBrIf);
2260 } 2305 }
2261 } 2306 }
2262 2307
2263 2308
2264 TEST_F(WasmOpcodeArityTest, LoadsAndStores) { 2309 TEST_F(WasmOpcodeArityTest, LoadsAndStores) {
2265 FunctionEnv env; 2310 FunctionEnv env;
2266 2311
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
2418 EXPECT_ARITY(1, kExprF64SConvertI64); 2463 EXPECT_ARITY(1, kExprF64SConvertI64);
2419 EXPECT_ARITY(1, kExprF64UConvertI64); 2464 EXPECT_ARITY(1, kExprF64UConvertI64);
2420 EXPECT_ARITY(1, kExprF64ConvertF32); 2465 EXPECT_ARITY(1, kExprF64ConvertF32);
2421 EXPECT_ARITY(1, kExprF64ReinterpretI64); 2466 EXPECT_ARITY(1, kExprF64ReinterpretI64);
2422 EXPECT_ARITY(1, kExprI32ReinterpretF32); 2467 EXPECT_ARITY(1, kExprI32ReinterpretF32);
2423 EXPECT_ARITY(1, kExprI64ReinterpretF64); 2468 EXPECT_ARITY(1, kExprI64ReinterpretF64);
2424 } 2469 }
2425 } // namespace wasm 2470 } // namespace wasm
2426 } // namespace internal 2471 } // namespace internal
2427 } // namespace v8 2472 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698