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

Side by Side Diff: test/cctest/wasm/test-run-wasm-interpreter.cc

Issue 2055803002: [wasm] Fix CFI failures due to Wasm threads. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 6 months 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
OLDNEW
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/wasm/wasm-macro-gen.h" 9 #include "src/wasm/wasm-macro-gen.h"
10 10
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 SmartArrayPointer<int> offsets = 169 SmartArrayPointer<int> offsets =
170 Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal, 170 Find(code, sizeof(code), kNumBreakpoints, kExprGetLocal, kExprGetLocal,
171 kExprI32Add); 171 kExprI32Add);
172 172
173 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), 173 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
174 MachineType::Uint32()); 174 MachineType::Uint32());
175 175
176 r.Build(code, code + arraysize(code)); 176 r.Build(code, code + arraysize(code));
177 177
178 WasmInterpreter* interpreter = r.interpreter(); 178 WasmInterpreter* interpreter = r.interpreter();
179 WasmInterpreter::Thread& thread = interpreter->GetThread(0); 179 WasmInterpreter::Thread* thread = interpreter->GetThread(0);
180 for (int i = 0; i < kNumBreakpoints; i++) { 180 for (int i = 0; i < kNumBreakpoints; i++) {
181 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[i], 181 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[i],
182 true); 182 true);
183 } 183 }
184 184
185 FOR_UINT32_INPUTS(a) { 185 FOR_UINT32_INPUTS(a) {
186 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) { 186 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) {
187 thread.Reset(); 187 thread->Reset();
188 WasmVal args[] = {WasmVal(*a), WasmVal(b)}; 188 WasmVal args[] = {WasmVal(*a), WasmVal(b)};
189 thread.PushFrame(r.function(), args); 189 thread->PushFrame(r.function(), args);
190 190
191 for (int i = 0; i < kNumBreakpoints; i++) { 191 for (int i = 0; i < kNumBreakpoints; i++) {
192 thread.Run(); // run to next breakpoint 192 thread->Run(); // run to next breakpoint
193 // Check the thread stopped at the right pc. 193 // Check the thread stopped at the right pc.
194 CHECK_EQ(WasmInterpreter::PAUSED, thread.state()); 194 CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
195 CHECK_EQ(kLocalsDeclSize + offsets[i], thread.GetBreakpointPc()); 195 CHECK_EQ(kLocalsDeclSize + offsets[i], thread->GetBreakpointPc());
196 } 196 }
197 197
198 thread.Run(); // run to completion 198 thread->Run(); // run to completion
199 199
200 // Check the thread finished with the right value. 200 // Check the thread finished with the right value.
201 CHECK_EQ(WasmInterpreter::FINISHED, thread.state()); 201 CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
202 uint32_t expected = (*a) + (b); 202 uint32_t expected = (*a) + (b);
203 CHECK_EQ(expected, thread.GetReturnValue().to<uint32_t>()); 203 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
204 } 204 }
205 } 205 }
206 } 206 }
207 207
208 TEST(Step_I32Mul) { 208 TEST(Step_I32Mul) {
209 static const int kTraceLength = 4; 209 static const int kTraceLength = 4;
210 byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; 210 byte code[] = {WASM_I32_MUL(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
211 211
212 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), 212 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
213 MachineType::Uint32()); 213 MachineType::Uint32());
214 214
215 r.Build(code, code + arraysize(code)); 215 r.Build(code, code + arraysize(code));
216 216
217 WasmInterpreter* interpreter = r.interpreter(); 217 WasmInterpreter* interpreter = r.interpreter();
218 WasmInterpreter::Thread& thread = interpreter->GetThread(0); 218 WasmInterpreter::Thread* thread = interpreter->GetThread(0);
219 219
220 FOR_UINT32_INPUTS(a) { 220 FOR_UINT32_INPUTS(a) {
221 for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) { 221 for (uint32_t b = 33; b < 3000000000u; b += 1000000000u) {
222 thread.Reset(); 222 thread->Reset();
223 WasmVal args[] = {WasmVal(*a), WasmVal(b)}; 223 WasmVal args[] = {WasmVal(*a), WasmVal(b)};
224 thread.PushFrame(r.function(), args); 224 thread->PushFrame(r.function(), args);
225 225
226 // Run instructions one by one. 226 // Run instructions one by one.
227 for (int i = 0; i < kTraceLength - 1; i++) { 227 for (int i = 0; i < kTraceLength - 1; i++) {
228 thread.Step(); 228 thread->Step();
229 // Check the thread stopped. 229 // Check the thread stopped.
230 CHECK_EQ(WasmInterpreter::PAUSED, thread.state()); 230 CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
231 } 231 }
232 232
233 // Run last instruction. 233 // Run last instruction.
234 thread.Step(); 234 thread->Step();
235 235
236 // Check the thread finished with the right value. 236 // Check the thread finished with the right value.
237 CHECK_EQ(WasmInterpreter::FINISHED, thread.state()); 237 CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
238 uint32_t expected = (*a) * (b); 238 uint32_t expected = (*a) * (b);
239 CHECK_EQ(expected, thread.GetReturnValue().to<uint32_t>()); 239 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
240 } 240 }
241 } 241 }
242 } 242 }
243 243
244 TEST(Breakpoint_I32And_disable) { 244 TEST(Breakpoint_I32And_disable) {
245 static const int kLocalsDeclSize = 1; 245 static const int kLocalsDeclSize = 1;
246 static const int kNumBreakpoints = 1; 246 static const int kNumBreakpoints = 1;
247 byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))}; 247 byte code[] = {WASM_I32_AND(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))};
248 SmartArrayPointer<int> offsets = 248 SmartArrayPointer<int> offsets =
249 Find(code, sizeof(code), kNumBreakpoints, kExprI32And); 249 Find(code, sizeof(code), kNumBreakpoints, kExprI32And);
250 250
251 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(), 251 WasmRunner<int32_t> r(kExecuteInterpreted, MachineType::Uint32(),
252 MachineType::Uint32()); 252 MachineType::Uint32());
253 253
254 r.Build(code, code + arraysize(code)); 254 r.Build(code, code + arraysize(code));
255 255
256 WasmInterpreter* interpreter = r.interpreter(); 256 WasmInterpreter* interpreter = r.interpreter();
257 WasmInterpreter::Thread& thread = interpreter->GetThread(0); 257 WasmInterpreter::Thread* thread = interpreter->GetThread(0);
258 258
259 FOR_UINT32_INPUTS(a) { 259 FOR_UINT32_INPUTS(a) {
260 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) { 260 for (uint32_t b = 11; b < 3000000000u; b += 1000000000u) {
261 // Run with and without breakpoints. 261 // Run with and without breakpoints.
262 for (int do_break = 0; do_break < 2; do_break++) { 262 for (int do_break = 0; do_break < 2; do_break++) {
263 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[0], 263 interpreter->SetBreakpoint(r.function(), kLocalsDeclSize + offsets[0],
264 do_break); 264 do_break);
265 thread.Reset(); 265 thread->Reset();
266 WasmVal args[] = {WasmVal(*a), WasmVal(b)}; 266 WasmVal args[] = {WasmVal(*a), WasmVal(b)};
267 thread.PushFrame(r.function(), args); 267 thread->PushFrame(r.function(), args);
268 268
269 if (do_break) { 269 if (do_break) {
270 thread.Run(); // run to next breakpoint 270 thread->Run(); // run to next breakpoint
271 // Check the thread stopped at the right pc. 271 // Check the thread stopped at the right pc.
272 CHECK_EQ(WasmInterpreter::PAUSED, thread.state()); 272 CHECK_EQ(WasmInterpreter::PAUSED, thread->state());
273 CHECK_EQ(kLocalsDeclSize + offsets[0], thread.GetBreakpointPc()); 273 CHECK_EQ(kLocalsDeclSize + offsets[0], thread->GetBreakpointPc());
274 } 274 }
275 275
276 thread.Run(); // run to completion 276 thread->Run(); // run to completion
277 277
278 // Check the thread finished with the right value. 278 // Check the thread finished with the right value.
279 CHECK_EQ(WasmInterpreter::FINISHED, thread.state()); 279 CHECK_EQ(WasmInterpreter::FINISHED, thread->state());
280 uint32_t expected = (*a) & (b); 280 uint32_t expected = (*a) & (b);
281 CHECK_EQ(expected, thread.GetReturnValue().to<uint32_t>()); 281 CHECK_EQ(expected, thread->GetReturnValue().to<uint32_t>());
282 } 282 }
283 } 283 }
284 } 284 }
285 } 285 }
286 286
287 } // namespace wasm 287 } // namespace wasm
288 } // namespace internal 288 } // namespace internal
289 } // namespace v8 289 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698