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 <stdint.h> | 5 #include <stdint.h> |
6 #include <stdlib.h> | 6 #include <stdlib.h> |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "src/base/platform/elapsed-timer.h" | 9 #include "src/base/platform/elapsed-timer.h" |
10 | 10 |
11 #include "src/wasm/wasm-macro-gen.h" | 11 #include "src/wasm/wasm-macro-gen.h" |
12 | 12 |
13 #include "test/cctest/cctest.h" | 13 #include "test/cctest/cctest.h" |
14 #include "test/cctest/compiler/value-helper.h" | 14 #include "test/cctest/compiler/value-helper.h" |
15 #include "test/cctest/wasm/test-signatures.h" | 15 #include "test/cctest/wasm/test-signatures.h" |
16 #include "test/cctest/wasm/wasm-run-utils.h" | 16 #include "test/cctest/wasm/wasm-run-utils.h" |
17 | 17 |
18 using namespace v8::base; | 18 using namespace v8::base; |
19 using namespace v8::internal; | 19 using namespace v8::internal; |
20 using namespace v8::internal::compiler; | 20 using namespace v8::internal::compiler; |
21 using namespace v8::internal::wasm; | 21 using namespace v8::internal::wasm; |
22 | 22 |
23 // for even shorter tests. | 23 // for even shorter tests. |
24 #define B2(a, b) kExprBlock, a, b, kExprEnd | 24 #define B2(a, b) kExprBlock, a, b, kExprEnd |
25 #define B1(a) kExprBlock, a, kExprEnd | 25 #define B1(a) kExprBlock, a, kExprEnd |
26 #define RET(x) x, kExprReturn, 1 | 26 #define RET(x) x, kExprReturn, 1 |
27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 | 27 #define RET_I8(x) kExprI8Const, x, kExprReturn, 1 |
28 | 28 |
29 #define IF_COMPILED(expr) \ | |
30 if (execution_mode == kExecuteCompiled) { \ | |
31 expr; \ | |
32 } | |
33 | |
34 namespace { | |
35 uint32_t GetMatchingRelocInfoCount(Handle<Code> code, RelocInfo::Mode rmode) { | |
36 int filter = 1 << rmode; | |
37 uint32_t ret = 0; | |
38 for (RelocIterator it(*code, filter); !it.done(); it.next()) { | |
39 ++ret; | |
40 } | |
41 return ret; | |
42 } | |
43 } | |
44 | |
29 WASM_EXEC_TEST(Int32AsmjsDivS) { | 45 WASM_EXEC_TEST(Int32AsmjsDivS) { |
30 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), | 46 WasmRunner<int32_t> r(execution_mode, MachineType::Int32(), |
31 MachineType::Int32()); | 47 MachineType::Int32()); |
32 BUILD(r, WASM_BINOP(kExprI32AsmjsDivS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); | 48 BUILD(r, WASM_BINOP(kExprI32AsmjsDivS, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); |
33 const int32_t kMin = std::numeric_limits<int32_t>::min(); | 49 const int32_t kMin = std::numeric_limits<int32_t>::min(); |
34 CHECK_EQ(0, r.Call(0, 100)); | 50 CHECK_EQ(0, r.Call(0, 100)); |
35 CHECK_EQ(0, r.Call(100, 0)); | 51 CHECK_EQ(0, r.Call(100, 0)); |
36 CHECK_EQ(0, r.Call(-1001, 0)); | 52 CHECK_EQ(0, r.Call(-1001, 0)); |
37 CHECK_EQ(kMin, r.Call(kMin, -1)); | 53 CHECK_EQ(kMin, r.Call(kMin, -1)); |
38 CHECK_EQ(0, r.Call(kMin, 0)); | 54 CHECK_EQ(0, r.Call(kMin, 0)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 } | 131 } |
116 | 132 |
117 WASM_EXEC_TEST(LoadMemI32_oob_asm) { | 133 WASM_EXEC_TEST(LoadMemI32_oob_asm) { |
118 TestingModule module(execution_mode); | 134 TestingModule module(execution_mode); |
119 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 135 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
120 WasmRunner<int32_t> r(&module, MachineType::Uint32()); | 136 WasmRunner<int32_t> r(&module, MachineType::Uint32()); |
121 module.RandomizeMemory(1112); | 137 module.RandomizeMemory(1112); |
122 | 138 |
123 BUILD(r, WASM_UNOP(kExprI32AsmjsLoadMem, WASM_GET_LOCAL(0))); | 139 BUILD(r, WASM_UNOP(kExprI32AsmjsLoadMem, WASM_GET_LOCAL(0))); |
124 | 140 |
141 IF_COMPILED( | |
bradnelson
2016/06/12 20:50:14
Worth making these separate from the oob test? Thi
Mircea Trofin
2016/06/13 03:33:09
Good point, thanks. Added a battery of tests for t
| |
142 CHECK_EQ(1, GetMatchingRelocInfoCount(module.instance->function_code[0], | |
143 RelocInfo::WASM_MEMORY_REFERENCE))); | |
125 memory[0] = 999999; | 144 memory[0] = 999999; |
126 CHECK_EQ(999999, r.Call(0u)); | 145 CHECK_EQ(999999, r.Call(0u)); |
127 // TODO(titzer): offset 29-31 should also be OOB. | 146 // TODO(titzer): offset 29-31 should also be OOB. |
128 for (uint32_t offset = 32; offset < 40; offset++) { | 147 for (uint32_t offset = 32; offset < 40; offset++) { |
129 CHECK_EQ(0, r.Call(offset)); | 148 CHECK_EQ(0, r.Call(offset)); |
130 } | 149 } |
131 | 150 |
132 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 151 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
133 CHECK_EQ(0, r.Call(offset)); | 152 CHECK_EQ(0, r.Call(offset)); |
134 } | 153 } |
135 } | 154 } |
136 | 155 |
137 WASM_EXEC_TEST(LoadMemF32_oob_asm) { | 156 WASM_EXEC_TEST(LoadMemF32_oob_asm) { |
138 TestingModule module(execution_mode); | 157 TestingModule module(execution_mode); |
139 float* memory = module.AddMemoryElems<float>(8); | 158 float* memory = module.AddMemoryElems<float>(8); |
140 WasmRunner<float> r(&module, MachineType::Uint32()); | 159 WasmRunner<float> r(&module, MachineType::Uint32()); |
141 module.RandomizeMemory(1112); | 160 module.RandomizeMemory(1112); |
142 | 161 |
143 BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0))); | 162 BUILD(r, WASM_UNOP(kExprF32AsmjsLoadMem, WASM_GET_LOCAL(0))); |
144 | 163 |
164 IF_COMPILED( | |
165 CHECK_EQ(1, GetMatchingRelocInfoCount(module.instance->function_code[0], | |
166 RelocInfo::WASM_MEMORY_REFERENCE))); | |
167 | |
145 memory[0] = 9999.5f; | 168 memory[0] = 9999.5f; |
146 CHECK_EQ(9999.5f, r.Call(0u)); | 169 CHECK_EQ(9999.5f, r.Call(0u)); |
147 // TODO(titzer): offset 29-31 should also be OOB. | 170 // TODO(titzer): offset 29-31 should also be OOB. |
148 for (uint32_t offset = 32; offset < 40; offset++) { | 171 for (uint32_t offset = 32; offset < 40; offset++) { |
149 CHECK(std::isnan(r.Call(offset))); | 172 CHECK(std::isnan(r.Call(offset))); |
150 } | 173 } |
151 | 174 |
152 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 175 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
153 CHECK(std::isnan(r.Call(offset))); | 176 CHECK(std::isnan(r.Call(offset))); |
154 } | 177 } |
155 } | 178 } |
156 | 179 |
157 WASM_EXEC_TEST(LoadMemF64_oob_asm) { | 180 WASM_EXEC_TEST(LoadMemF64_oob_asm) { |
158 TestingModule module(execution_mode); | 181 TestingModule module(execution_mode); |
159 double* memory = module.AddMemoryElems<double>(8); | 182 double* memory = module.AddMemoryElems<double>(8); |
160 WasmRunner<double> r(&module, MachineType::Uint32()); | 183 WasmRunner<double> r(&module, MachineType::Uint32()); |
161 module.RandomizeMemory(1112); | 184 module.RandomizeMemory(1112); |
162 | 185 |
163 BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0))); | 186 BUILD(r, WASM_UNOP(kExprF64AsmjsLoadMem, WASM_GET_LOCAL(0))); |
164 | 187 |
188 IF_COMPILED( | |
189 CHECK_EQ(1, GetMatchingRelocInfoCount(module.instance->function_code[0], | |
190 RelocInfo::WASM_MEMORY_REFERENCE))); | |
191 | |
165 memory[0] = 9799.5; | 192 memory[0] = 9799.5; |
166 CHECK_EQ(9799.5, r.Call(0u)); | 193 CHECK_EQ(9799.5, r.Call(0u)); |
167 memory[1] = 11799.25; | 194 memory[1] = 11799.25; |
168 CHECK_EQ(11799.25, r.Call(8u)); | 195 CHECK_EQ(11799.25, r.Call(8u)); |
169 // TODO(titzer): offset 57-63 should also be OOB. | 196 // TODO(titzer): offset 57-63 should also be OOB. |
170 for (uint32_t offset = 64; offset < 80; offset++) { | 197 for (uint32_t offset = 64; offset < 80; offset++) { |
171 CHECK(std::isnan(r.Call(offset))); | 198 CHECK(std::isnan(r.Call(offset))); |
172 } | 199 } |
173 | 200 |
174 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { | 201 for (uint32_t offset = 0x80000000; offset < 0x80000010; offset++) { |
175 CHECK(std::isnan(r.Call(offset))); | 202 CHECK(std::isnan(r.Call(offset))); |
176 } | 203 } |
177 } | 204 } |
178 | 205 |
179 WASM_EXEC_TEST(StoreMemI32_oob_asm) { | 206 WASM_EXEC_TEST(StoreMemI32_oob_asm) { |
180 TestingModule module(execution_mode); | 207 TestingModule module(execution_mode); |
181 int32_t* memory = module.AddMemoryElems<int32_t>(8); | 208 int32_t* memory = module.AddMemoryElems<int32_t>(8); |
182 WasmRunner<int32_t> r(&module, MachineType::Uint32(), MachineType::Uint32()); | 209 WasmRunner<int32_t> r(&module, MachineType::Uint32(), MachineType::Uint32()); |
183 module.RandomizeMemory(1112); | 210 module.RandomizeMemory(1112); |
184 | 211 |
185 BUILD(r, WASM_BINOP(kExprI32AsmjsStoreMem, WASM_GET_LOCAL(0), | 212 BUILD(r, WASM_BINOP(kExprI32AsmjsStoreMem, WASM_GET_LOCAL(0), |
186 WASM_GET_LOCAL(1))); | 213 WASM_GET_LOCAL(1))); |
187 | 214 |
215 IF_COMPILED( | |
216 CHECK_EQ(1, GetMatchingRelocInfoCount(module.instance->function_code[0], | |
217 RelocInfo::WASM_MEMORY_REFERENCE))); | |
218 | |
188 memory[0] = 7777; | 219 memory[0] = 7777; |
189 CHECK_EQ(999999, r.Call(0u, 999999)); | 220 CHECK_EQ(999999, r.Call(0u, 999999)); |
190 CHECK_EQ(999999, memory[0]); | 221 CHECK_EQ(999999, memory[0]); |
191 // TODO(titzer): offset 29-31 should also be OOB. | 222 // TODO(titzer): offset 29-31 should also be OOB. |
192 for (uint32_t offset = 32; offset < 40; offset++) { | 223 for (uint32_t offset = 32; offset < 40; offset++) { |
193 CHECK_EQ(8888, r.Call(offset, 8888)); | 224 CHECK_EQ(8888, r.Call(offset, 8888)); |
194 } | 225 } |
195 | 226 |
196 for (uint32_t offset = 0x10000000; offset < 0xF0000000; offset += 0x1000000) { | 227 for (uint32_t offset = 0x10000000; offset < 0xF0000000; offset += 0x1000000) { |
197 CHECK_EQ(7777, r.Call(offset, 7777)); | 228 CHECK_EQ(7777, r.Call(offset, 7777)); |
198 } | 229 } |
199 } | 230 } |
OLD | NEW |