OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_UNIT_TEST_H_ | 5 #ifndef VM_UNIT_TEST_H_ |
6 #define VM_UNIT_TEST_H_ | 6 #define VM_UNIT_TEST_H_ |
7 | 7 |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 | 9 |
10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 } | 314 } |
315 Isolate* isolate() const { return isolate_; } | 315 Isolate* isolate() const { return isolate_; } |
316 | 316 |
317 private: | 317 private: |
318 Isolate* isolate_; | 318 Isolate* isolate_; |
319 | 319 |
320 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope); | 320 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope); |
321 }; | 321 }; |
322 | 322 |
323 | 323 |
324 template<typename T> struct is_void { | |
325 static const bool value = false; | |
326 }; | |
327 | |
328 | |
329 template<> struct is_void<void> { | |
330 static const bool value = true; | |
331 }; | |
332 | |
333 | |
334 template<typename T> struct is_double { | |
335 static const bool value = false; | |
336 }; | |
337 | |
338 | |
339 template<> struct is_double<double> { | |
340 static const bool value = true; | |
341 }; | |
342 | |
343 | |
324 class AssemblerTest { | 344 class AssemblerTest { |
325 public: | 345 public: |
326 AssemblerTest(const char* name, Assembler* assembler) | 346 AssemblerTest(const char* name, Assembler* assembler) |
327 : name_(name), | 347 : name_(name), |
328 assembler_(assembler), | 348 assembler_(assembler), |
329 code_(Code::ZoneHandle()) { | 349 code_(Code::ZoneHandle()) { |
330 ASSERT(name != NULL); | 350 ASSERT(name != NULL); |
331 ASSERT(assembler != NULL); | 351 ASSERT(assembler != NULL); |
332 } | 352 } |
333 ~AssemblerTest() { } | 353 ~AssemblerTest() { } |
334 | 354 |
335 Assembler* assembler() const { return assembler_; } | 355 Assembler* assembler() const { return assembler_; } |
336 | 356 |
337 const Code& code() const { return code_; } | 357 const Code& code() const { return code_; } |
338 | 358 |
339 uword entry() const { return entry_; } | 359 uword entry() const { return entry_; } |
360 #if defined(USING_SIMULATOR) | |
zra
2015/08/11 19:48:17
Please add comments here about how to use Invoke()
Florian Schneider
2015/08/12 07:30:53
If you happen to write a test that requires a new
zra
2015/08/17 16:35:43
Template errors from the compiler are hard to read
| |
361 template<typename ResultType> ResultType Invoke() { | |
362 const bool fp_return = is_double<ResultType>::value; | |
363 COMPILE_ASSERT(!fp_return); | |
364 const bool fp_args = false; | |
365 return static_cast<ResultType>(Simulator::Current()->Call( | |
366 bit_cast<intptr_t, uword>(entry()), 0, 0, 0, 0, fp_return, fp_args)); | |
367 } | |
368 template<typename ResultType, typename Arg1Type> | |
369 ResultType Invoke(Arg1Type arg1) { | |
370 const bool fp_return = is_double<ResultType>::value; | |
371 COMPILE_ASSERT(!fp_return); | |
372 const bool fp_args = false; | |
373 COMPILE_ASSERT(!is_double<Arg1Type>::value); | |
374 return static_cast<ResultType>(Simulator::Current()->Call( | |
375 bit_cast<intptr_t, uword>(entry()), | |
376 reinterpret_cast<intptr_t>(arg1), | |
377 0, 0, 0, fp_return, fp_args)); | |
378 } | |
379 template<typename ResultType, | |
380 typename Arg1Type, | |
381 typename Arg2Type, | |
382 typename Arg3Type> | |
383 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { | |
384 COMPILE_ASSERT(is_void<ResultType>::value); | |
385 const bool fp_return = false; | |
386 COMPILE_ASSERT(!is_double<Arg1Type>::value); | |
387 COMPILE_ASSERT(!is_double<Arg2Type>::value); | |
388 COMPILE_ASSERT(!is_double<Arg3Type>::value); | |
389 const bool fp_args = false; | |
390 return static_cast<ResultType>(Simulator::Current()->Call( | |
391 bit_cast<intptr_t, uword>(entry()), | |
392 reinterpret_cast<intptr_t>(arg1), | |
393 reinterpret_cast<intptr_t>(arg2), | |
394 reinterpret_cast<intptr_t>(arg3), | |
395 0, fp_return, fp_args)); | |
396 } | |
397 #else | |
398 template<typename ResultType> ResultType Invoke() { | |
399 typedef ResultType (*FunctionType) (); | |
400 return reinterpret_cast<FunctionType>(entry())(); | |
401 } | |
402 | |
403 template<typename ResultType, typename Arg1Type> | |
404 ResultType Invoke(Arg1Type arg1) { | |
405 typedef ResultType (*FunctionType) (Arg1Type); | |
406 return reinterpret_cast<FunctionType>(entry())(arg1); | |
407 } | |
408 | |
409 template<typename ResultType, | |
410 typename Arg1Type, | |
411 typename Arg2Type, | |
412 typename Arg3Type> | |
413 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) { | |
414 typedef ResultType (*FunctionType) (Arg1Type, Arg2Type, Arg3Type); | |
415 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3); | |
416 } | |
417 #endif | |
340 | 418 |
341 // Assemble test and set code_ and entry_. | 419 // Assemble test and set code_ and entry_. |
342 void Assemble(); | 420 void Assemble(); |
343 | 421 |
344 private: | 422 private: |
345 const char* name_; | 423 const char* name_; |
346 Assembler* assembler_; | 424 Assembler* assembler_; |
347 Code& code_; | 425 Code& code_; |
348 uword entry_; | 426 uword entry_; |
349 | 427 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 } \ | 502 } \ |
425 } else { \ | 503 } else { \ |
426 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \ | 504 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \ |
427 #handle); \ | 505 #handle); \ |
428 } \ | 506 } \ |
429 } while (0) | 507 } while (0) |
430 | 508 |
431 } // namespace dart | 509 } // namespace dart |
432 | 510 |
433 #endif // VM_UNIT_TEST_H_ | 511 #endif // VM_UNIT_TEST_H_ |
OLD | NEW |