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 RUNTIME_VM_UNIT_TEST_H_ | 5 #ifndef RUNTIME_VM_UNIT_TEST_H_ |
6 #define RUNTIME_VM_UNIT_TEST_H_ | 6 #define RUNTIME_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 10 matching lines...) Expand all Loading... |
21 #include "vm/simulator.h" | 21 #include "vm/simulator.h" |
22 #include "vm/zone.h" | 22 #include "vm/zone.h" |
23 | 23 |
24 // The UNIT_TEST_CASE macro is used for tests that do not need any | 24 // The UNIT_TEST_CASE macro is used for tests that do not need any |
25 // default isolate or zone functionality. | 25 // default isolate or zone functionality. |
26 #define UNIT_TEST_CASE(name) \ | 26 #define UNIT_TEST_CASE(name) \ |
27 void Dart_Test##name(); \ | 27 void Dart_Test##name(); \ |
28 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ | 28 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ |
29 void Dart_Test##name() | 29 void Dart_Test##name() |
30 | 30 |
| 31 // The RAW_UNIT_TEST_CASE macro is used for tests that do not require any of the |
| 32 // functionality provided by the VM. Tests declared using this macro will be run |
| 33 // before the VM is initialized. |
| 34 #define RAW_UNIT_TEST_CASE(name) \ |
| 35 void Dart_Test##name(); \ |
| 36 static const dart::RawTestCase kRegister##name(Dart_Test##name, #name); \ |
| 37 void Dart_Test##name() |
| 38 |
31 // The VM_TEST_CASE macro is used for tests that need an isolate and zone | 39 // The VM_TEST_CASE macro is used for tests that need an isolate and zone |
32 // in order to test its functionality. This macro is used for tests that | 40 // in order to test its functionality. This macro is used for tests that |
33 // are implemented using the VM code directly and do not use the Dart API | 41 // are implemented using the VM code directly and do not use the Dart API |
34 // for calling into the VM. The safepoint execution state of threads using | 42 // for calling into the VM. The safepoint execution state of threads using |
35 // this macro is transitioned from kThreadInNative to kThreadInVM. | 43 // this macro is transitioned from kThreadInNative to kThreadInVM. |
36 #define VM_TEST_CASE(name) \ | 44 #define VM_TEST_CASE(name) \ |
37 static void Dart_TestHelper##name(Thread* thread); \ | 45 static void Dart_TestHelper##name(Thread* thread); \ |
38 UNIT_TEST_CASE(name) { \ | 46 UNIT_TEST_CASE(name) { \ |
39 TestIsolateScope __test_isolate__; \ | 47 TestIsolateScope __test_isolate__; \ |
40 Thread* __thread__ = Thread::Current(); \ | 48 Thread* __thread__ = Thread::Current(); \ |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 public: | 262 public: |
255 explicit TestCaseBase(const char* name); | 263 explicit TestCaseBase(const char* name); |
256 virtual ~TestCaseBase() {} | 264 virtual ~TestCaseBase() {} |
257 | 265 |
258 const char* name() const { return name_; } | 266 const char* name() const { return name_; } |
259 | 267 |
260 virtual void Run() = 0; | 268 virtual void Run() = 0; |
261 void RunTest(); | 269 void RunTest(); |
262 | 270 |
263 static void RunAll(); | 271 static void RunAll(); |
| 272 static void RunAllRaw(); |
| 273 |
| 274 protected: |
| 275 bool raw_test_; |
264 | 276 |
265 private: | 277 private: |
266 static TestCaseBase* first_; | 278 static TestCaseBase* first_; |
267 static TestCaseBase* tail_; | 279 static TestCaseBase* tail_; |
268 | 280 |
269 TestCaseBase* next_; | 281 TestCaseBase* next_; |
270 const char* name_; | 282 const char* name_; |
271 | 283 |
272 DISALLOW_COPY_AND_ASSIGN(TestCaseBase); | 284 DISALLOW_COPY_AND_ASSIGN(TestCaseBase); |
273 }; | 285 }; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 static void AddTestLib(const char* url, const char* source); | 328 static void AddTestLib(const char* url, const char* source); |
317 static const char* GetTestLib(const char* url); | 329 static const char* GetTestLib(const char* url); |
318 | 330 |
319 private: | 331 private: |
320 static Dart_Isolate CreateIsolate(const uint8_t* buffer, const char* name); | 332 static Dart_Isolate CreateIsolate(const uint8_t* buffer, const char* name); |
321 | 333 |
322 RunEntry* const run_; | 334 RunEntry* const run_; |
323 }; | 335 }; |
324 | 336 |
325 | 337 |
| 338 class RawTestCase : TestCaseBase { |
| 339 public: |
| 340 typedef void(RunEntry)(); |
| 341 |
| 342 RawTestCase(RunEntry* run, const char* name) : TestCaseBase(name), run_(run) { |
| 343 raw_test_ = true; |
| 344 } |
| 345 virtual void Run(); |
| 346 |
| 347 private: |
| 348 RunEntry* const run_; |
| 349 }; |
| 350 |
| 351 |
326 class TestIsolateScope { | 352 class TestIsolateScope { |
327 public: | 353 public: |
328 TestIsolateScope() { | 354 TestIsolateScope() { |
329 isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate()); | 355 isolate_ = reinterpret_cast<Isolate*>(TestCase::CreateTestIsolate()); |
330 Dart_EnterScope(); // Create a Dart API scope for unit tests. | 356 Dart_EnterScope(); // Create a Dart API scope for unit tests. |
331 } | 357 } |
332 ~TestIsolateScope() { | 358 ~TestIsolateScope() { |
333 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. | 359 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. |
334 ASSERT(isolate_ == Isolate::Current()); | 360 ASSERT(isolate_ == Isolate::Current()); |
335 Dart_ShutdownIsolate(); | 361 Dart_ShutdownIsolate(); |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 ~SetFlagScope() { *flag_ = original_value_; } | 640 ~SetFlagScope() { *flag_ = original_value_; } |
615 | 641 |
616 private: | 642 private: |
617 T* flag_; | 643 T* flag_; |
618 T original_value_; | 644 T original_value_; |
619 }; | 645 }; |
620 | 646 |
621 } // namespace dart | 647 } // namespace dart |
622 | 648 |
623 #endif // RUNTIME_VM_UNIT_TEST_H_ | 649 #endif // RUNTIME_VM_UNIT_TEST_H_ |
OLD | NEW |