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

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

Issue 2324733002: [wasm] Do not support grow_memory for asmjs modules. (Closed)
Patch Set: Fixed a typo Created 4 years, 3 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
« no previous file with comments | « test/cctest/wasm/test-signatures.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "src/objects.h" 11 #include "src/objects.h"
12 12
13 #include "src/wasm/ast-decoder.h" 13 #include "src/wasm/ast-decoder.h"
14 #include "src/wasm/wasm-macro-gen.h" 14 #include "src/wasm/wasm-macro-gen.h"
15 #include "src/wasm/wasm-module.h" 15 #include "src/wasm/wasm-module.h"
16 #include "src/wasm/wasm-opcodes.h"
16 17
17 namespace v8 { 18 namespace v8 {
18 namespace internal { 19 namespace internal {
19 namespace wasm { 20 namespace wasm {
20 21
21 #define B1(a) kExprBlock, a, kExprEnd 22 #define B1(a) kExprBlock, a, kExprEnd
22 #define B2(a, b) kExprBlock, a, b, kExprEnd 23 #define B2(a, b) kExprBlock, a, b, kExprEnd
23 #define B3(a, b, c) kExprBlock, a, b, c, kExprEnd 24 #define B3(a, b, c) kExprBlock, a, b, c, kExprEnd
24 25
25 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0}; 26 static const byte kCodeGetLocal0[] = {kExprGetLocal, 0};
(...skipping 1046 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 1073
1073 #undef DECODE_TEST 1074 #undef DECODE_TEST
1074 } 1075 }
1075 1076
1076 TEST_F(AstDecoderTest, MemorySize) { 1077 TEST_F(AstDecoderTest, MemorySize) {
1077 byte code[] = {kExprMemorySize}; 1078 byte code[] = {kExprMemorySize};
1078 EXPECT_VERIFIES(sigs.i_i(), code); 1079 EXPECT_VERIFIES(sigs.i_i(), code);
1079 EXPECT_FAILURE(sigs.f_ff(), code); 1080 EXPECT_FAILURE(sigs.f_ff(), code);
1080 } 1081 }
1081 1082
1082 TEST_F(AstDecoderTest, GrowMemory) {
1083 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))};
1084 EXPECT_VERIFIES(sigs.i_i(), code);
1085 EXPECT_FAILURE(sigs.i_d(), code);
1086 }
1087
1088 TEST_F(AstDecoderTest, LoadMemOffset) { 1083 TEST_F(AstDecoderTest, LoadMemOffset) {
1089 for (int offset = 0; offset < 128; offset += 7) { 1084 for (int offset = 0; offset < 128; offset += 7) {
1090 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT, 1085 byte code[] = {kExprI8Const, 0, kExprI32LoadMem, ZERO_ALIGNMENT,
1091 static_cast<byte>(offset)}; 1086 static_cast<byte>(offset)};
1092 EXPECT_VERIFIES(sigs.i_i(), code); 1087 EXPECT_VERIFIES(sigs.i_i(), code);
1093 } 1088 }
1094 } 1089 }
1095 1090
1096 TEST_F(AstDecoderTest, LoadMemAlignment) { 1091 TEST_F(AstDecoderTest, LoadMemAlignment) {
1097 struct { 1092 struct {
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 module_env.AddGlobal(global_type); 1487 module_env.AddGlobal(global_type);
1493 if (local_type == global_type) { 1488 if (local_type == global_type) {
1494 EXPECT_VERIFIES_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); 1489 EXPECT_VERIFIES_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)));
1495 } else { 1490 } else {
1496 EXPECT_FAILURE_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0))); 1491 EXPECT_FAILURE_INLINE(&sig, WASM_SET_GLOBAL(0, WASM_GET_LOCAL(0)));
1497 } 1492 }
1498 } 1493 }
1499 } 1494 }
1500 } 1495 }
1501 1496
1497 TEST_F(AstDecoderTest, WasmGrowMemory) {
1498 TestModuleEnv module_env;
1499 module = &module_env;
1500 module->origin = kWasmOrigin;
1501
1502 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))};
1503 EXPECT_VERIFIES(sigs.i_i(), code);
1504 EXPECT_FAILURE(sigs.i_d(), code);
1505 }
1506
1507 TEST_F(AstDecoderTest, AsmJsGrowMemory) {
1508 TestModuleEnv module_env;
1509 module = &module_env;
1510 module->origin = kAsmJsOrigin;
1511
1512 byte code[] = {WASM_UNOP(kExprGrowMemory, WASM_GET_LOCAL(0))};
1513 EXPECT_FAILURE(sigs.i_i(), code);
1514 }
1515
1516 TEST_F(AstDecoderTest, AsmJsBinOpsCheckOrigin) {
1517 LocalType float32int32float32[] = {kAstF32, kAstI32, kAstF32};
1518 FunctionSig sig_f_if(1, 2, float32int32float32);
1519 LocalType float64int32float64[] = {kAstF64, kAstI32, kAstF64};
1520 FunctionSig sig_d_id(1, 2, float64int32float64);
1521 struct {
1522 WasmOpcode op;
1523 FunctionSig* sig;
1524 } AsmJsBinOps[] = {
1525 {kExprF64Atan2, sigs.d_dd()},
1526 {kExprF64Pow, sigs.d_dd()},
1527 {kExprF64Mod, sigs.d_dd()},
1528 {kExprI32AsmjsDivS, sigs.i_ii()},
1529 {kExprI32AsmjsDivU, sigs.i_ii()},
1530 {kExprI32AsmjsRemS, sigs.i_ii()},
1531 {kExprI32AsmjsRemU, sigs.i_ii()},
1532 {kExprI32AsmjsStoreMem8, sigs.i_ii()},
1533 {kExprI32AsmjsStoreMem16, sigs.i_ii()},
1534 {kExprI32AsmjsStoreMem, sigs.i_ii()},
1535 {kExprF32AsmjsStoreMem, &sig_f_if},
1536 {kExprF64AsmjsStoreMem, &sig_d_id},
1537 };
1538
1539 {
1540 TestModuleEnv module_env;
1541 module = &module_env;
1542 module->origin = kAsmJsOrigin;
1543 for (int i = 0; i < arraysize(AsmJsBinOps); i++) {
1544 TestBinop(AsmJsBinOps[i].op, AsmJsBinOps[i].sig);
1545 }
1546 }
1547
1548 {
1549 TestModuleEnv module_env;
1550 module = &module_env;
1551 module->origin = kWasmOrigin;
1552 for (int i = 0; i < arraysize(AsmJsBinOps); i++) {
1553 byte code[] = {
1554 WASM_BINOP(AsmJsBinOps[i].op, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
1555 EXPECT_FAILURE(AsmJsBinOps[i].sig, code);
1556 }
1557 }
1558 }
1559
1560 TEST_F(AstDecoderTest, AsmJsUnOpsCheckOrigin) {
1561 LocalType float32int32[] = {kAstF32, kAstI32};
1562 FunctionSig sig_f_i(1, 2, float32int32);
1563 LocalType float64int32[] = {kAstF64, kAstI32};
1564 FunctionSig sig_d_i(1, 2, float64int32);
1565 struct {
1566 WasmOpcode op;
1567 FunctionSig* sig;
1568 } AsmJsUnOps[] = {{kExprF64Acos, sigs.d_d()},
1569 {kExprF64Asin, sigs.d_d()},
1570 {kExprF64Atan, sigs.d_d()},
1571 {kExprF64Cos, sigs.d_d()},
1572 {kExprF64Sin, sigs.d_d()},
1573 {kExprF64Tan, sigs.d_d()},
1574 {kExprF64Exp, sigs.d_d()},
1575 {kExprF64Log, sigs.d_d()},
1576 {kExprI32AsmjsLoadMem8S, sigs.i_i()},
1577 {kExprI32AsmjsLoadMem8U, sigs.i_i()},
1578 {kExprI32AsmjsLoadMem16S, sigs.i_i()},
1579 {kExprI32AsmjsLoadMem16U, sigs.i_i()},
1580 {kExprI32AsmjsLoadMem, sigs.i_i()},
1581 {kExprF32AsmjsLoadMem, &sig_f_i},
1582 {kExprF64AsmjsLoadMem, &sig_d_i},
1583 {kExprI32AsmjsSConvertF32, sigs.i_f()},
1584 {kExprI32AsmjsUConvertF32, sigs.i_f()},
1585 {kExprI32AsmjsSConvertF64, sigs.i_d()},
1586 {kExprI32AsmjsUConvertF64, sigs.i_d()}};
1587 {
1588 TestModuleEnv module_env;
1589 module = &module_env;
1590 module->origin = kAsmJsOrigin;
1591 for (int i = 0; i < arraysize(AsmJsUnOps); i++) {
1592 TestUnop(AsmJsUnOps[i].op, AsmJsUnOps[i].sig);
1593 }
1594 }
1595
1596 {
1597 TestModuleEnv module_env;
1598 module = &module_env;
1599 module->origin = kWasmOrigin;
1600 for (int i = 0; i < arraysize(AsmJsUnOps); i++) {
1601 byte code[] = {WASM_UNOP(AsmJsUnOps[i].op, WASM_GET_LOCAL(0))};
1602 EXPECT_FAILURE(AsmJsUnOps[i].sig, code);
1603 }
1604 }
1605 }
1606
1502 TEST_F(AstDecoderTest, BreakEnd) { 1607 TEST_F(AstDecoderTest, BreakEnd) {
1503 EXPECT_VERIFIES_INLINE(sigs.i_i(), 1608 EXPECT_VERIFIES_INLINE(sigs.i_i(),
1504 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO))); 1609 B1(WASM_I32_ADD(WASM_BRV(0, WASM_ZERO), WASM_ZERO)));
1505 EXPECT_VERIFIES_INLINE(sigs.i_i(), 1610 EXPECT_VERIFIES_INLINE(sigs.i_i(),
1506 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO)))); 1611 B1(WASM_I32_ADD(WASM_ZERO, WASM_BRV(0, WASM_ZERO))));
1507 } 1612 }
1508 1613
1509 TEST_F(AstDecoderTest, BreakIfBinop) { 1614 TEST_F(AstDecoderTest, BreakIfBinop) {
1510 EXPECT_FAILURE_INLINE( 1615 EXPECT_FAILURE_INLINE(
1511 sigs.i_i(), WASM_BLOCK(WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO), 1616 sigs.i_i(), WASM_BLOCK(WASM_I32_ADD(WASM_BRV_IF(0, WASM_ZERO, WASM_ZERO),
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
2615 iter.next(); 2720 iter.next();
2616 EXPECT_TRUE(iter.has_next()); 2721 EXPECT_TRUE(iter.has_next());
2617 EXPECT_EQ(kExprI8Const, iter.current()); 2722 EXPECT_EQ(kExprI8Const, iter.current());
2618 iter.next(); 2723 iter.next();
2619 EXPECT_FALSE(iter.has_next()); 2724 EXPECT_FALSE(iter.has_next());
2620 } 2725 }
2621 2726
2622 } // namespace wasm 2727 } // namespace wasm
2623 } // namespace internal 2728 } // namespace internal
2624 } // namespace v8 2729 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/wasm/test-signatures.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698