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

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

Issue 2628883006: Revert of [wasm] Enforce that function bodies end with the \"end\" opcode. (Closed)
Patch Set: Created 3 years, 11 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/common/wasm/test-signatures.h" 9 #include "test/common/wasm/test-signatures.h"
10 10
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 LocalDeclEncoder local_decls; 101 LocalDeclEncoder local_decls;
102 102
103 void AddLocals(ValueType type, uint32_t count) { 103 void AddLocals(ValueType type, uint32_t count) {
104 local_decls.AddLocals(count, type); 104 local_decls.AddLocals(count, type);
105 } 105 }
106 106
107 // Prepends local variable declarations and renders nice error messages for 107 // Prepends local variable declarations and renders nice error messages for
108 // verification failures. 108 // verification failures.
109 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start, 109 void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
110 const byte* end) { 110 const byte* end) {
111 size_t locals_size = local_decls.Size(); 111 local_decls.Prepend(zone(), &start, &end);
112 size_t total_size = end - start + locals_size + 1;
113 byte* buffer = static_cast<byte*>(zone()->New(total_size));
114 // Prepend the local decls to the code.
115 local_decls.Emit(buffer);
116 // Emit the code.
117 memcpy(buffer + locals_size, start, end - start);
118 // Append an extra end opcode.
119 buffer[total_size - 1] = kExprEnd;
120
121 start = buffer;
122 end = buffer + total_size;
123
124 // Verify the code. 112 // Verify the code.
125 DecodeResult result = VerifyWasmCode( 113 DecodeResult result = VerifyWasmCode(
126 zone()->allocator(), module == nullptr ? nullptr : module->module, sig, 114 zone()->allocator(), module == nullptr ? nullptr : module->module, sig,
127 start, end); 115 start, end);
128 116
129 if (result.error_code != expected) { 117 if (result.error_code != expected) {
130 ptrdiff_t pc = result.error_pc - result.start; 118 ptrdiff_t pc = result.error_pc - result.start;
131 ptrdiff_t pt = result.error_pt - result.start; 119 ptrdiff_t pt = result.error_pt - result.start;
132 std::ostringstream str; 120 std::ostringstream str;
133 if (expected == kSuccess) { 121 if (expected == kSuccess) {
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 EXPECT_FAILURE_C(i_i, code); 454 EXPECT_FAILURE_C(i_i, code);
467 } 455 }
468 456
469 TEST_F(FunctionBodyDecoderTest, Block0Block0) { 457 TEST_F(FunctionBodyDecoderTest, Block0Block0) {
470 static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK}; 458 static const byte code[] = {WASM_EMPTY_BLOCK, WASM_EMPTY_BLOCK};
471 EXPECT_VERIFIES_C(v_v, code); 459 EXPECT_VERIFIES_C(v_v, code);
472 EXPECT_FAILURE_C(i_i, code); 460 EXPECT_FAILURE_C(i_i, code);
473 } 461 }
474 462
475 TEST_F(FunctionBodyDecoderTest, Block0_end) { 463 TEST_F(FunctionBodyDecoderTest, Block0_end) {
476 EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd); 464 EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd);
465 }
466
467 TEST_F(FunctionBodyDecoderTest, Block0_end_end) {
468 EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd);
477 } 469 }
478 470
479 TEST_F(FunctionBodyDecoderTest, Block1) { 471 TEST_F(FunctionBodyDecoderTest, Block1) {
480 byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))}; 472 byte code[] = {WASM_BLOCK_I(WASM_GET_LOCAL(0))};
481 EXPECT_VERIFIES_C(i_i, code); 473 EXPECT_VERIFIES_C(i_i, code);
482 EXPECT_FAILURE_C(v_i, code); 474 EXPECT_FAILURE_C(v_i, code);
483 EXPECT_FAILURE_C(d_dd, code); 475 EXPECT_FAILURE_C(d_dd, code);
484 EXPECT_FAILURE_C(i_f, code); 476 EXPECT_FAILURE_C(i_f, code);
485 EXPECT_FAILURE_C(i_d, code); 477 EXPECT_FAILURE_C(i_d, code);
486 } 478 }
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 } 711 }
720 712
721 TEST_F(FunctionBodyDecoderTest, IfNop) { 713 TEST_F(FunctionBodyDecoderTest, IfNop) {
722 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP)); 714 EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
723 } 715 }
724 716
725 TEST_F(FunctionBodyDecoderTest, IfNopElseNop) { 717 TEST_F(FunctionBodyDecoderTest, IfNopElseNop) {
726 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP)); 718 EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
727 } 719 }
728 720
729 TEST_F(FunctionBodyDecoderTest, If_end) {
730 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd};
731 EXPECT_VERIFIES_C(v_i, code);
732 }
733
734 TEST_F(FunctionBodyDecoderTest, If_end_end) { 721 TEST_F(FunctionBodyDecoderTest, If_end_end) {
735 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd}; 722 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd};
723 EXPECT_VERIFIES_C(v_i, code);
724 }
725
726 TEST_F(FunctionBodyDecoderTest, If_end_end_end) {
727 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP,
728 kExprEnd, kExprEnd, kExprEnd};
736 EXPECT_FAILURE_C(v_i, code); 729 EXPECT_FAILURE_C(v_i, code);
737 } 730 }
738 731
739 TEST_F(FunctionBodyDecoderTest, If_falloff1) { 732 TEST_F(FunctionBodyDecoderTest, If_falloff1) {
740 static const byte code[] = {kExprGetLocal, 0, kExprIf}; 733 static const byte code[] = {kExprGetLocal, 0, kExprIf};
741 EXPECT_FAILURE_C(v_i, code); 734 EXPECT_FAILURE_C(v_i, code);
742 } 735 }
743 736
744 TEST_F(FunctionBodyDecoderTest, If_falloff2) { 737 TEST_F(FunctionBodyDecoderTest, If_falloff2) {
745 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP}; 738 static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP};
(...skipping 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2735 iter.next(); 2728 iter.next();
2736 EXPECT_TRUE(iter.has_next()); 2729 EXPECT_TRUE(iter.has_next());
2737 EXPECT_EQ(kExprI32Const, iter.current()); 2730 EXPECT_EQ(kExprI32Const, iter.current());
2738 iter.next(); 2731 iter.next();
2739 EXPECT_FALSE(iter.has_next()); 2732 EXPECT_FALSE(iter.has_next());
2740 } 2733 }
2741 2734
2742 } // namespace wasm 2735 } // namespace wasm
2743 } // namespace internal 2736 } // namespace internal
2744 } // namespace v8 2737 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/value-serializer-unittest.cc ('k') | test/unittests/wasm/module-decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698