OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 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 | 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/objects-inl.h" | 7 #include "src/objects-inl.h" |
8 #include "src/wasm/decoder.h" | 8 #include "src/wasm/decoder.h" |
9 #include "src/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
10 | 10 |
11 namespace v8 { | 11 namespace v8 { |
12 namespace internal { | 12 namespace internal { |
13 namespace wasm { | 13 namespace wasm { |
14 | 14 |
15 class DecoderTest : public TestWithZone { | 15 class DecoderTest : public TestWithZone { |
16 public: | 16 public: |
17 DecoderTest() : decoder(nullptr, nullptr) {} | 17 DecoderTest() : decoder(nullptr, nullptr) {} |
18 | 18 |
19 Decoder decoder; | 19 Decoder decoder; |
20 }; | 20 }; |
21 | 21 |
22 #define CHECK_UINT32V_INLINE(expected, expected_length, ...) \ | 22 #define CHECK_UINT32V_INLINE(expected, expected_length, ...) \ |
23 do { \ | 23 do { \ |
24 const byte data[] = {__VA_ARGS__}; \ | 24 const byte data[] = {__VA_ARGS__}; \ |
25 decoder.Reset(data, data + sizeof(data)); \ | 25 decoder.Reset(data, data + sizeof(data)); \ |
26 unsigned length; \ | 26 unsigned length; \ |
27 EXPECT_EQ(expected, \ | 27 EXPECT_EQ(static_cast<uint32_t>(expected), \ |
28 decoder.checked_read_u32v(decoder.start(), 0, &length)); \ | 28 decoder.checked_read_u32v(decoder.start(), 0, &length)); \ |
29 EXPECT_EQ(expected_length, length); \ | 29 EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ |
30 EXPECT_EQ(data, decoder.pc()); \ | 30 EXPECT_EQ(data, decoder.pc()); \ |
31 EXPECT_TRUE(decoder.ok()); \ | 31 EXPECT_TRUE(decoder.ok()); \ |
32 EXPECT_EQ(expected, decoder.consume_u32v()); \ | 32 EXPECT_EQ(static_cast<uint32_t>(expected), decoder.consume_u32v()); \ |
33 EXPECT_EQ(data + expected_length, decoder.pc()); \ | 33 EXPECT_EQ(data + expected_length, decoder.pc()); \ |
34 } while (false) | 34 } while (false) |
35 | 35 |
36 #define CHECK_INT32V_INLINE(expected, expected_length, ...) \ | 36 #define CHECK_INT32V_INLINE(expected, expected_length, ...) \ |
37 do { \ | 37 do { \ |
38 const byte data[] = {__VA_ARGS__}; \ | 38 const byte data[] = {__VA_ARGS__}; \ |
39 decoder.Reset(data, data + sizeof(data)); \ | 39 decoder.Reset(data, data + sizeof(data)); \ |
40 unsigned length; \ | 40 unsigned length; \ |
41 EXPECT_EQ(expected, \ | 41 EXPECT_EQ(expected, \ |
42 decoder.checked_read_i32v(decoder.start(), 0, &length)); \ | 42 decoder.checked_read_i32v(decoder.start(), 0, &length)); \ |
43 EXPECT_EQ(expected_length, length); \ | 43 EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ |
44 EXPECT_EQ(data, decoder.pc()); \ | 44 EXPECT_EQ(data, decoder.pc()); \ |
45 EXPECT_TRUE(decoder.ok()); \ | 45 EXPECT_TRUE(decoder.ok()); \ |
46 EXPECT_EQ(expected, decoder.consume_i32v()); \ | 46 EXPECT_EQ(expected, decoder.consume_i32v()); \ |
47 EXPECT_EQ(data + expected_length, decoder.pc()); \ | 47 EXPECT_EQ(data + expected_length, decoder.pc()); \ |
48 } while (false) | 48 } while (false) |
49 | 49 |
50 #define CHECK_UINT64V_INLINE(expected, expected_length, ...) \ | 50 #define CHECK_UINT64V_INLINE(expected, expected_length, ...) \ |
51 do { \ | 51 do { \ |
52 const byte data[] = {__VA_ARGS__}; \ | 52 const byte data[] = {__VA_ARGS__}; \ |
53 decoder.Reset(data, data + sizeof(data)); \ | 53 decoder.Reset(data, data + sizeof(data)); \ |
54 unsigned length; \ | 54 unsigned length; \ |
55 EXPECT_EQ(expected, \ | 55 EXPECT_EQ(static_cast<uint64_t>(expected), \ |
56 decoder.checked_read_u64v(decoder.start(), 0, &length)); \ | 56 decoder.checked_read_u64v(decoder.start(), 0, &length)); \ |
57 EXPECT_EQ(expected_length, length); \ | 57 EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ |
58 } while (false) | 58 } while (false) |
59 | 59 |
60 #define CHECK_INT64V_INLINE(expected, expected_length, ...) \ | 60 #define CHECK_INT64V_INLINE(expected, expected_length, ...) \ |
61 do { \ | 61 do { \ |
62 const byte data[] = {__VA_ARGS__}; \ | 62 const byte data[] = {__VA_ARGS__}; \ |
63 decoder.Reset(data, data + sizeof(data)); \ | 63 decoder.Reset(data, data + sizeof(data)); \ |
64 unsigned length; \ | 64 unsigned length; \ |
65 EXPECT_EQ(expected, \ | 65 EXPECT_EQ(expected, \ |
66 decoder.checked_read_i64v(decoder.start(), 0, &length)); \ | 66 decoder.checked_read_i64v(decoder.start(), 0, &length)); \ |
67 EXPECT_EQ(expected_length, length); \ | 67 EXPECT_EQ(static_cast<unsigned>(expected_length), length); \ |
68 } while (false) | 68 } while (false) |
69 | 69 |
70 TEST_F(DecoderTest, ReadU32v_OneByte) { | 70 TEST_F(DecoderTest, ReadU32v_OneByte) { |
71 CHECK_UINT32V_INLINE(0, 1, 0); | 71 CHECK_UINT32V_INLINE(0, 1, 0); |
72 CHECK_UINT32V_INLINE(5, 1, 5); | 72 CHECK_UINT32V_INLINE(5, 1, 5); |
73 CHECK_UINT32V_INLINE(7, 1, 7); | 73 CHECK_UINT32V_INLINE(7, 1, 7); |
74 CHECK_UINT32V_INLINE(9, 1, 9); | 74 CHECK_UINT32V_INLINE(9, 1, 9); |
75 CHECK_UINT32V_INLINE(37, 1, 37); | 75 CHECK_UINT32V_INLINE(37, 1, 37); |
76 CHECK_UINT32V_INLINE(69, 1, 69); | 76 CHECK_UINT32V_INLINE(69, 1, 69); |
77 CHECK_UINT32V_INLINE(110, 1, 110); | 77 CHECK_UINT32V_INLINE(110, 1, 110); |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 for (int i = max; i > max - 10; i--) { | 370 for (int i = max; i > max - 10; i--) { |
371 CHECK_INT32V_INLINE(i, 5, U32V_5(i)); | 371 CHECK_INT32V_INLINE(i, 5, U32V_5(i)); |
372 } | 372 } |
373 } | 373 } |
374 | 374 |
375 TEST_F(DecoderTest, ReadU32v_off_end1) { | 375 TEST_F(DecoderTest, ReadU32v_off_end1) { |
376 static const byte data[] = {U32V_1(11)}; | 376 static const byte data[] = {U32V_1(11)}; |
377 unsigned length = 0; | 377 unsigned length = 0; |
378 decoder.Reset(data, data); | 378 decoder.Reset(data, data); |
379 decoder.checked_read_u32v(decoder.start(), 0, &length); | 379 decoder.checked_read_u32v(decoder.start(), 0, &length); |
380 EXPECT_EQ(0, length); | 380 EXPECT_EQ(0u, length); |
381 EXPECT_FALSE(decoder.ok()); | 381 EXPECT_FALSE(decoder.ok()); |
382 } | 382 } |
383 | 383 |
384 TEST_F(DecoderTest, ReadU32v_off_end2) { | 384 TEST_F(DecoderTest, ReadU32v_off_end2) { |
385 static const byte data[] = {U32V_2(1111)}; | 385 static const byte data[] = {U32V_2(1111)}; |
386 for (size_t i = 0; i < sizeof(data); i++) { | 386 for (size_t i = 0; i < sizeof(data); i++) { |
387 unsigned length = 0; | 387 unsigned length = 0; |
388 decoder.Reset(data, data + i); | 388 decoder.Reset(data, data + i); |
389 decoder.checked_read_u32v(decoder.start(), 0, &length); | 389 decoder.checked_read_u32v(decoder.start(), 0, &length); |
390 EXPECT_EQ(i, length); | 390 EXPECT_EQ(i, length); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 TEST_F(DecoderTest, ReadU32v_extra_bits) { | 428 TEST_F(DecoderTest, ReadU32v_extra_bits) { |
429 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x00}; | 429 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x00}; |
430 for (int i = 1; i < 16; i++) { | 430 for (int i = 1; i < 16; i++) { |
431 data[4] = static_cast<byte>(i << 4); | 431 data[4] = static_cast<byte>(i << 4); |
432 unsigned length = 0; | 432 unsigned length = 0; |
433 decoder.Reset(data, data + sizeof(data)); | 433 decoder.Reset(data, data + sizeof(data)); |
434 decoder.checked_read_u32v(decoder.start(), 0, &length); | 434 decoder.checked_read_u32v(decoder.start(), 0, &length); |
435 EXPECT_EQ(5, length); | 435 EXPECT_EQ(5u, length); |
436 EXPECT_FALSE(decoder.ok()); | 436 EXPECT_FALSE(decoder.ok()); |
437 } | 437 } |
438 } | 438 } |
439 | 439 |
440 TEST_F(DecoderTest, ReadI32v_extra_bits_negative) { | 440 TEST_F(DecoderTest, ReadI32v_extra_bits_negative) { |
441 // OK for negative signed values to have extra ones. | 441 // OK for negative signed values to have extra ones. |
442 unsigned length = 0; | 442 unsigned length = 0; |
443 byte data[] = {0xff, 0xff, 0xff, 0xff, 0x7f}; | 443 byte data[] = {0xff, 0xff, 0xff, 0xff, 0x7f}; |
444 decoder.Reset(data, data + sizeof(data)); | 444 decoder.Reset(data, data + sizeof(data)); |
445 decoder.checked_read_i32v(decoder.start(), 0, &length); | 445 decoder.checked_read_i32v(decoder.start(), 0, &length); |
446 EXPECT_EQ(5, length); | 446 EXPECT_EQ(5u, length); |
447 EXPECT_TRUE(decoder.ok()); | 447 EXPECT_TRUE(decoder.ok()); |
448 } | 448 } |
449 | 449 |
450 TEST_F(DecoderTest, ReadI32v_extra_bits_positive) { | 450 TEST_F(DecoderTest, ReadI32v_extra_bits_positive) { |
451 // Not OK for positive signed values to have extra ones. | 451 // Not OK for positive signed values to have extra ones. |
452 unsigned length = 0; | 452 unsigned length = 0; |
453 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x77}; | 453 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x77}; |
454 decoder.Reset(data, data + sizeof(data)); | 454 decoder.Reset(data, data + sizeof(data)); |
455 decoder.checked_read_i32v(decoder.start(), 0, &length); | 455 decoder.checked_read_i32v(decoder.start(), 0, &length); |
456 EXPECT_EQ(5, length); | 456 EXPECT_EQ(5u, length); |
457 EXPECT_FALSE(decoder.ok()); | 457 EXPECT_FALSE(decoder.ok()); |
458 } | 458 } |
459 | 459 |
460 TEST_F(DecoderTest, ReadU32v_Bits) { | 460 TEST_F(DecoderTest, ReadU32v_Bits) { |
461 // A more exhaustive test. | 461 // A more exhaustive test. |
462 const int kMaxSize = 5; | 462 const int kMaxSize = 5; |
463 const uint32_t kVals[] = { | 463 const uint32_t kVals[] = { |
464 0xaabbccdd, 0x11223344, 0x33445566, 0xffeeddcc, 0xF0F0F0F0, 0x0F0F0F0F, | 464 0xaabbccdd, 0x11223344, 0x33445566, 0xffeeddcc, 0xF0F0F0F0, 0x0F0F0F0F, |
465 0xEEEEEEEE, 0xAAAAAAAA, 0x12345678, 0x9abcdef0, 0x80309488, 0x729ed997, | 465 0xEEEEEEEE, 0xAAAAAAAA, 0x12345678, 0x9abcdef0, 0x80309488, 0x729ed997, |
466 0xc4a0cf81, 0x16c6eb85, 0x4206db8e, 0xf3b089d5, 0xaa2e223e, 0xf99e29c8, | 466 0xc4a0cf81, 0x16c6eb85, 0x4206db8e, 0xf3b089d5, 0xaa2e223e, 0xf99e29c8, |
467 0x4a4357d8, 0x1890b1c1, 0x8d80a085, 0xacb6ae4c, 0x1b827e10, 0xeb5c7bd9, | 467 0x4a4357d8, 0x1890b1c1, 0x8d80a085, 0xacb6ae4c, 0x1b827e10, 0xeb5c7bd9, |
468 0xbb1bc146, 0xdf57a33l}; | 468 0xbb1bc146, 0xdf57a33l}; |
469 byte data[kMaxSize]; | 469 byte data[kMaxSize]; |
470 | 470 |
471 // foreach value in above array | 471 // foreach value in above array |
472 for (size_t v = 0; v < arraysize(kVals); v++) { | 472 for (size_t v = 0; v < arraysize(kVals); v++) { |
473 // foreach length 1...32 | 473 // foreach length 1...32 |
474 for (int i = 1; i <= 32; i++) { | 474 for (int i = 1; i <= 32; i++) { |
475 uint32_t val = kVals[v]; | 475 uint32_t val = kVals[v]; |
476 if (i < 32) val &= ((1 << i) - 1); | 476 if (i < 32) val &= ((1 << i) - 1); |
477 | 477 |
478 int length = 1 + i / 7; | 478 unsigned length = 1 + i / 7; |
479 for (int j = 0; j < kMaxSize; j++) { | 479 for (unsigned j = 0; j < kMaxSize; j++) { |
480 data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7); | 480 data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7); |
481 } | 481 } |
482 for (int j = 0; j < length - 1; j++) { | 482 for (unsigned j = 0; j < length - 1; j++) { |
483 data[j] |= 0x80; | 483 data[j] |= 0x80; |
484 } | 484 } |
485 | 485 |
486 // foreach buffer size 0...5 | 486 // foreach buffer size 0...5 |
487 for (int limit = 0; limit <= kMaxSize; limit++) { | 487 for (unsigned limit = 0; limit <= kMaxSize; limit++) { |
488 decoder.Reset(data, data + limit); | 488 decoder.Reset(data, data + limit); |
489 unsigned rlen; | 489 unsigned rlen; |
490 uint32_t result = decoder.checked_read_u32v(data, 0, &rlen); | 490 uint32_t result = decoder.checked_read_u32v(data, 0, &rlen); |
491 if (limit < length) { | 491 if (limit < length) { |
492 EXPECT_FALSE(decoder.ok()); | 492 EXPECT_FALSE(decoder.ok()); |
493 } else { | 493 } else { |
494 EXPECT_TRUE(decoder.ok()); | 494 EXPECT_TRUE(decoder.ok()); |
495 EXPECT_EQ(val, result); | 495 EXPECT_EQ(val, result); |
496 EXPECT_EQ(length, rlen); | 496 EXPECT_EQ(length, rlen); |
497 } | 497 } |
(...skipping 29 matching lines...) Expand all Loading... |
527 CHECK_INT64V_INLINE(-11, 1, 117); | 527 CHECK_INT64V_INLINE(-11, 1, 117); |
528 CHECK_INT64V_INLINE(-62, 1, 66); | 528 CHECK_INT64V_INLINE(-62, 1, 66); |
529 CHECK_INT64V_INLINE(-63, 1, 65); | 529 CHECK_INT64V_INLINE(-63, 1, 65); |
530 CHECK_INT64V_INLINE(-64, 1, 64); | 530 CHECK_INT64V_INLINE(-64, 1, 64); |
531 } | 531 } |
532 | 532 |
533 TEST_F(DecoderTest, ReadU64v_PowerOf2) { | 533 TEST_F(DecoderTest, ReadU64v_PowerOf2) { |
534 const int kMaxSize = 10; | 534 const int kMaxSize = 10; |
535 byte data[kMaxSize]; | 535 byte data[kMaxSize]; |
536 | 536 |
537 for (int i = 0; i < 64; i++) { | 537 for (unsigned i = 0; i < 64; i++) { |
538 const uint64_t val = 1ull << i; | 538 const uint64_t val = 1ull << i; |
539 int index = i / 7; | 539 unsigned index = i / 7; |
540 data[index] = 1 << (i % 7); | 540 data[index] = 1 << (i % 7); |
541 memset(data, 0x80, index); | 541 memset(data, 0x80, index); |
542 | 542 |
543 for (int limit = 0; limit <= kMaxSize; limit++) { | 543 for (unsigned limit = 0; limit <= kMaxSize; limit++) { |
544 decoder.Reset(data, data + limit); | 544 decoder.Reset(data, data + limit); |
545 unsigned length; | 545 unsigned length; |
546 uint64_t result = decoder.checked_read_u64v(data, 0, &length); | 546 uint64_t result = decoder.checked_read_u64v(data, 0, &length); |
547 if (limit <= index) { | 547 if (limit <= index) { |
548 EXPECT_FALSE(decoder.ok()); | 548 EXPECT_FALSE(decoder.ok()); |
549 } else { | 549 } else { |
550 EXPECT_TRUE(decoder.ok()); | 550 EXPECT_TRUE(decoder.ok()); |
551 EXPECT_EQ(val, result); | 551 EXPECT_EQ(val, result); |
552 EXPECT_EQ(index + 1, length); | 552 EXPECT_EQ(index + 1, length); |
553 } | 553 } |
(...skipping 11 matching lines...) Expand all Loading... |
565 0x8d80a085acb6ae4cull, 0x1b827e10eb5c7bd9ull, 0xbb1bc146df57a338ull}; | 565 0x8d80a085acb6ae4cull, 0x1b827e10eb5c7bd9ull, 0xbb1bc146df57a338ull}; |
566 byte data[kMaxSize]; | 566 byte data[kMaxSize]; |
567 | 567 |
568 // foreach value in above array | 568 // foreach value in above array |
569 for (size_t v = 0; v < arraysize(kVals); v++) { | 569 for (size_t v = 0; v < arraysize(kVals); v++) { |
570 // foreach length 1...64 | 570 // foreach length 1...64 |
571 for (int i = 1; i <= 64; i++) { | 571 for (int i = 1; i <= 64; i++) { |
572 uint64_t val = kVals[v]; | 572 uint64_t val = kVals[v]; |
573 if (i < 64) val &= ((1ull << i) - 1); | 573 if (i < 64) val &= ((1ull << i) - 1); |
574 | 574 |
575 int length = 1 + i / 7; | 575 unsigned length = 1 + i / 7; |
576 for (int j = 0; j < kMaxSize; j++) { | 576 for (unsigned j = 0; j < kMaxSize; j++) { |
577 data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7); | 577 data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7); |
578 } | 578 } |
579 for (int j = 0; j < length - 1; j++) { | 579 for (unsigned j = 0; j < length - 1; j++) { |
580 data[j] |= 0x80; | 580 data[j] |= 0x80; |
581 } | 581 } |
582 | 582 |
583 // foreach buffer size 0...10 | 583 // foreach buffer size 0...10 |
584 for (int limit = 0; limit <= kMaxSize; limit++) { | 584 for (unsigned limit = 0; limit <= kMaxSize; limit++) { |
585 decoder.Reset(data, data + limit); | 585 decoder.Reset(data, data + limit); |
586 unsigned rlen; | 586 unsigned rlen; |
587 uint64_t result = decoder.checked_read_u64v(data, 0, &rlen); | 587 uint64_t result = decoder.checked_read_u64v(data, 0, &rlen); |
588 if (limit < length) { | 588 if (limit < length) { |
589 EXPECT_FALSE(decoder.ok()); | 589 EXPECT_FALSE(decoder.ok()); |
590 } else { | 590 } else { |
591 EXPECT_TRUE(decoder.ok()); | 591 EXPECT_TRUE(decoder.ok()); |
592 EXPECT_EQ(val, result); | 592 EXPECT_EQ(val, result); |
593 EXPECT_EQ(length, rlen); | 593 EXPECT_EQ(length, rlen); |
594 } | 594 } |
(...skipping 12 matching lines...) Expand all Loading... |
607 0x4206db8ef3b089d5ull, 0xaa2e223ef99e29c8ull, 0x4a4357d81890b1c1ull, | 607 0x4206db8ef3b089d5ull, 0xaa2e223ef99e29c8ull, 0x4a4357d81890b1c1ull, |
608 0x8d80a085acb6ae4cull, 0x1b827e10eb5c7bd9ull, 0xbb1bc146df57a338ull}; | 608 0x8d80a085acb6ae4cull, 0x1b827e10eb5c7bd9ull, 0xbb1bc146df57a338ull}; |
609 byte data[kMaxSize]; | 609 byte data[kMaxSize]; |
610 | 610 |
611 // foreach value in above array | 611 // foreach value in above array |
612 for (size_t v = 0; v < arraysize(kVals); v++) { | 612 for (size_t v = 0; v < arraysize(kVals); v++) { |
613 // foreach length 1...64 | 613 // foreach length 1...64 |
614 for (int i = 1; i <= 64; i++) { | 614 for (int i = 1; i <= 64; i++) { |
615 const int64_t val = bit_cast<int64_t>(kVals[v] << (64 - i)) >> (64 - i); | 615 const int64_t val = bit_cast<int64_t>(kVals[v] << (64 - i)) >> (64 - i); |
616 | 616 |
617 int length = 1 + i / 7; | 617 unsigned length = 1 + i / 7; |
618 for (int j = 0; j < kMaxSize; j++) { | 618 for (unsigned j = 0; j < kMaxSize; j++) { |
619 data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7); | 619 data[j] = static_cast<byte>((val >> (7 * j)) & MASK_7); |
620 } | 620 } |
621 for (int j = 0; j < length - 1; j++) { | 621 for (unsigned j = 0; j < length - 1; j++) { |
622 data[j] |= 0x80; | 622 data[j] |= 0x80; |
623 } | 623 } |
624 | 624 |
625 // foreach buffer size 0...10 | 625 // foreach buffer size 0...10 |
626 for (int limit = 0; limit <= kMaxSize; limit++) { | 626 for (unsigned limit = 0; limit <= kMaxSize; limit++) { |
627 decoder.Reset(data, data + limit); | 627 decoder.Reset(data, data + limit); |
628 unsigned rlen; | 628 unsigned rlen; |
629 int64_t result = decoder.checked_read_i64v(data, 0, &rlen); | 629 int64_t result = decoder.checked_read_i64v(data, 0, &rlen); |
630 if (limit < length) { | 630 if (limit < length) { |
631 EXPECT_FALSE(decoder.ok()); | 631 EXPECT_FALSE(decoder.ok()); |
632 } else { | 632 } else { |
633 EXPECT_TRUE(decoder.ok()); | 633 EXPECT_TRUE(decoder.ok()); |
634 EXPECT_EQ(val, result); | 634 EXPECT_EQ(val, result); |
635 EXPECT_EQ(length, rlen); | 635 EXPECT_EQ(length, rlen); |
636 } | 636 } |
637 } | 637 } |
638 } | 638 } |
639 } | 639 } |
640 } | 640 } |
641 | 641 |
642 TEST_F(DecoderTest, ReadU64v_extra_bits) { | 642 TEST_F(DecoderTest, ReadU64v_extra_bits) { |
643 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00}; | 643 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00}; |
644 for (int i = 1; i < 128; i++) { | 644 for (int i = 1; i < 128; i++) { |
645 data[9] = static_cast<byte>(i << 1); | 645 data[9] = static_cast<byte>(i << 1); |
646 unsigned length = 0; | 646 unsigned length = 0; |
647 decoder.Reset(data, data + sizeof(data)); | 647 decoder.Reset(data, data + sizeof(data)); |
648 decoder.checked_read_u64v(decoder.start(), 0, &length); | 648 decoder.checked_read_u64v(decoder.start(), 0, &length); |
649 EXPECT_EQ(10, length); | 649 EXPECT_EQ(10u, length); |
650 EXPECT_FALSE(decoder.ok()); | 650 EXPECT_FALSE(decoder.ok()); |
651 } | 651 } |
652 } | 652 } |
653 | 653 |
654 TEST_F(DecoderTest, ReadI64v_extra_bits_negative) { | 654 TEST_F(DecoderTest, ReadI64v_extra_bits_negative) { |
655 // OK for negative signed values to have extra ones. | 655 // OK for negative signed values to have extra ones. |
656 unsigned length = 0; | 656 unsigned length = 0; |
657 byte data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}; | 657 byte data[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}; |
658 decoder.Reset(data, data + sizeof(data)); | 658 decoder.Reset(data, data + sizeof(data)); |
659 decoder.checked_read_i64v(decoder.start(), 0, &length); | 659 decoder.checked_read_i64v(decoder.start(), 0, &length); |
660 EXPECT_EQ(10, length); | 660 EXPECT_EQ(10u, length); |
661 EXPECT_TRUE(decoder.ok()); | 661 EXPECT_TRUE(decoder.ok()); |
662 } | 662 } |
663 | 663 |
664 TEST_F(DecoderTest, ReadI64v_extra_bits_positive) { | 664 TEST_F(DecoderTest, ReadI64v_extra_bits_positive) { |
665 // Not OK for positive signed values to have extra ones. | 665 // Not OK for positive signed values to have extra ones. |
666 unsigned length = 0; | 666 unsigned length = 0; |
667 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77}; | 667 byte data[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x77}; |
668 decoder.Reset(data, data + sizeof(data)); | 668 decoder.Reset(data, data + sizeof(data)); |
669 decoder.checked_read_i64v(decoder.start(), 0, &length); | 669 decoder.checked_read_i64v(decoder.start(), 0, &length); |
670 EXPECT_EQ(10, length); | 670 EXPECT_EQ(10u, length); |
671 EXPECT_FALSE(decoder.ok()); | 671 EXPECT_FALSE(decoder.ok()); |
672 } | 672 } |
673 | 673 |
674 TEST_F(DecoderTest, FailOnNullData) { | 674 TEST_F(DecoderTest, FailOnNullData) { |
675 decoder.Reset(nullptr, 0); | 675 decoder.Reset(nullptr, 0); |
676 decoder.checkAvailable(1); | 676 decoder.checkAvailable(1); |
677 EXPECT_FALSE(decoder.ok()); | 677 EXPECT_FALSE(decoder.ok()); |
678 EXPECT_FALSE(decoder.toResult(nullptr).ok()); | 678 EXPECT_FALSE(decoder.toResult(nullptr).ok()); |
679 } | 679 } |
680 | 680 |
681 } // namespace wasm | 681 } // namespace wasm |
682 } // namespace internal | 682 } // namespace internal |
683 } // namespace v8 | 683 } // namespace v8 |
OLD | NEW |