OLD | NEW |
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/cctest/wasm/test-signatures.h" | 9 #include "test/cctest/wasm/test-signatures.h" |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 FunctionEnv env_v_i; | 80 FunctionEnv env_v_i; |
81 FunctionEnv env_i_f; | 81 FunctionEnv env_i_f; |
82 FunctionEnv env_i_d; | 82 FunctionEnv env_i_d; |
83 FunctionEnv env_l_l; | 83 FunctionEnv env_l_l; |
84 FunctionEnv env_f_ff; | 84 FunctionEnv env_f_ff; |
85 FunctionEnv env_d_dd; | 85 FunctionEnv env_d_dd; |
86 | 86 |
87 static void init_env(FunctionEnv* env, FunctionSig* sig) { | 87 static void init_env(FunctionEnv* env, FunctionSig* sig) { |
88 env->module = nullptr; | 88 env->module = nullptr; |
89 env->sig = sig; | 89 env->sig = sig; |
90 env->local_int32_count = 0; | 90 env->local_i32_count = 0; |
91 env->local_int64_count = 0; | 91 env->local_i64_count = 0; |
92 env->local_float32_count = 0; | 92 env->local_f32_count = 0; |
93 env->local_float64_count = 0; | 93 env->local_f64_count = 0; |
94 env->SumLocals(); | 94 env->SumLocals(); |
95 } | 95 } |
96 | 96 |
97 // A wrapper around VerifyWasmCode() that renders a nice failure message. | 97 // A wrapper around VerifyWasmCode() that renders a nice failure message. |
98 void Verify(ErrorCode expected, FunctionEnv* env, const byte* start, | 98 void Verify(ErrorCode expected, FunctionEnv* env, const byte* start, |
99 const byte* end) { | 99 const byte* end) { |
100 TreeResult result = VerifyWasmCode(env, start, end); | 100 TreeResult result = VerifyWasmCode(env, start, end); |
101 if (result.error_code != expected) { | 101 if (result.error_code != expected) { |
102 ptrdiff_t pc = result.error_pc - result.start; | 102 ptrdiff_t pc = result.error_pc - result.start; |
103 ptrdiff_t pt = result.error_pt - result.start; | 103 ptrdiff_t pt = result.error_pt - result.start; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 } | 173 } |
174 } | 174 } |
175 }; | 175 }; |
176 | 176 |
177 | 177 |
178 static FunctionEnv CreateInt32FunctionEnv(FunctionSig* sig, int count) { | 178 static FunctionEnv CreateInt32FunctionEnv(FunctionSig* sig, int count) { |
179 FunctionEnv env; | 179 FunctionEnv env; |
180 env.module = nullptr; | 180 env.module = nullptr; |
181 env.sig = sig; | 181 env.sig = sig; |
182 env.local_int32_count = count; | 182 env.local_i32_count = count; |
183 env.local_float64_count = 0; | 183 env.local_f64_count = 0; |
184 env.local_float32_count = 0; | 184 env.local_f32_count = 0; |
185 env.total_locals = static_cast<unsigned>(count + sig->parameter_count()); | 185 env.total_locals = static_cast<unsigned>(count + sig->parameter_count()); |
186 return env; | 186 return env; |
187 } | 187 } |
188 | 188 |
189 | 189 |
190 TEST_F(WasmDecoderTest, Int8Const) { | 190 TEST_F(WasmDecoderTest, Int8Const) { |
191 byte code[] = {kExprI8Const, 0}; | 191 byte code[] = {kExprI8Const, 0}; |
192 for (int i = -128; i < 128; i++) { | 192 for (int i = -128; i < 128; i++) { |
193 code[1] = static_cast<byte>(i); | 193 code[1] = static_cast<byte>(i); |
194 EXPECT_VERIFIES(&env_i_i, code); | 194 EXPECT_VERIFIES(&env_i_i, code); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 } | 326 } |
327 | 327 |
328 | 328 |
329 TEST_F(WasmDecoderTest, GetLocal_off_end) { | 329 TEST_F(WasmDecoderTest, GetLocal_off_end) { |
330 static const byte code[] = {kExprGetLocal}; | 330 static const byte code[] = {kExprGetLocal}; |
331 EXPECT_FAILURE(&env_i_i, code); | 331 EXPECT_FAILURE(&env_i_i, code); |
332 } | 332 } |
333 | 333 |
334 | 334 |
335 TEST_F(WasmDecoderTest, GetLocal_varint) { | 335 TEST_F(WasmDecoderTest, GetLocal_varint) { |
336 env_i_i.local_int32_count = 1000000000; | 336 env_i_i.local_i32_count = 1000000000; |
337 env_i_i.total_locals += 1000000000; | 337 env_i_i.total_locals += 1000000000; |
338 | 338 |
339 { | 339 { |
340 static const byte code[] = {kExprGetLocal, 0xFF, 0x01}; | 340 static const byte code[] = {kExprGetLocal, 0xFF, 0x01}; |
341 EXPECT_VERIFIES(&env_i_i, code); | 341 EXPECT_VERIFIES(&env_i_i, code); |
342 EXPECT_FAILURE(&env_i_f, code); | 342 EXPECT_FAILURE(&env_i_f, code); |
343 } | 343 } |
344 | 344 |
345 { | 345 { |
346 static const byte code[] = {kExprGetLocal, 0xF0, 0x80, 0x01}; | 346 static const byte code[] = {kExprGetLocal, 0xF0, 0x80, 0x01}; |
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 EXPECT_ARITY(1, kExprF64SConvertI64); | 2377 EXPECT_ARITY(1, kExprF64SConvertI64); |
2378 EXPECT_ARITY(1, kExprF64UConvertI64); | 2378 EXPECT_ARITY(1, kExprF64UConvertI64); |
2379 EXPECT_ARITY(1, kExprF64ConvertF32); | 2379 EXPECT_ARITY(1, kExprF64ConvertF32); |
2380 EXPECT_ARITY(1, kExprF64ReinterpretI64); | 2380 EXPECT_ARITY(1, kExprF64ReinterpretI64); |
2381 EXPECT_ARITY(1, kExprI32ReinterpretF32); | 2381 EXPECT_ARITY(1, kExprI32ReinterpretF32); |
2382 EXPECT_ARITY(1, kExprI64ReinterpretF64); | 2382 EXPECT_ARITY(1, kExprI64ReinterpretF64); |
2383 } | 2383 } |
2384 } // namespace wasm | 2384 } // namespace wasm |
2385 } // namespace internal | 2385 } // namespace internal |
2386 } // namespace v8 | 2386 } // namespace v8 |
OLD | NEW |