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

Side by Side Diff: test/unittests/wasm/ast-decoder-unittest.cc

Issue 2492793005: [wasm] Fix more -Wsign-compare warnings. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « test/unittests/wasm/asm-types-unittest.cc ('k') | test/unittests/wasm/decoder-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/v8.h" 7 #include "src/v8.h"
8 8
9 #include "test/common/wasm/test-signatures.h" 9 #include "test/common/wasm/test-signatures.h"
10 10
(...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after
2239 kExprI32Add); 2239 kExprI32Add);
2240 } 2240 }
2241 2241
2242 class BranchTableIteratorTest : public TestWithZone { 2242 class BranchTableIteratorTest : public TestWithZone {
2243 public: 2243 public:
2244 BranchTableIteratorTest() : TestWithZone() {} 2244 BranchTableIteratorTest() : TestWithZone() {}
2245 void CheckBrTableSize(const byte* start, const byte* end) { 2245 void CheckBrTableSize(const byte* start, const byte* end) {
2246 Decoder decoder(start, end); 2246 Decoder decoder(start, end);
2247 BranchTableOperand operand(&decoder, start); 2247 BranchTableOperand operand(&decoder, start);
2248 BranchTableIterator iterator(&decoder, operand); 2248 BranchTableIterator iterator(&decoder, operand);
2249 EXPECT_EQ(end - start - 1, iterator.length()); 2249 EXPECT_EQ(end - start - 1u, iterator.length());
2250 EXPECT_TRUE(decoder.ok()); 2250 EXPECT_TRUE(decoder.ok());
2251 } 2251 }
2252 void CheckBrTableError(const byte* start, const byte* end) { 2252 void CheckBrTableError(const byte* start, const byte* end) {
2253 Decoder decoder(start, end); 2253 Decoder decoder(start, end);
2254 BranchTableOperand operand(&decoder, start); 2254 BranchTableOperand operand(&decoder, start);
2255 BranchTableIterator iterator(&decoder, operand); 2255 BranchTableIterator iterator(&decoder, operand);
2256 iterator.length(); 2256 iterator.length();
2257 EXPECT_FALSE(decoder.ok()); 2257 EXPECT_FALSE(decoder.ok());
2258 } 2258 }
2259 }; 2259 };
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 TEST_F(BranchTableIteratorTest, error0) { 2297 TEST_F(BranchTableIteratorTest, error0) {
2298 CHECK_BR_TABLE_ERROR(0); 2298 CHECK_BR_TABLE_ERROR(0);
2299 CHECK_BR_TABLE_ERROR(1, U32V_1(33)); 2299 CHECK_BR_TABLE_ERROR(1, U32V_1(33));
2300 } 2300 }
2301 2301
2302 class WasmOpcodeLengthTest : public TestWithZone { 2302 class WasmOpcodeLengthTest : public TestWithZone {
2303 public: 2303 public:
2304 WasmOpcodeLengthTest() : TestWithZone() {} 2304 WasmOpcodeLengthTest() : TestWithZone() {}
2305 }; 2305 };
2306 2306
2307 #define EXPECT_LENGTH(expected, opcode) \ 2307 #define EXPECT_LENGTH(expected, opcode) \
2308 { \ 2308 { \
2309 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \ 2309 static const byte code[] = {opcode, 0, 0, 0, 0, 0, 0, 0, 0}; \
2310 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ 2310 EXPECT_EQ(static_cast<unsigned>(expected), \
2311 OpcodeLength(code, code + sizeof(code))); \
2311 } 2312 }
2312 2313
2313 #define EXPECT_LENGTH_N(expected, ...) \ 2314 #define EXPECT_LENGTH_N(expected, ...) \
2314 { \ 2315 { \
2315 static const byte code[] = {__VA_ARGS__}; \ 2316 static const byte code[] = {__VA_ARGS__}; \
2316 EXPECT_EQ(expected, OpcodeLength(code, code + sizeof(code))); \ 2317 EXPECT_EQ(static_cast<unsigned>(expected), \
2318 OpcodeLength(code, code + sizeof(code))); \
2317 } 2319 }
2318 2320
2319 TEST_F(WasmOpcodeLengthTest, Statements) { 2321 TEST_F(WasmOpcodeLengthTest, Statements) {
2320 EXPECT_LENGTH(1, kExprNop); 2322 EXPECT_LENGTH(1, kExprNop);
2321 EXPECT_LENGTH(2, kExprBlock); 2323 EXPECT_LENGTH(2, kExprBlock);
2322 EXPECT_LENGTH(2, kExprLoop); 2324 EXPECT_LENGTH(2, kExprLoop);
2323 EXPECT_LENGTH(2, kExprIf); 2325 EXPECT_LENGTH(2, kExprIf);
2324 EXPECT_LENGTH(1, kExprElse); 2326 EXPECT_LENGTH(1, kExprElse);
2325 EXPECT_LENGTH(1, kExprEnd); 2327 EXPECT_LENGTH(1, kExprEnd);
2326 EXPECT_LENGTH(1, kExprSelect); 2328 EXPECT_LENGTH(1, kExprSelect);
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
2564 AstLocalDecls decls(zone()); 2566 AstLocalDecls decls(zone());
2565 bool result = DecodeLocalDecls(decls, nullptr, nullptr); 2567 bool result = DecodeLocalDecls(decls, nullptr, nullptr);
2566 EXPECT_FALSE(result); 2568 EXPECT_FALSE(result);
2567 } 2569 }
2568 2570
2569 TEST_F(LocalDeclDecoderTest, NoLocals) { 2571 TEST_F(LocalDeclDecoderTest, NoLocals) {
2570 static const byte data[] = {0}; 2572 static const byte data[] = {0};
2571 AstLocalDecls decls(zone()); 2573 AstLocalDecls decls(zone());
2572 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); 2574 bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
2573 EXPECT_TRUE(result); 2575 EXPECT_TRUE(result);
2574 EXPECT_EQ(0, decls.total_local_count); 2576 EXPECT_EQ(0u, decls.total_local_count);
2575 } 2577 }
2576 2578
2577 TEST_F(LocalDeclDecoderTest, OneLocal) { 2579 TEST_F(LocalDeclDecoderTest, OneLocal) {
2578 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 2580 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
2579 LocalType type = kLocalTypes[i]; 2581 LocalType type = kLocalTypes[i];
2580 const byte data[] = { 2582 const byte data[] = {
2581 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; 2583 1, 1, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))};
2582 AstLocalDecls decls(zone()); 2584 AstLocalDecls decls(zone());
2583 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); 2585 bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
2584 EXPECT_TRUE(result); 2586 EXPECT_TRUE(result);
2585 EXPECT_EQ(1, decls.total_local_count); 2587 EXPECT_EQ(1u, decls.total_local_count);
2586 2588
2587 LocalTypeMap map = Expand(decls); 2589 LocalTypeMap map = Expand(decls);
2588 EXPECT_EQ(1, map.size()); 2590 EXPECT_EQ(1u, map.size());
2589 EXPECT_EQ(type, map[0]); 2591 EXPECT_EQ(type, map[0]);
2590 } 2592 }
2591 } 2593 }
2592 2594
2593 TEST_F(LocalDeclDecoderTest, FiveLocals) { 2595 TEST_F(LocalDeclDecoderTest, FiveLocals) {
2594 for (size_t i = 0; i < arraysize(kLocalTypes); i++) { 2596 for (size_t i = 0; i < arraysize(kLocalTypes); i++) {
2595 LocalType type = kLocalTypes[i]; 2597 LocalType type = kLocalTypes[i];
2596 const byte data[] = { 2598 const byte data[] = {
2597 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))}; 2599 1, 5, static_cast<byte>(WasmOpcodes::LocalTypeCodeFor(type))};
2598 AstLocalDecls decls(zone()); 2600 AstLocalDecls decls(zone());
2599 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); 2601 bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
2600 EXPECT_TRUE(result); 2602 EXPECT_TRUE(result);
2601 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); 2603 EXPECT_EQ(sizeof(data), decls.decls_encoded_size);
2602 EXPECT_EQ(5, decls.total_local_count); 2604 EXPECT_EQ(5u, decls.total_local_count);
2603 2605
2604 LocalTypeMap map = Expand(decls); 2606 LocalTypeMap map = Expand(decls);
2605 EXPECT_EQ(5, map.size()); 2607 EXPECT_EQ(5u, map.size());
2606 ExpectRun(map, 0, type, 5); 2608 ExpectRun(map, 0, type, 5);
2607 } 2609 }
2608 } 2610 }
2609 2611
2610 TEST_F(LocalDeclDecoderTest, MixedLocals) { 2612 TEST_F(LocalDeclDecoderTest, MixedLocals) {
2611 for (byte a = 0; a < 3; a++) { 2613 for (byte a = 0; a < 3; a++) {
2612 for (byte b = 0; b < 3; b++) { 2614 for (byte b = 0; b < 3; b++) {
2613 for (byte c = 0; c < 3; c++) { 2615 for (byte c = 0; c < 3; c++) {
2614 for (byte d = 0; d < 3; d++) { 2616 for (byte d = 0; d < 3; d++) {
2615 const byte data[] = {4, a, kLocalI32, b, kLocalI64, 2617 const byte data[] = {4, a, kLocalI32, b, kLocalI64,
2616 c, kLocalF32, d, kLocalF64}; 2618 c, kLocalF32, d, kLocalF64};
2617 AstLocalDecls decls(zone()); 2619 AstLocalDecls decls(zone());
2618 bool result = DecodeLocalDecls(decls, data, data + sizeof(data)); 2620 bool result = DecodeLocalDecls(decls, data, data + sizeof(data));
2619 EXPECT_TRUE(result); 2621 EXPECT_TRUE(result);
2620 EXPECT_EQ(sizeof(data), decls.decls_encoded_size); 2622 EXPECT_EQ(sizeof(data), decls.decls_encoded_size);
2621 EXPECT_EQ(a + b + c + d, decls.total_local_count); 2623 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d),
2624 decls.total_local_count);
2622 2625
2623 LocalTypeMap map = Expand(decls); 2626 LocalTypeMap map = Expand(decls);
2624 EXPECT_EQ(a + b + c + d, map.size()); 2627 EXPECT_EQ(static_cast<uint32_t>(a + b + c + d), map.size());
2625 2628
2626 size_t pos = 0; 2629 size_t pos = 0;
2627 pos = ExpectRun(map, pos, kAstI32, a); 2630 pos = ExpectRun(map, pos, kAstI32, a);
2628 pos = ExpectRun(map, pos, kAstI64, b); 2631 pos = ExpectRun(map, pos, kAstI64, b);
2629 pos = ExpectRun(map, pos, kAstF32, c); 2632 pos = ExpectRun(map, pos, kAstF32, c);
2630 pos = ExpectRun(map, pos, kAstF64, d); 2633 pos = ExpectRun(map, pos, kAstF64, d);
2631 } 2634 }
2632 } 2635 }
2633 } 2636 }
2634 } 2637 }
2635 } 2638 }
2636 2639
2637 TEST_F(LocalDeclDecoderTest, UseEncoder) { 2640 TEST_F(LocalDeclDecoderTest, UseEncoder) {
2638 const byte* data = nullptr; 2641 const byte* data = nullptr;
2639 const byte* end = nullptr; 2642 const byte* end = nullptr;
2640 LocalDeclEncoder local_decls(zone()); 2643 LocalDeclEncoder local_decls(zone());
2641 2644
2642 local_decls.AddLocals(5, kAstF32); 2645 local_decls.AddLocals(5, kAstF32);
2643 local_decls.AddLocals(1337, kAstI32); 2646 local_decls.AddLocals(1337, kAstI32);
2644 local_decls.AddLocals(212, kAstI64); 2647 local_decls.AddLocals(212, kAstI64);
2645 local_decls.Prepend(zone(), &data, &end); 2648 local_decls.Prepend(zone(), &data, &end);
2646 2649
2647 AstLocalDecls decls(zone()); 2650 AstLocalDecls decls(zone());
2648 bool result = DecodeLocalDecls(decls, data, end); 2651 bool result = DecodeLocalDecls(decls, data, end);
2649 EXPECT_TRUE(result); 2652 EXPECT_TRUE(result);
2650 EXPECT_EQ(5 + 1337 + 212, decls.total_local_count); 2653 EXPECT_EQ(5u + 1337u + 212u, decls.total_local_count);
2651 2654
2652 LocalTypeMap map = Expand(decls); 2655 LocalTypeMap map = Expand(decls);
2653 size_t pos = 0; 2656 size_t pos = 0;
2654 pos = ExpectRun(map, pos, kAstF32, 5); 2657 pos = ExpectRun(map, pos, kAstF32, 5);
2655 pos = ExpectRun(map, pos, kAstI32, 1337); 2658 pos = ExpectRun(map, pos, kAstI32, 1337);
2656 pos = ExpectRun(map, pos, kAstI64, 212); 2659 pos = ExpectRun(map, pos, kAstI64, 212);
2657 } 2660 }
2658 2661
2659 class BytecodeIteratorTest : public TestWithZone {}; 2662 class BytecodeIteratorTest : public TestWithZone {};
2660 2663
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2692 count++; 2695 count++;
2693 } 2696 }
2694 EXPECT_EQ(6, count); 2697 EXPECT_EQ(6, count);
2695 } 2698 }
2696 2699
2697 TEST_F(BytecodeIteratorTest, WithAstDecls) { 2700 TEST_F(BytecodeIteratorTest, WithAstDecls) {
2698 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)}; 2701 byte code[] = {1, 1, kLocalI32, WASM_I8(9), WASM_I8(11)};
2699 AstLocalDecls decls(zone()); 2702 AstLocalDecls decls(zone());
2700 BytecodeIterator iter(code, code + sizeof(code), &decls); 2703 BytecodeIterator iter(code, code + sizeof(code), &decls);
2701 2704
2702 EXPECT_EQ(3, decls.decls_encoded_size); 2705 EXPECT_EQ(3u, decls.decls_encoded_size);
2703 EXPECT_EQ(3, iter.pc_offset()); 2706 EXPECT_EQ(3u, iter.pc_offset());
2704 EXPECT_TRUE(iter.has_next()); 2707 EXPECT_TRUE(iter.has_next());
2705 EXPECT_EQ(kExprI8Const, iter.current()); 2708 EXPECT_EQ(kExprI8Const, iter.current());
2706 iter.next(); 2709 iter.next();
2707 EXPECT_TRUE(iter.has_next()); 2710 EXPECT_TRUE(iter.has_next());
2708 EXPECT_EQ(kExprI8Const, iter.current()); 2711 EXPECT_EQ(kExprI8Const, iter.current());
2709 iter.next(); 2712 iter.next();
2710 EXPECT_FALSE(iter.has_next()); 2713 EXPECT_FALSE(iter.has_next());
2711 } 2714 }
2712 2715
2713 } // namespace wasm 2716 } // namespace wasm
2714 } // namespace internal 2717 } // namespace internal
2715 } // namespace v8 2718 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/wasm/asm-types-unittest.cc ('k') | test/unittests/wasm/decoder-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698