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

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

Issue 2628203003: Reland 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 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..0f7476b24df49947f54fb28f437d930e20cfebf3 100644
--- a/test/unittests/wasm/function-body-decoder-unittest.cc
+++ b/test/unittests/wasm/function-body-decoder-unittest.cc
@@ -108,7 +108,19 @@
// verification failures.
void Verify(ErrorCode expected, FunctionSig* sig, const byte* start,
const byte* end) {
- local_decls.Prepend(zone(), &start, &end);
+ 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;
+
+ start = buffer;
+ end = buffer + total_size;
+
// Verify the code.
DecodeResult result = VerifyWasmCode(
zone()->allocator(), module == nullptr ? nullptr : module->module, sig,
@@ -461,11 +473,7 @@
}
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) {
@@ -718,14 +726,13 @@
EXPECT_VERIFIES(v_i, WASM_IF_ELSE(WASM_GET_LOCAL(0), WASM_NOP, WASM_NOP));
}
+TEST_F(FunctionBodyDecoderTest, If_end) {
+ static const byte code[] = {kExprGetLocal, 0, WASM_IF_OP, kExprEnd};
+ EXPECT_VERIFIES_C(v_i, code);
+}
+
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);
}
« 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