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_api.h" | 8 #include "include/dart_api.h" |
9 | 9 |
10 #include "vm/ast.h" | 10 #include "vm/ast.h" |
11 #include "vm/dart.h" | 11 #include "vm/dart.h" |
12 #include "vm/globals.h" | 12 #include "vm/globals.h" |
13 #include "vm/heap.h" | 13 #include "vm/heap.h" |
14 #include "vm/isolate.h" | 14 #include "vm/isolate.h" |
15 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
16 #include "vm/object.h" | 16 #include "vm/object.h" |
17 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
| 18 #include "vm/simulator.h" |
18 #include "vm/zone.h" | 19 #include "vm/zone.h" |
19 | 20 |
20 // The UNIT_TEST_CASE macro is used for tests that do not need any | 21 // The UNIT_TEST_CASE macro is used for tests that do not need any |
21 // default isolate or zone functionality. | 22 // default isolate or zone functionality. |
22 #define UNIT_TEST_CASE(name) \ | 23 #define UNIT_TEST_CASE(name) \ |
23 void Dart_Test##name(); \ | 24 void Dart_Test##name(); \ |
24 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ | 25 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ |
25 void Dart_Test##name() | 26 void Dart_Test##name() |
26 | 27 |
27 // The TEST_CASE macro is used for tests that need an isolate and zone | 28 // The TEST_CASE macro is used for tests that need an isolate and zone |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 static void CodeGenTestRun##name1(const Function& function) { \ | 122 static void CodeGenTestRun##name1(const Function& function) { \ |
122 Object& result = Object::Handle(); \ | 123 Object& result = Object::Handle(); \ |
123 result = DartEntry::InvokeStatic(function, Object::empty_array()); \ | 124 result = DartEntry::InvokeStatic(function, Object::empty_array()); \ |
124 EXPECT(!result.IsError()); \ | 125 EXPECT(!result.IsError()); \ |
125 Instance& actual = Instance::Handle(); \ | 126 Instance& actual = Instance::Handle(); \ |
126 actual ^= result.raw(); \ | 127 actual ^= result.raw(); \ |
127 EXPECT(actual.Equals(Instance::Handle(expected))); \ | 128 EXPECT(actual.Equals(Instance::Handle(expected))); \ |
128 } | 129 } |
129 | 130 |
130 | 131 |
| 132 #if defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) |
| 133 #if defined(HOST_ARCH_ARM) || defined(HOST_ARCH_MIPS) |
| 134 // Running on actual ARM or MIPS hardware, execute code natively. |
| 135 #define EXECUTE_TEST_CODE_INT32(name, entry) reinterpret_cast<name>(entry)() |
| 136 #define EXECUTE_TEST_CODE_INT64_LL(name, entry, long_arg0, long_arg1) \ |
| 137 reinterpret_cast<name>(entry)(long_arg0, long_arg1) |
| 138 #define EXECUTE_TEST_CODE_FLOAT(name, entry) reinterpret_cast<name>(entry)() |
| 139 #define EXECUTE_TEST_CODE_DOUBLE(name, entry) reinterpret_cast<name>(entry)() |
| 140 #define EXECUTE_TEST_CODE_INT32_F(name, entry, float_arg) \ |
| 141 reinterpret_cast<name>(entry)(float_arg) |
| 142 #define EXECUTE_TEST_CODE_INT32_D(name, entry, double_arg) \ |
| 143 reinterpret_cast<name>(entry)(double_arg) |
| 144 #else |
| 145 // Not running on ARM or MIPS hardware, call simulator to execute code. |
| 146 #define EXECUTE_TEST_CODE_INT32(name, entry) \ |
| 147 static_cast<int32_t>(Simulator::Current()->Call((int32_t)entry, \ |
| 148 0, 0, 0, 0, 0)) |
| 149 #define EXECUTE_TEST_CODE_INT64_LL(name, entry, long_arg0, long_arg1) \ |
| 150 static_cast<int64_t>(Simulator::Current()->Call((int32_t)entry, \ |
| 151 Utils::Low32Bits(long_arg0), \ |
| 152 Utils::High32Bits(long_arg0), \ |
| 153 Utils::Low32Bits(long_arg1), \ |
| 154 Utils::High32Bits(long_arg1), \ |
| 155 0)) |
| 156 #define EXECUTE_TEST_CODE_FLOAT(name, entry) \ |
| 157 bit_cast<float, int32_t>(Simulator::Current()->Call((int32_t)entry, \ |
| 158 0, 0, 0, 0, 0)) |
| 159 #define EXECUTE_TEST_CODE_DOUBLE(name, entry) \ |
| 160 bit_cast<double, int64_t>(Simulator::Current()->Call((int32_t)entry, \ |
| 161 0, 0, 0, 0, 0)) |
| 162 #define EXECUTE_TEST_CODE_INT32_F(name, entry, float_arg) \ |
| 163 static_cast<int32_t>(Simulator::Current()->Call((int32_t)entry, \ |
| 164 bit_cast<int32_t, float>(float_arg), \ |
| 165 0, 0, 0, 0)) |
| 166 #define EXECUTE_TEST_CODE_INT32_D(name, entry, double_arg) \ |
| 167 static_cast<int32_t>(Simulator::Current()->Call((int32_t)entry, \ |
| 168 Utils::Low32Bits(bit_cast<int64_t, double>(double_arg)), \ |
| 169 Utils::High32Bits(bit_cast<int64_t, double>(double_arg)), \ |
| 170 0, 0, 0)) |
| 171 #endif // defined(HOST_ARCH_ARM) || defined(HOST_ARCH_MIPS) |
| 172 #endif // defined(TARGET_ARCH_ARM) || defined(TARGET_ARCH_MIPS) |
| 173 |
| 174 |
131 inline Dart_Handle NewString(const char* str) { | 175 inline Dart_Handle NewString(const char* str) { |
132 return Dart_NewStringFromCString(str); | 176 return Dart_NewStringFromCString(str); |
133 } | 177 } |
134 | 178 |
135 | 179 |
136 namespace dart { | 180 namespace dart { |
137 | 181 |
138 // Forward declarations. | 182 // Forward declarations. |
139 class Assembler; | 183 class Assembler; |
140 class CodeGenerator; | 184 class CodeGenerator; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 } else { \ | 349 } else { \ |
306 dart::Expect(__FILE__, __LINE__).Fail( \ | 350 dart::Expect(__FILE__, __LINE__).Fail( \ |
307 "expected '%s' to be an error handle but found a valid handle.\n", \ | 351 "expected '%s' to be an error handle but found a valid handle.\n", \ |
308 #handle); \ | 352 #handle); \ |
309 } \ | 353 } \ |
310 } while (0) | 354 } while (0) |
311 | 355 |
312 } // namespace dart | 356 } // namespace dart |
313 | 357 |
314 #endif // VM_UNIT_TEST_H_ | 358 #endif // VM_UNIT_TEST_H_ |
OLD | NEW |