OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "test/unittests/test-utils.h" |
| 6 |
| 7 #include "src/wasm/decoder.h" |
| 8 #include "src/wasm/wasm-macro-gen.h" |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 namespace wasm { |
| 13 |
| 14 class DecoderTest : public TestWithZone { |
| 15 public: |
| 16 DecoderTest() : decoder(nullptr, nullptr) {} |
| 17 |
| 18 Decoder decoder; |
| 19 }; |
| 20 |
| 21 #define CHECK_UINT32V_INLINE(expected, expected_length, ...) \ |
| 22 do { \ |
| 23 const byte data[] = {__VA_ARGS__}; \ |
| 24 decoder.Reset(data, data + sizeof(data)); \ |
| 25 int length; \ |
| 26 EXPECT_EQ(expected, \ |
| 27 decoder.checked_read_u32v(decoder.start(), 0, &length)); \ |
| 28 EXPECT_EQ(expected_length, length); \ |
| 29 } while (false) |
| 30 |
| 31 #define CHECK_INT32V_INLINE(expected, expected_length, ...) \ |
| 32 do { \ |
| 33 const byte data[] = {__VA_ARGS__}; \ |
| 34 decoder.Reset(data, data + sizeof(data)); \ |
| 35 int length; \ |
| 36 EXPECT_EQ(expected, \ |
| 37 decoder.checked_read_i32v(decoder.start(), 0, &length)); \ |
| 38 EXPECT_EQ(expected_length, length); \ |
| 39 } while (false) |
| 40 |
| 41 TEST_F(DecoderTest, ReadU32v_OneByte) { |
| 42 CHECK_UINT32V_INLINE(0, 1, 0); |
| 43 CHECK_UINT32V_INLINE(5, 1, 5); |
| 44 CHECK_UINT32V_INLINE(7, 1, 7); |
| 45 CHECK_UINT32V_INLINE(9, 1, 9); |
| 46 CHECK_UINT32V_INLINE(37, 1, 37); |
| 47 CHECK_UINT32V_INLINE(69, 1, 69); |
| 48 CHECK_UINT32V_INLINE(110, 1, 110); |
| 49 CHECK_UINT32V_INLINE(125, 1, 125); |
| 50 CHECK_UINT32V_INLINE(126, 1, 126); |
| 51 CHECK_UINT32V_INLINE(127, 1, 127); |
| 52 } |
| 53 |
| 54 TEST_F(DecoderTest, ReadU32v_TwoByte) { |
| 55 CHECK_UINT32V_INLINE(0, 1, 0, 0); |
| 56 CHECK_UINT32V_INLINE(10, 1, 10, 0); |
| 57 CHECK_UINT32V_INLINE(27, 1, 27, 0); |
| 58 CHECK_UINT32V_INLINE(100, 1, 100, 0); |
| 59 |
| 60 CHECK_UINT32V_INLINE(444, 2, U32V_2(444)); |
| 61 CHECK_UINT32V_INLINE(544, 2, U32V_2(544)); |
| 62 CHECK_UINT32V_INLINE(1311, 2, U32V_2(1311)); |
| 63 CHECK_UINT32V_INLINE(2333, 2, U32V_2(2333)); |
| 64 |
| 65 for (uint32_t i = 0; i < 1 << 14; i = i * 13 + 1) { |
| 66 CHECK_UINT32V_INLINE(i, 2, U32V_2(i)); |
| 67 } |
| 68 |
| 69 const uint32_t max = (1 << 14) - 1; |
| 70 CHECK_UINT32V_INLINE(max, 2, U32V_2(max)); |
| 71 } |
| 72 |
| 73 TEST_F(DecoderTest, ReadU32v_ThreeByte) { |
| 74 CHECK_UINT32V_INLINE(0, 1, 0, 0, 0, 0); |
| 75 CHECK_UINT32V_INLINE(10, 1, 10, 0, 0, 0); |
| 76 CHECK_UINT32V_INLINE(27, 1, 27, 0, 0, 0); |
| 77 CHECK_UINT32V_INLINE(100, 1, 100, 0, 0, 0); |
| 78 |
| 79 CHECK_UINT32V_INLINE(11, 3, U32V_3(11)); |
| 80 CHECK_UINT32V_INLINE(101, 3, U32V_3(101)); |
| 81 CHECK_UINT32V_INLINE(446, 3, U32V_3(446)); |
| 82 CHECK_UINT32V_INLINE(546, 3, U32V_3(546)); |
| 83 CHECK_UINT32V_INLINE(1319, 3, U32V_3(1319)); |
| 84 CHECK_UINT32V_INLINE(2338, 3, U32V_3(2338)); |
| 85 CHECK_UINT32V_INLINE(8191, 3, U32V_3(8191)); |
| 86 CHECK_UINT32V_INLINE(9999, 3, U32V_3(9999)); |
| 87 CHECK_UINT32V_INLINE(14444, 3, U32V_3(14444)); |
| 88 CHECK_UINT32V_INLINE(314444, 3, U32V_3(314444)); |
| 89 CHECK_UINT32V_INLINE(614444, 3, U32V_3(614444)); |
| 90 |
| 91 const uint32_t max = (1 << 21) - 1; |
| 92 |
| 93 for (uint32_t i = 0; i <= max; i = i * 13 + 3) { |
| 94 CHECK_UINT32V_INLINE(i, 3, U32V_3(i), 0); |
| 95 } |
| 96 |
| 97 CHECK_UINT32V_INLINE(max, 3, U32V_3(max)); |
| 98 } |
| 99 |
| 100 TEST_F(DecoderTest, ReadU32v_FourByte) { |
| 101 CHECK_UINT32V_INLINE(0, 1, 0, 0, 0, 0, 0); |
| 102 CHECK_UINT32V_INLINE(10, 1, 10, 0, 0, 0, 0); |
| 103 CHECK_UINT32V_INLINE(27, 1, 27, 0, 0, 0, 0); |
| 104 CHECK_UINT32V_INLINE(100, 1, 100, 0, 0, 0, 0); |
| 105 |
| 106 CHECK_UINT32V_INLINE(13, 4, U32V_4(13)); |
| 107 CHECK_UINT32V_INLINE(107, 4, U32V_4(107)); |
| 108 CHECK_UINT32V_INLINE(449, 4, U32V_4(449)); |
| 109 CHECK_UINT32V_INLINE(541, 4, U32V_4(541)); |
| 110 CHECK_UINT32V_INLINE(1317, 4, U32V_4(1317)); |
| 111 CHECK_UINT32V_INLINE(2334, 4, U32V_4(2334)); |
| 112 CHECK_UINT32V_INLINE(8191, 4, U32V_4(8191)); |
| 113 CHECK_UINT32V_INLINE(9994, 4, U32V_4(9994)); |
| 114 CHECK_UINT32V_INLINE(14442, 4, U32V_4(14442)); |
| 115 CHECK_UINT32V_INLINE(314442, 4, U32V_4(314442)); |
| 116 CHECK_UINT32V_INLINE(614442, 4, U32V_4(614442)); |
| 117 CHECK_UINT32V_INLINE(1614442, 4, U32V_4(1614442)); |
| 118 CHECK_UINT32V_INLINE(5614442, 4, U32V_4(5614442)); |
| 119 CHECK_UINT32V_INLINE(19614442, 4, U32V_4(19614442)); |
| 120 |
| 121 const uint32_t max = (1 << 28) - 1; |
| 122 |
| 123 for (uint32_t i = 0; i <= max; i = i * 13 + 5) { |
| 124 CHECK_UINT32V_INLINE(i, 4, U32V_4(i), 0); |
| 125 } |
| 126 |
| 127 CHECK_UINT32V_INLINE(max, 4, U32V_4(max)); |
| 128 } |
| 129 |
| 130 TEST_F(DecoderTest, ReadU32v_FiveByte) { |
| 131 CHECK_UINT32V_INLINE(0, 1, 0, 0, 0, 0, 0); |
| 132 CHECK_UINT32V_INLINE(10, 1, 10, 0, 0, 0, 0); |
| 133 CHECK_UINT32V_INLINE(27, 1, 27, 0, 0, 0, 0); |
| 134 CHECK_UINT32V_INLINE(100, 1, 100, 0, 0, 0, 0); |
| 135 |
| 136 CHECK_UINT32V_INLINE(13, 5, U32V_5(13)); |
| 137 CHECK_UINT32V_INLINE(107, 5, U32V_5(107)); |
| 138 CHECK_UINT32V_INLINE(449, 5, U32V_5(449)); |
| 139 CHECK_UINT32V_INLINE(541, 5, U32V_5(541)); |
| 140 CHECK_UINT32V_INLINE(1317, 5, U32V_5(1317)); |
| 141 CHECK_UINT32V_INLINE(2334, 5, U32V_5(2334)); |
| 142 CHECK_UINT32V_INLINE(8191, 5, U32V_5(8191)); |
| 143 CHECK_UINT32V_INLINE(9994, 5, U32V_5(9994)); |
| 144 CHECK_UINT32V_INLINE(24442, 5, U32V_5(24442)); |
| 145 CHECK_UINT32V_INLINE(414442, 5, U32V_5(414442)); |
| 146 CHECK_UINT32V_INLINE(714442, 5, U32V_5(714442)); |
| 147 CHECK_UINT32V_INLINE(1614442, 5, U32V_5(1614442)); |
| 148 CHECK_UINT32V_INLINE(6614442, 5, U32V_5(6614442)); |
| 149 CHECK_UINT32V_INLINE(89614442, 5, U32V_5(89614442)); |
| 150 CHECK_UINT32V_INLINE(2219614442u, 5, U32V_5(2219614442u)); |
| 151 CHECK_UINT32V_INLINE(3219614442u, 5, U32V_5(3219614442u)); |
| 152 CHECK_UINT32V_INLINE(4019614442u, 5, U32V_5(4019614442u)); |
| 153 |
| 154 const uint32_t max = 0xFFFFFFFFu; |
| 155 |
| 156 for (uint32_t i = 1; i < 32; i++) { |
| 157 uint32_t val = 0x983489aau << i; |
| 158 CHECK_UINT32V_INLINE(val, 5, U32V_5(val), 0); |
| 159 } |
| 160 |
| 161 CHECK_UINT32V_INLINE(max, 5, U32V_5(max)); |
| 162 } |
| 163 |
| 164 TEST_F(DecoderTest, ReadU32v_various) { |
| 165 for (int i = 0; i < 10; i++) { |
| 166 uint32_t x = 0xCCCCCCCCu * i; |
| 167 for (int width = 0; width < 32; width++) { |
| 168 uint32_t val = x >> width; |
| 169 |
| 170 CHECK_UINT32V_INLINE(val & MASK_7, 1, U32V_1(val)); |
| 171 CHECK_UINT32V_INLINE(val & MASK_14, 2, U32V_2(val)); |
| 172 CHECK_UINT32V_INLINE(val & MASK_21, 3, U32V_3(val)); |
| 173 CHECK_UINT32V_INLINE(val & MASK_28, 4, U32V_4(val)); |
| 174 CHECK_UINT32V_INLINE(val, 5, U32V_5(val)); |
| 175 } |
| 176 } |
| 177 } |
| 178 |
| 179 TEST_F(DecoderTest, ReadI32v_OneByte) { |
| 180 CHECK_INT32V_INLINE(0, 1, 0); |
| 181 CHECK_INT32V_INLINE(4, 1, 4); |
| 182 CHECK_INT32V_INLINE(6, 1, 6); |
| 183 CHECK_INT32V_INLINE(9, 1, 9); |
| 184 CHECK_INT32V_INLINE(33, 1, 33); |
| 185 CHECK_INT32V_INLINE(61, 1, 61); |
| 186 CHECK_INT32V_INLINE(63, 1, 63); |
| 187 |
| 188 CHECK_INT32V_INLINE(-1, 1, 127); |
| 189 CHECK_INT32V_INLINE(-2, 1, 126); |
| 190 CHECK_INT32V_INLINE(-11, 1, 117); |
| 191 CHECK_INT32V_INLINE(-62, 1, 66); |
| 192 CHECK_INT32V_INLINE(-63, 1, 65); |
| 193 CHECK_INT32V_INLINE(-64, 1, 64); |
| 194 } |
| 195 |
| 196 TEST_F(DecoderTest, ReadI32v_TwoByte) { |
| 197 CHECK_INT32V_INLINE(0, 2, U32V_2(0)); |
| 198 CHECK_INT32V_INLINE(9, 2, U32V_2(9)); |
| 199 CHECK_INT32V_INLINE(61, 2, U32V_2(61)); |
| 200 CHECK_INT32V_INLINE(63, 2, U32V_2(63)); |
| 201 |
| 202 CHECK_INT32V_INLINE(-1, 2, U32V_2(-1)); |
| 203 CHECK_INT32V_INLINE(-2, 2, U32V_2(-2)); |
| 204 CHECK_INT32V_INLINE(-63, 2, U32V_2(-63)); |
| 205 CHECK_INT32V_INLINE(-64, 2, U32V_2(-64)); |
| 206 |
| 207 CHECK_INT32V_INLINE(-200, 2, U32V_2(-200)); |
| 208 CHECK_INT32V_INLINE(-1002, 2, U32V_2(-1002)); |
| 209 CHECK_INT32V_INLINE(-2004, 2, U32V_2(-2004)); |
| 210 CHECK_INT32V_INLINE(-4077, 2, U32V_2(-4077)); |
| 211 |
| 212 CHECK_INT32V_INLINE(207, 2, U32V_2(207)); |
| 213 CHECK_INT32V_INLINE(1009, 2, U32V_2(1009)); |
| 214 CHECK_INT32V_INLINE(2003, 2, U32V_2(2003)); |
| 215 CHECK_INT32V_INLINE(4072, 2, U32V_2(4072)); |
| 216 |
| 217 const int32_t min = 0 - (1 << 13); |
| 218 for (int i = min; i < min + 10; i++) { |
| 219 CHECK_INT32V_INLINE(i, 2, U32V_2(i)); |
| 220 } |
| 221 |
| 222 const int32_t max = (1 << 13) - 1; |
| 223 for (int i = max; i > max - 10; i--) { |
| 224 CHECK_INT32V_INLINE(i, 2, U32V_2(i)); |
| 225 } |
| 226 } |
| 227 |
| 228 TEST_F(DecoderTest, ReadI32v_ThreeByte) { |
| 229 CHECK_INT32V_INLINE(0, 3, U32V_3(0)); |
| 230 CHECK_INT32V_INLINE(9, 3, U32V_3(9)); |
| 231 CHECK_INT32V_INLINE(61, 3, U32V_3(61)); |
| 232 CHECK_INT32V_INLINE(63, 3, U32V_3(63)); |
| 233 |
| 234 CHECK_INT32V_INLINE(-1, 3, U32V_3(-1)); |
| 235 CHECK_INT32V_INLINE(-2, 3, U32V_3(-2)); |
| 236 CHECK_INT32V_INLINE(-63, 3, U32V_3(-63)); |
| 237 CHECK_INT32V_INLINE(-64, 3, U32V_3(-64)); |
| 238 |
| 239 CHECK_INT32V_INLINE(-207, 3, U32V_3(-207)); |
| 240 CHECK_INT32V_INLINE(-1012, 3, U32V_3(-1012)); |
| 241 CHECK_INT32V_INLINE(-4067, 3, U32V_3(-4067)); |
| 242 CHECK_INT32V_INLINE(-14067, 3, U32V_3(-14067)); |
| 243 CHECK_INT32V_INLINE(-234061, 3, U32V_3(-234061)); |
| 244 |
| 245 CHECK_INT32V_INLINE(237, 3, U32V_3(237)); |
| 246 CHECK_INT32V_INLINE(1309, 3, U32V_3(1309)); |
| 247 CHECK_INT32V_INLINE(4372, 3, U32V_3(4372)); |
| 248 CHECK_INT32V_INLINE(64372, 3, U32V_3(64372)); |
| 249 CHECK_INT32V_INLINE(374372, 3, U32V_3(374372)); |
| 250 |
| 251 const int32_t min = 0 - (1 << 20); |
| 252 for (int i = min; i < min + 10; i++) { |
| 253 CHECK_INT32V_INLINE(i, 3, U32V_3(i)); |
| 254 } |
| 255 |
| 256 const int32_t max = (1 << 20) - 1; |
| 257 for (int i = max; i > max - 10; i--) { |
| 258 CHECK_INT32V_INLINE(i, 3, U32V_3(i)); |
| 259 } |
| 260 } |
| 261 |
| 262 TEST_F(DecoderTest, ReadI32v_FourByte) { |
| 263 CHECK_INT32V_INLINE(0, 4, U32V_4(0)); |
| 264 CHECK_INT32V_INLINE(9, 4, U32V_4(9)); |
| 265 CHECK_INT32V_INLINE(61, 4, U32V_4(61)); |
| 266 CHECK_INT32V_INLINE(63, 4, U32V_4(63)); |
| 267 |
| 268 CHECK_INT32V_INLINE(-1, 4, U32V_4(-1)); |
| 269 CHECK_INT32V_INLINE(-2, 4, U32V_4(-2)); |
| 270 CHECK_INT32V_INLINE(-63, 4, U32V_4(-63)); |
| 271 CHECK_INT32V_INLINE(-64, 4, U32V_4(-64)); |
| 272 |
| 273 CHECK_INT32V_INLINE(-267, 4, U32V_4(-267)); |
| 274 CHECK_INT32V_INLINE(-1612, 4, U32V_4(-1612)); |
| 275 CHECK_INT32V_INLINE(-4667, 4, U32V_4(-4667)); |
| 276 CHECK_INT32V_INLINE(-16067, 4, U32V_4(-16067)); |
| 277 CHECK_INT32V_INLINE(-264061, 4, U32V_4(-264061)); |
| 278 CHECK_INT32V_INLINE(-1264061, 4, U32V_4(-1264061)); |
| 279 CHECK_INT32V_INLINE(-6264061, 4, U32V_4(-6264061)); |
| 280 CHECK_INT32V_INLINE(-8264061, 4, U32V_4(-8264061)); |
| 281 |
| 282 CHECK_INT32V_INLINE(277, 4, U32V_4(277)); |
| 283 CHECK_INT32V_INLINE(1709, 4, U32V_4(1709)); |
| 284 CHECK_INT32V_INLINE(4772, 4, U32V_4(4772)); |
| 285 CHECK_INT32V_INLINE(67372, 4, U32V_4(67372)); |
| 286 CHECK_INT32V_INLINE(374372, 4, U32V_4(374372)); |
| 287 CHECK_INT32V_INLINE(2374372, 4, U32V_4(2374372)); |
| 288 CHECK_INT32V_INLINE(7374372, 4, U32V_4(7374372)); |
| 289 CHECK_INT32V_INLINE(9374372, 4, U32V_4(9374372)); |
| 290 |
| 291 const int32_t min = 0 - (1 << 27); |
| 292 for (int i = min; i < min + 10; i++) { |
| 293 CHECK_INT32V_INLINE(i, 4, U32V_4(i)); |
| 294 } |
| 295 |
| 296 const int32_t max = (1 << 27) - 1; |
| 297 for (int i = max; i > max - 10; i--) { |
| 298 CHECK_INT32V_INLINE(i, 4, U32V_4(i)); |
| 299 } |
| 300 } |
| 301 |
| 302 TEST_F(DecoderTest, ReadI32v_FiveByte) { |
| 303 CHECK_INT32V_INLINE(0, 5, U32V_5(0)); |
| 304 CHECK_INT32V_INLINE(16, 5, U32V_5(16)); |
| 305 CHECK_INT32V_INLINE(94, 5, U32V_5(94)); |
| 306 CHECK_INT32V_INLINE(127, 5, U32V_5(127)); |
| 307 |
| 308 CHECK_INT32V_INLINE(-1, 5, U32V_5(-1)); |
| 309 CHECK_INT32V_INLINE(-2, 5, U32V_5(-2)); |
| 310 CHECK_INT32V_INLINE(-63, 5, U32V_5(-63)); |
| 311 CHECK_INT32V_INLINE(-64, 5, U32V_5(-64)); |
| 312 |
| 313 CHECK_INT32V_INLINE(-257, 5, U32V_5(-257)); |
| 314 CHECK_INT32V_INLINE(-1512, 5, U32V_5(-1512)); |
| 315 CHECK_INT32V_INLINE(-4567, 5, U32V_5(-4567)); |
| 316 CHECK_INT32V_INLINE(-15067, 5, U32V_5(-15067)); |
| 317 CHECK_INT32V_INLINE(-254061, 5, U32V_5(-254061)); |
| 318 CHECK_INT32V_INLINE(-1364061, 5, U32V_5(-1364061)); |
| 319 CHECK_INT32V_INLINE(-6364061, 5, U32V_5(-6364061)); |
| 320 CHECK_INT32V_INLINE(-8364061, 5, U32V_5(-8364061)); |
| 321 CHECK_INT32V_INLINE(-28364061, 5, U32V_5(-28364061)); |
| 322 CHECK_INT32V_INLINE(-228364061, 5, U32V_5(-228364061)); |
| 323 |
| 324 CHECK_INT32V_INLINE(227, 5, U32V_5(227)); |
| 325 CHECK_INT32V_INLINE(1209, 5, U32V_5(1209)); |
| 326 CHECK_INT32V_INLINE(4272, 5, U32V_5(4272)); |
| 327 CHECK_INT32V_INLINE(62372, 5, U32V_5(62372)); |
| 328 CHECK_INT32V_INLINE(324372, 5, U32V_5(324372)); |
| 329 CHECK_INT32V_INLINE(2274372, 5, U32V_5(2274372)); |
| 330 CHECK_INT32V_INLINE(7274372, 5, U32V_5(7274372)); |
| 331 CHECK_INT32V_INLINE(9274372, 5, U32V_5(9274372)); |
| 332 CHECK_INT32V_INLINE(42374372, 5, U32V_5(42374372)); |
| 333 CHECK_INT32V_INLINE(429374372, 5, U32V_5(429374372)); |
| 334 |
| 335 const int32_t min = kMinInt; |
| 336 for (int i = min; i < min + 10; i++) { |
| 337 CHECK_INT32V_INLINE(i, 5, U32V_5(i)); |
| 338 } |
| 339 |
| 340 const int32_t max = kMaxInt; |
| 341 for (int i = max; i > max - 10; i--) { |
| 342 CHECK_INT32V_INLINE(i, 5, U32V_5(i)); |
| 343 } |
| 344 } |
| 345 |
| 346 TEST_F(DecoderTest, ReadU32v_off_end1) { |
| 347 static const byte data[] = {U32V_1(11)}; |
| 348 int length = 0; |
| 349 decoder.Reset(data, data); |
| 350 decoder.checked_read_u32v(decoder.start(), 0, &length); |
| 351 EXPECT_EQ(0, length); |
| 352 EXPECT_FALSE(decoder.ok()); |
| 353 } |
| 354 |
| 355 TEST_F(DecoderTest, ReadU32v_off_end2) { |
| 356 static const byte data[] = {U32V_2(1111)}; |
| 357 for (size_t i = 0; i < sizeof(data); i++) { |
| 358 int length = 0; |
| 359 decoder.Reset(data, data + i); |
| 360 decoder.checked_read_u32v(decoder.start(), 0, &length); |
| 361 EXPECT_EQ(i, length); |
| 362 EXPECT_FALSE(decoder.ok()); |
| 363 } |
| 364 } |
| 365 |
| 366 TEST_F(DecoderTest, ReadU32v_off_end3) { |
| 367 static const byte data[] = {U32V_3(111111)}; |
| 368 for (size_t i = 0; i < sizeof(data); i++) { |
| 369 int length = 0; |
| 370 decoder.Reset(data, data + i); |
| 371 decoder.checked_read_u32v(decoder.start(), 0, &length); |
| 372 EXPECT_EQ(i, length); |
| 373 EXPECT_FALSE(decoder.ok()); |
| 374 } |
| 375 } |
| 376 |
| 377 TEST_F(DecoderTest, ReadU32v_off_end4) { |
| 378 static const byte data[] = {U32V_4(11111111)}; |
| 379 for (size_t i = 0; i < sizeof(data); i++) { |
| 380 int length = 0; |
| 381 decoder.Reset(data, data + i); |
| 382 decoder.checked_read_u32v(decoder.start(), 0, &length); |
| 383 EXPECT_EQ(i, length); |
| 384 EXPECT_FALSE(decoder.ok()); |
| 385 } |
| 386 } |
| 387 |
| 388 TEST_F(DecoderTest, ReadU32v_off_end5) { |
| 389 static const byte data[] = {U32V_5(111111111)}; |
| 390 for (size_t i = 0; i < sizeof(data); i++) { |
| 391 int length = 0; |
| 392 decoder.Reset(data, data + i); |
| 393 decoder.checked_read_u32v(decoder.start(), 0, &length); |
| 394 EXPECT_EQ(i, length); |
| 395 EXPECT_FALSE(decoder.ok()); |
| 396 } |
| 397 } |
| 398 |
| 399 TEST_F(DecoderTest, ReadU32v_extra_bits) { |
| 400 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x00}; |
| 401 for (int i = 1; i < 16; i++) { |
| 402 data[4] = static_cast<byte>(i << 4); |
| 403 int length = 0; |
| 404 decoder.Reset(data, data + sizeof(data)); |
| 405 decoder.checked_read_u32v(decoder.start(), 0, &length); |
| 406 EXPECT_EQ(5, length); |
| 407 EXPECT_FALSE(decoder.ok()); |
| 408 } |
| 409 } |
| 410 |
| 411 } // namespace wasm |
| 412 } // namespace internal |
| 413 } // namespace v8 |
OLD | NEW |