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

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

Issue 2630553002: [wasm] Enforce that function bodies end with the \"end\" opcode. (Closed)
Patch Set: Collapse some tests together 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/wasm/function-body-decoder-unittest.cc
diff --git a/test/unittests/wasm/function-body-decoder-unittest.cc b/test/unittests/wasm/function-body-decoder-unittest.cc
index 0da781451efde4736ecbbcbdf9153190d051e670..66bbaa75807a103dc2e7d2f4932e5457ba5c01ee 100644
--- a/test/unittests/wasm/function-body-decoder-unittest.cc
+++ b/test/unittests/wasm/function-body-decoder-unittest.cc
@@ -104,11 +104,29 @@ class FunctionBodyDecoderTest : public TestWithZone {
local_decls.AddLocals(count, type);
}
+ void PrepareBytecode(const byte** startp, const byte** endp) {
+ const byte* start = *startp;
+ const byte* end = *endp;
+ size_t locals_size = local_decls.Size();
+ size_t total_size = end - start + locals_size + 1;
+ byte* buffer = static_cast<byte*>(zone()->New(total_size));
+ // Prepend the local decls to the code.
+ local_decls.Emit(buffer);
+ // Emit the code.
+ memcpy(buffer + locals_size, start, end - start);
+ // Append an extra end opcode.
+ buffer[total_size - 1] = kExprEnd;
+
+ *startp = buffer;
+ *endp = buffer + total_size;
+ }
+
// Prepends local variable declarations and renders nice error messages for
// verification failures.
void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
const byte* end) {
- local_decls.Prepend(zone(), &start, &end);
+ PrepareBytecode(&start, &end);
+
// Verify the code.
DecodeResult result = VerifyWasmCode(
zone()->allocator(), module == nullptr ? nullptr : module->module, sig,
@@ -461,11 +479,7 @@ TEST_F(FunctionBodyDecoderTest, Block0Block0) {
}
TEST_F(FunctionBodyDecoderTest, Block0_end) {
- EXPECT_VERIFIES(v_v, WASM_EMPTY_BLOCK, kExprEnd);
-}
-
-TEST_F(FunctionBodyDecoderTest, Block0_end_end) {
- EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd, kExprEnd);
+ EXPECT_FAILURE(v_v, WASM_EMPTY_BLOCK, kExprEnd);
}
TEST_F(FunctionBodyDecoderTest, Block1) {
@@ -712,37 +726,18 @@ TEST_F(FunctionBodyDecoderTest, Block_else) {
TEST_F(FunctionBodyDecoderTest, IfNop) {
EXPECT_VERIFIES(v_i, WASM_IF(WASM_GET_LOCAL(0), WASM_NOP));
-}
-
-TEST_F(FunctionBodyDecoderTest, IfNopElseNop) {
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
}
-TEST_F(FunctionBodyDecoderTest, If_end_end) {
- static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd};
- EXPECT_VERIFIES_C(v_i, code);
-}
-
-TEST_F(FunctionBodyDecoderTest, If_end_end_end) {
- static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP,
- kExprEnd, kExprEnd, kExprEnd};
- EXPECT_FAILURE_C(v_i, code);
+TEST_F(FunctionBodyDecoderTest, If_end) {
+ EXPECT_VERIFIES(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd);
+ EXPECT_FAILURE(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprEnd, kExprEnd);
}
TEST_F(FunctionBodyDecoderTest, If_falloff1) {
- static const byte code[] = {kExprGetLocal, 0, kExprIf};
- EXPECT_FAILURE_C(v_i, code);
-}
-
-TEST_F(FunctionBodyDecoderTest, If_falloff2) {
- static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP};
- EXPECT_FAILURE_C(v_i, code);
-}
-
-TEST_F(FunctionBodyDecoderTest, IfElse_falloff) {
- static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprNop,
- kExprElse};
- EXPECT_FAILURE_C(v_i, code);
+ EXPECT_FAILURE(v_i, kExprGetLocal, 0, kExprIf);
+ EXPECT_FAILURE(v_i, kExprGetLocal, 0, WASM_IF_OP);
+ EXPECT_FAILURE(v_i, kExprGetLocal, 0, WASM_IF_OP, kExprNop, kExprElse);
}
TEST_F(FunctionBodyDecoderTest, IfElseNop) {
« 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