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/leb-helper.h" | 9 #include "src/wasm/leb-helper.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 LEBHelperTest : public TestWithZone {}; | 15 class LEBHelperTest : public TestWithZone {}; |
16 | 16 |
17 TEST_F(LEBHelperTest, sizeof_u32v) { | 17 TEST_F(LEBHelperTest, sizeof_u32v) { |
18 EXPECT_EQ(1, LEBHelper::sizeof_u32v(0)); | 18 EXPECT_EQ(1u, LEBHelper::sizeof_u32v(0)); |
19 EXPECT_EQ(1, LEBHelper::sizeof_u32v(1)); | 19 EXPECT_EQ(1u, LEBHelper::sizeof_u32v(1)); |
20 EXPECT_EQ(1, LEBHelper::sizeof_u32v(3)); | 20 EXPECT_EQ(1u, LEBHelper::sizeof_u32v(3)); |
21 | 21 |
22 for (uint32_t i = 4; i < 128; i++) { | 22 for (uint32_t i = 4; i < 128; i++) { |
23 EXPECT_EQ(1, LEBHelper::sizeof_u32v(i)); | 23 EXPECT_EQ(1u, LEBHelper::sizeof_u32v(i)); |
24 } | 24 } |
25 | 25 |
26 for (uint32_t i = (1u << 7); i < (1u << 9); i++) { | 26 for (uint32_t i = (1u << 7); i < (1u << 9); i++) { |
27 EXPECT_EQ(2, LEBHelper::sizeof_u32v(i)); | 27 EXPECT_EQ(2u, LEBHelper::sizeof_u32v(i)); |
28 } | 28 } |
29 | 29 |
30 for (uint32_t i = (1u << 14); i < (1u << 16); i += 33) { | 30 for (uint32_t i = (1u << 14); i < (1u << 16); i += 33) { |
31 EXPECT_EQ(3, LEBHelper::sizeof_u32v(i)); | 31 EXPECT_EQ(3u, LEBHelper::sizeof_u32v(i)); |
32 } | 32 } |
33 | 33 |
34 for (uint32_t i = (1u << 21); i < (1u << 24); i += 33999) { | 34 for (uint32_t i = (1u << 21); i < (1u << 24); i += 33999) { |
35 EXPECT_EQ(4, LEBHelper::sizeof_u32v(i)); | 35 EXPECT_EQ(4u, LEBHelper::sizeof_u32v(i)); |
36 } | 36 } |
37 | 37 |
38 for (uint32_t i = (1u << 28); i < (1u << 31); i += 33997779u) { | 38 for (uint32_t i = (1u << 28); i < (1u << 31); i += 33997779u) { |
39 EXPECT_EQ(5, LEBHelper::sizeof_u32v(i)); | 39 EXPECT_EQ(5u, LEBHelper::sizeof_u32v(i)); |
40 } | 40 } |
41 | 41 |
42 EXPECT_EQ(5, LEBHelper::sizeof_u32v(0xFFFFFFFF)); | 42 EXPECT_EQ(5u, LEBHelper::sizeof_u32v(0xFFFFFFFF)); |
43 } | 43 } |
44 | 44 |
45 TEST_F(LEBHelperTest, sizeof_i32v) { | 45 TEST_F(LEBHelperTest, sizeof_i32v) { |
46 EXPECT_EQ(1, LEBHelper::sizeof_i32v(0)); | 46 EXPECT_EQ(1u, LEBHelper::sizeof_i32v(0)); |
47 EXPECT_EQ(1, LEBHelper::sizeof_i32v(1)); | 47 EXPECT_EQ(1u, LEBHelper::sizeof_i32v(1)); |
48 EXPECT_EQ(1, LEBHelper::sizeof_i32v(3)); | 48 EXPECT_EQ(1u, LEBHelper::sizeof_i32v(3)); |
49 | 49 |
50 for (int32_t i = 0; i < (1 << 6); i++) { | 50 for (int32_t i = 0; i < (1 << 6); i++) { |
51 EXPECT_EQ(1, LEBHelper::sizeof_i32v(i)); | 51 EXPECT_EQ(1u, LEBHelper::sizeof_i32v(i)); |
52 } | 52 } |
53 | 53 |
54 for (int32_t i = (1 << 6); i < (1 << 8); i++) { | 54 for (int32_t i = (1 << 6); i < (1 << 8); i++) { |
55 EXPECT_EQ(2, LEBHelper::sizeof_i32v(i)); | 55 EXPECT_EQ(2u, LEBHelper::sizeof_i32v(i)); |
56 } | 56 } |
57 | 57 |
58 for (int32_t i = (1 << 13); i < (1 << 15); i += 31) { | 58 for (int32_t i = (1 << 13); i < (1 << 15); i += 31) { |
59 EXPECT_EQ(3, LEBHelper::sizeof_i32v(i)); | 59 EXPECT_EQ(3u, LEBHelper::sizeof_i32v(i)); |
60 } | 60 } |
61 | 61 |
62 for (int32_t i = (1 << 20); i < (1 << 22); i += 31991) { | 62 for (int32_t i = (1 << 20); i < (1 << 22); i += 31991) { |
63 EXPECT_EQ(4, LEBHelper::sizeof_i32v(i)); | 63 EXPECT_EQ(4u, LEBHelper::sizeof_i32v(i)); |
64 } | 64 } |
65 | 65 |
66 for (int32_t i = (1 << 27); i < (1 << 29); i += 3199893) { | 66 for (int32_t i = (1 << 27); i < (1 << 29); i += 3199893) { |
67 EXPECT_EQ(5, LEBHelper::sizeof_i32v(i)); | 67 EXPECT_EQ(5u, LEBHelper::sizeof_i32v(i)); |
68 } | 68 } |
69 | 69 |
70 for (int32_t i = -(1 << 6); i <= 0; i++) { | 70 for (int32_t i = -(1 << 6); i <= 0; i++) { |
71 EXPECT_EQ(1, LEBHelper::sizeof_i32v(i)); | 71 EXPECT_EQ(1u, LEBHelper::sizeof_i32v(i)); |
72 } | 72 } |
73 | 73 |
74 for (int32_t i = -(1 << 13); i < -(1 << 6); i++) { | 74 for (int32_t i = -(1 << 13); i < -(1 << 6); i++) { |
75 EXPECT_EQ(2, LEBHelper::sizeof_i32v(i)); | 75 EXPECT_EQ(2u, LEBHelper::sizeof_i32v(i)); |
76 } | 76 } |
77 | 77 |
78 for (int32_t i = -(1 << 20); i < -(1 << 18); i += 11) { | 78 for (int32_t i = -(1 << 20); i < -(1 << 18); i += 11) { |
79 EXPECT_EQ(3, LEBHelper::sizeof_i32v(i)); | 79 EXPECT_EQ(3u, LEBHelper::sizeof_i32v(i)); |
80 } | 80 } |
81 | 81 |
82 for (int32_t i = -(1 << 27); i < -(1 << 25); i += 11999) { | 82 for (int32_t i = -(1 << 27); i < -(1 << 25); i += 11999) { |
83 EXPECT_EQ(4, LEBHelper::sizeof_i32v(i)); | 83 EXPECT_EQ(4u, LEBHelper::sizeof_i32v(i)); |
84 } | 84 } |
85 | 85 |
86 for (int32_t i = -(1 << 30); i < -(1 << 28); i += 1199999) { | 86 for (int32_t i = -(1 << 30); i < -(1 << 28); i += 1199999) { |
87 EXPECT_EQ(5, LEBHelper::sizeof_i32v(i)); | 87 EXPECT_EQ(5u, LEBHelper::sizeof_i32v(i)); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 #define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \ | 91 #define DECLARE_ENCODE_DECODE_CHECKER(ctype, name) \ |
92 static void CheckEncodeDecode_##name(ctype val) { \ | 92 static void CheckEncodeDecode_##name(ctype val) { \ |
93 static const int kSize = 16; \ | 93 static const int kSize = 16; \ |
94 static byte buffer[kSize]; \ | 94 static byte buffer[kSize]; \ |
95 byte *ptr = buffer; \ | 95 byte *ptr = buffer; \ |
96 LEBHelper::write_##name(&ptr, val); \ | 96 LEBHelper::write_##name(&ptr, val); \ |
97 EXPECT_EQ(LEBHelper::sizeof_##name(val), \ | 97 EXPECT_EQ(LEBHelper::sizeof_##name(val), \ |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); | 182 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); |
183 } | 183 } |
184 | 184 |
185 for (uint64_t val = 0xFFFFFFFFFFFFFF3B; val != 0; val = val << 1) { | 185 for (uint64_t val = 0xFFFFFFFFFFFFFF3B; val != 0; val = val << 1) { |
186 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); | 186 CheckEncodeDecode_i64v(bit_cast<int64_t>(val)); |
187 } | 187 } |
188 } | 188 } |
189 } // namespace wasm | 189 } // namespace wasm |
190 } // namespace internal | 190 } // namespace internal |
191 } // namespace v8 | 191 } // namespace v8 |
OLD | NEW |