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 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 false}); // export | 1304 false}); // export |
1305 CHECK(mod.functions.size() <= 127); | 1305 CHECK(mod.functions.size() <= 127); |
1306 return static_cast<byte>(mod.functions.size() - 1); | 1306 return static_cast<byte>(mod.functions.size() - 1); |
1307 } | 1307 } |
1308 byte AddImport(FunctionSig* sig) { | 1308 byte AddImport(FunctionSig* sig) { |
1309 byte result = AddFunction(sig); | 1309 byte result = AddFunction(sig); |
1310 mod.functions[result].imported = true; | 1310 mod.functions[result].imported = true; |
1311 return result; | 1311 return result; |
1312 } | 1312 } |
1313 | 1313 |
1314 void InitializeFunctionTable() { | |
1315 mod.function_tables.push_back( | |
1316 {0, 0, true, std::vector<int32_t>(), false, false, SignatureMap()}); | |
1317 } | |
1318 | |
1319 private: | 1314 private: |
1320 WasmModule mod; | 1315 WasmModule mod; |
1321 }; | 1316 }; |
1322 } // namespace | 1317 } // namespace |
1323 | 1318 |
1324 TEST_F(AstDecoderTest, SimpleCalls) { | 1319 TEST_F(AstDecoderTest, SimpleCalls) { |
1325 FunctionSig* sig = sigs.i_i(); | 1320 FunctionSig* sig = sigs.i_i(); |
1326 TestModuleEnv module_env; | 1321 TestModuleEnv module_env; |
1327 module = &module_env; | 1322 module = &module_env; |
1328 | 1323 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1419 } | 1414 } |
1420 } | 1415 } |
1421 } | 1416 } |
1422 } | 1417 } |
1423 } | 1418 } |
1424 } | 1419 } |
1425 | 1420 |
1426 TEST_F(AstDecoderTest, SimpleIndirectCalls) { | 1421 TEST_F(AstDecoderTest, SimpleIndirectCalls) { |
1427 FunctionSig* sig = sigs.i_i(); | 1422 FunctionSig* sig = sigs.i_i(); |
1428 TestModuleEnv module_env; | 1423 TestModuleEnv module_env; |
1429 module_env.InitializeFunctionTable(); | |
1430 module = &module_env; | 1424 module = &module_env; |
1431 | 1425 |
1432 byte f0 = module_env.AddSignature(sigs.i_v()); | 1426 byte f0 = module_env.AddSignature(sigs.i_v()); |
1433 byte f1 = module_env.AddSignature(sigs.i_i()); | 1427 byte f1 = module_env.AddSignature(sigs.i_i()); |
1434 byte f2 = module_env.AddSignature(sigs.i_ii()); | 1428 byte f2 = module_env.AddSignature(sigs.i_ii()); |
1435 | 1429 |
1436 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); | 1430 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); |
1437 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); | 1431 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); |
1438 EXPECT_VERIFIES_S( | 1432 EXPECT_VERIFIES_S( |
1439 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); | 1433 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); |
1440 } | 1434 } |
1441 | 1435 |
1442 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { | 1436 TEST_F(AstDecoderTest, IndirectCallsOutOfBounds) { |
1443 FunctionSig* sig = sigs.i_i(); | 1437 FunctionSig* sig = sigs.i_i(); |
1444 TestModuleEnv module_env; | 1438 TestModuleEnv module_env; |
1445 module_env.InitializeFunctionTable(); | |
1446 module = &module_env; | 1439 module = &module_env; |
1447 | 1440 |
1448 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); | 1441 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
1449 module_env.AddSignature(sigs.i_v()); | 1442 module_env.AddSignature(sigs.i_v()); |
1450 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); | 1443 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
1451 | 1444 |
1452 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); | 1445 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(22))); |
1453 module_env.AddSignature(sigs.i_i()); | 1446 module_env.AddSignature(sigs.i_i()); |
1454 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); | 1447 EXPECT_VERIFIES_S(sig, WASM_CALL_INDIRECT1(1, WASM_ZERO, WASM_I8(27))); |
1455 | 1448 |
1456 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); | 1449 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(2, WASM_ZERO, WASM_I8(27))); |
1457 } | 1450 } |
1458 | 1451 |
1459 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { | 1452 TEST_F(AstDecoderTest, IndirectCallsWithMismatchedSigs3) { |
1460 FunctionSig* sig = sigs.i_i(); | 1453 FunctionSig* sig = sigs.i_i(); |
1461 TestModuleEnv module_env; | 1454 TestModuleEnv module_env; |
1462 module_env.InitializeFunctionTable(); | |
1463 module = &module_env; | 1455 module = &module_env; |
1464 | 1456 |
1465 byte f0 = module_env.AddFunction(sigs.i_f()); | 1457 byte f0 = module_env.AddFunction(sigs.i_f()); |
1466 | 1458 |
1467 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); | 1459 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I8(17))); |
1468 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); | 1460 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_I64V_1(27))); |
1469 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); | 1461 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f0, WASM_ZERO, WASM_F64(37.2))); |
1470 | 1462 |
1471 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); | 1463 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I8(17))); |
1472 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); | 1464 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_I64V_1(27))); |
1473 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); | 1465 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_F64(37.2))); |
1474 | 1466 |
1475 byte f1 = module_env.AddFunction(sigs.i_d()); | 1467 byte f1 = module_env.AddFunction(sigs.i_d()); |
1476 | 1468 |
1477 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); | 1469 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(16))); |
1478 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); | 1470 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I64V_1(16))); |
1479 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); | 1471 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_F32(17.6))); |
1480 } | 1472 } |
1481 | 1473 |
1482 TEST_F(AstDecoderTest, IndirectCallsWithoutTableCrash) { | |
1483 FunctionSig* sig = sigs.i_i(); | |
1484 TestModuleEnv module_env; | |
1485 module = &module_env; | |
1486 | |
1487 byte f0 = module_env.AddSignature(sigs.i_v()); | |
1488 byte f1 = module_env.AddSignature(sigs.i_i()); | |
1489 byte f2 = module_env.AddSignature(sigs.i_ii()); | |
1490 | |
1491 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT0(f0, WASM_ZERO)); | |
1492 EXPECT_FAILURE_S(sig, WASM_CALL_INDIRECT1(f1, WASM_ZERO, WASM_I8(22))); | |
1493 EXPECT_FAILURE_S( | |
1494 sig, WASM_CALL_INDIRECT2(f2, WASM_ZERO, WASM_I8(32), WASM_I8(72))); | |
1495 } | |
1496 | |
1497 TEST_F(AstDecoderTest, SimpleImportCalls) { | 1474 TEST_F(AstDecoderTest, SimpleImportCalls) { |
1498 FunctionSig* sig = sigs.i_i(); | 1475 FunctionSig* sig = sigs.i_i(); |
1499 TestModuleEnv module_env; | 1476 TestModuleEnv module_env; |
1500 module = &module_env; | 1477 module = &module_env; |
1501 | 1478 |
1502 byte f0 = module_env.AddImport(sigs.i_v()); | 1479 byte f0 = module_env.AddImport(sigs.i_v()); |
1503 byte f1 = module_env.AddImport(sigs.i_i()); | 1480 byte f1 = module_env.AddImport(sigs.i_i()); |
1504 byte f2 = module_env.AddImport(sigs.i_ii()); | 1481 byte f2 = module_env.AddImport(sigs.i_ii()); |
1505 | 1482 |
1506 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); | 1483 EXPECT_VERIFIES_S(sig, WASM_CALL_FUNCTION0(f0)); |
(...skipping 1198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2705 iter.next(); | 2682 iter.next(); |
2706 EXPECT_TRUE(iter.has_next()); | 2683 EXPECT_TRUE(iter.has_next()); |
2707 EXPECT_EQ(kExprI8Const, iter.current()); | 2684 EXPECT_EQ(kExprI8Const, iter.current()); |
2708 iter.next(); | 2685 iter.next(); |
2709 EXPECT_FALSE(iter.has_next()); | 2686 EXPECT_FALSE(iter.has_next()); |
2710 } | 2687 } |
2711 | 2688 |
2712 } // namespace wasm | 2689 } // namespace wasm |
2713 } // namespace internal | 2690 } // namespace internal |
2714 } // namespace v8 | 2691 } // namespace v8 |
OLD | NEW |