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

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

Issue 1765673002: [wasm] Update {i32,i64}.const to use signed leb128 (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: nits, WASM_I64V fixes Created 4 years, 10 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/wasm/ast-decoder-unittest.cc ('k') | test/unittests/wasm/wasm-macro-gen-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/unittests/wasm/decoder-unittest.cc
diff --git a/test/unittests/wasm/decoder-unittest.cc b/test/unittests/wasm/decoder-unittest.cc
index d773c955c0454e629d7ac501d02971a9352edc53..11d68f161eecfa32adf4faa2050cb329e1fff671 100644
--- a/test/unittests/wasm/decoder-unittest.cc
+++ b/test/unittests/wasm/decoder-unittest.cc
@@ -428,6 +428,26 @@ TEST_F(DecoderTest, ReadU32v_extra_bits) {
}
}
+TEST_F(DecoderTest, ReadI32v_extra_bits_negative) {
+ // OK for negative signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0xff, 0xff, 0xff, 0xff, 0x7f};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i32v(decoder.start(), 0, &length);
+ EXPECT_EQ(5, length);
+ EXPECT_TRUE(decoder.ok());
+}
+
+TEST_F(DecoderTest, ReadI32v_extra_bits_positive) {
+ // Not OK for positive signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0x80, 0x80, 0x80, 0x80, 0x77};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i32v(decoder.start(), 0, &length);
+ EXPECT_EQ(5, length);
+ EXPECT_FALSE(decoder.ok());
+}
+
TEST_F(DecoderTest, ReadU32v_Bits) {
// A more exhaustive test.
const int kMaxSize = 5;
@@ -587,8 +607,7 @@ TEST_F(DecoderTest, ReadI64v_Bits) {
int length = 1 + i / 7;
for (int j = 0; j < kMaxSize; j++) {
- const uint64_t uval = bit_cast<uint64_t>(val);
- data[j] = static_cast<byte>((uval >> (7 * j)) & MASK_7);
+ data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7);
}
for (int j = 0; j < length - 1; j++) {
data[j] |= 0x80;
@@ -623,6 +642,26 @@ TEST_F(DecoderTest, ReadU64v_extra_bits) {
}
}
+TEST_F(DecoderTest, ReadI64v_extra_bits_negative) {
+ // OK for negative signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i64v(decoder.start(), 0, &length);
+ EXPECT_EQ(10, length);
+ EXPECT_TRUE(decoder.ok());
+}
+
+TEST_F(DecoderTest, ReadI64v_extra_bits_positive) {
+ // Not OK for positive signed values to have extra ones.
+ int length = 0;
+ byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77};
+ decoder.Reset(data, data + sizeof(data));
+ decoder.checked_read_i64v(decoder.start(), 0, &length);
+ EXPECT_EQ(10, length);
+ EXPECT_FALSE(decoder.ok());
+}
+
} // namespace wasm
} // namespace internal
} // namespace v8
« no previous file with comments | « test/unittests/wasm/ast-decoder-unittest.cc ('k') | test/unittests/wasm/wasm-macro-gen-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698