Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 // The UNIT_TEST_CASE macro is used for tests that do not need any | 23 // The UNIT_TEST_CASE macro is used for tests that do not need any |
| 24 // default isolate or zone functionality. | 24 // default isolate or zone functionality. |
| 25 #define UNIT_TEST_CASE(name) \ | 25 #define UNIT_TEST_CASE(name) \ |
| 26 void Dart_Test##name(); \ | 26 void Dart_Test##name(); \ |
| 27 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ | 27 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ |
| 28 void Dart_Test##name() | 28 void Dart_Test##name() |
| 29 | 29 |
| 30 // The TEST_CASE macro is used for tests that need an isolate and zone | 30 // The TEST_CASE macro is used for tests that need an isolate and zone |
| 31 // in order to test its functionality. | 31 // in order to test its functionality. |
| 32 #define VM_TEST_CASE(name) \ | |
| 33 static void Dart_TestHelper##name(Thread* thread); \ | |
| 34 UNIT_TEST_CASE(name) \ | |
| 35 { \ | |
| 36 TestIsolateScope __test_isolate__; \ | |
| 37 Thread* __thread__ = Thread::Current(); \ | |
| 38 ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \ | |
| 39 TransitionNativeToVM transition(__thread__); \ | |
| 40 StackZone __zone__(__thread__); \ | |
| 41 HandleScope __hs__(__thread__); \ | |
| 42 Dart_TestHelper##name(__thread__); \ | |
| 43 } \ | |
| 44 static void Dart_TestHelper##name(Thread* thread) | |
| 45 | |
| 46 // The TEST_CASE macro is used for tests that need an isolate and zone | |
|
zra
2016/01/08 23:32:07
This is the same comments that's on VM_TEST_CASE.
siva
2016/01/12 21:26:22
Fixed the comments.
| |
| 47 // in order to test its functionality. | |
| 32 #define TEST_CASE(name) \ | 48 #define TEST_CASE(name) \ |
| 33 static void Dart_TestHelper##name(Thread* thread); \ | 49 static void Dart_TestHelper##name(Thread* thread); \ |
| 34 UNIT_TEST_CASE(name) \ | 50 UNIT_TEST_CASE(name) \ |
| 35 { \ | 51 { \ |
| 36 TestIsolateScope __test_isolate__; \ | 52 TestIsolateScope __test_isolate__; \ |
| 37 Thread* __thread__ = Thread::Current(); \ | 53 Thread* __thread__ = Thread::Current(); \ |
| 38 ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \ | 54 ASSERT(__thread__->isolate() == __test_isolate__.isolate()); \ |
| 39 StackZone __zone__(__thread__); \ | 55 StackZone __zone__(__thread__); \ |
| 40 HandleScope __hs__(__thread__); \ | 56 HandleScope __hs__(__thread__); \ |
| 41 Dart_TestHelper##name(__thread__); \ | 57 Dart_TestHelper##name(__thread__); \ |
| 42 } \ | 58 } \ |
| 43 static void Dart_TestHelper##name(Thread* thread) | 59 static void Dart_TestHelper##name(Thread* thread) |
| 44 | 60 |
| 45 // The ASSEMBLER_TEST_GENERATE macro is used to generate a unit test | 61 // The ASSEMBLER_TEST_GENERATE macro is used to generate a unit test |
| 46 // for the assembler. | 62 // for the assembler. |
| 47 #define ASSEMBLER_TEST_GENERATE(name, assembler) \ | 63 #define ASSEMBLER_TEST_GENERATE(name, assembler) \ |
| 48 void AssemblerTestGenerate##name(Assembler* assembler) | 64 void AssemblerTestGenerate##name(Assembler* assembler) |
| 49 | 65 |
| 50 // The ASSEMBLER_TEST_EXTERN macro is used to declare a unit test | 66 // The ASSEMBLER_TEST_EXTERN macro is used to declare a unit test |
| 51 // for the assembler. | 67 // for the assembler. |
| 52 #define ASSEMBLER_TEST_EXTERN(name) \ | 68 #define ASSEMBLER_TEST_EXTERN(name) \ |
| 53 extern void AssemblerTestGenerate##name(Assembler* assembler); | 69 extern void AssemblerTestGenerate##name(Assembler* assembler); |
| 54 | 70 |
| 55 // The ASSEMBLER_TEST_RUN macro is used to execute the assembler unit | 71 // The ASSEMBLER_TEST_RUN macro is used to execute the assembler unit |
| 56 // test generated using the ASSEMBLER_TEST_GENERATE macro. | 72 // test generated using the ASSEMBLER_TEST_GENERATE macro. |
| 57 // C++ callee-saved registers are not preserved. Arguments may be passed in. | 73 // C++ callee-saved registers are not preserved. Arguments may be passed in. |
| 58 #define ASSEMBLER_TEST_RUN(name, test) \ | 74 #define ASSEMBLER_TEST_RUN(name, test) \ |
| 59 static void AssemblerTestRun##name(AssemblerTest* test); \ | 75 static void AssemblerTestRun##name(AssemblerTest* test); \ |
| 60 TEST_CASE(name) { \ | 76 VM_TEST_CASE(name) { \ |
| 61 Assembler __assembler__; \ | 77 Assembler __assembler__; \ |
| 62 AssemblerTest test(""#name, &__assembler__); \ | 78 AssemblerTest test(""#name, &__assembler__); \ |
| 63 AssemblerTestGenerate##name(test.assembler()); \ | 79 AssemblerTestGenerate##name(test.assembler()); \ |
| 64 test.Assemble(); \ | 80 test.Assemble(); \ |
| 65 AssemblerTestRun##name(&test); \ | 81 AssemblerTestRun##name(&test); \ |
| 66 } \ | 82 } \ |
| 67 static void AssemblerTestRun##name(AssemblerTest* test) | 83 static void AssemblerTestRun##name(AssemblerTest* test) |
| 68 | 84 |
| 69 // Populate node list with AST nodes. | 85 // Populate node list with AST nodes. |
| 70 #define CODEGEN_TEST_GENERATE(name, test) \ | 86 #define CODEGEN_TEST_GENERATE(name, test) \ |
| 71 static void CodeGenTestGenerate##name(CodeGenTest* test) | 87 static void CodeGenTestGenerate##name(CodeGenTest* test) |
| 72 | 88 |
| 73 // Populate node list with AST nodes, possibly using the provided function | 89 // Populate node list with AST nodes, possibly using the provided function |
| 74 // object built by a previous CODEGEN_TEST_GENERATE. | 90 // object built by a previous CODEGEN_TEST_GENERATE. |
| 75 #define CODEGEN_TEST2_GENERATE(name, function, test) \ | 91 #define CODEGEN_TEST2_GENERATE(name, function, test) \ |
| 76 static void CodeGenTestGenerate##name(const Function& function, \ | 92 static void CodeGenTestGenerate##name(const Function& function, \ |
| 77 CodeGenTest* test) | 93 CodeGenTest* test) |
| 78 | 94 |
| 79 | 95 |
| 80 // Pass the name of test and the expected results as RawObject. | 96 // Pass the name of test and the expected results as RawObject. |
| 81 #define CODEGEN_TEST_RUN(name, expected) \ | 97 #define CODEGEN_TEST_RUN(name, expected) \ |
| 82 static void CodeGenTestRun##name(const Function& function); \ | 98 static void CodeGenTestRun##name(const Function& function); \ |
| 83 TEST_CASE(name) { \ | 99 VM_TEST_CASE(name) { \ |
| 84 CodeGenTest __test__(""#name); \ | 100 CodeGenTest __test__(""#name); \ |
| 85 CodeGenTestGenerate##name(&__test__); \ | 101 CodeGenTestGenerate##name(&__test__); \ |
| 86 __test__.Compile(); \ | 102 __test__.Compile(); \ |
| 87 CodeGenTestRun##name(__test__.function()); \ | 103 CodeGenTestRun##name(__test__.function()); \ |
| 88 } \ | 104 } \ |
| 89 static void CodeGenTestRun##name(const Function& function) { \ | 105 static void CodeGenTestRun##name(const Function& function) { \ |
| 90 Object& result = Object::Handle(); \ | 106 Object& result = Object::Handle(); \ |
| 91 result = DartEntry::InvokeFunction(function, Object::empty_array()); \ | 107 result = DartEntry::InvokeFunction(function, Object::empty_array()); \ |
| 92 EXPECT(!result.IsError()); \ | 108 EXPECT(!result.IsError()); \ |
| 93 Instance& actual = Instance::Handle(); \ | 109 Instance& actual = Instance::Handle(); \ |
| 94 actual ^= result.raw(); \ | 110 actual ^= result.raw(); \ |
| 95 EXPECT(actual.CanonicalizeEquals(Instance::Handle(expected))); \ | 111 EXPECT(actual.CanonicalizeEquals(Instance::Handle(expected))); \ |
| 96 } | 112 } |
| 97 | 113 |
| 98 | 114 |
| 99 // Pass the name of test, and use the generated function to call it | 115 // Pass the name of test, and use the generated function to call it |
| 100 // and evaluate its result. | 116 // and evaluate its result. |
| 101 #define CODEGEN_TEST_RAW_RUN(name, function) \ | 117 #define CODEGEN_TEST_RAW_RUN(name, function) \ |
| 102 static void CodeGenTestRun##name(const Function& function); \ | 118 static void CodeGenTestRun##name(const Function& function); \ |
| 103 TEST_CASE(name) { \ | 119 VM_TEST_CASE(name) { \ |
| 104 CodeGenTest __test__(""#name); \ | 120 CodeGenTest __test__(""#name); \ |
| 105 CodeGenTestGenerate##name(&__test__); \ | 121 CodeGenTestGenerate##name(&__test__); \ |
| 106 __test__.Compile(); \ | 122 __test__.Compile(); \ |
| 107 CodeGenTestRun##name(__test__.function()); \ | 123 CodeGenTestRun##name(__test__.function()); \ |
| 108 } \ | 124 } \ |
| 109 static void CodeGenTestRun##name(const Function& function) | 125 static void CodeGenTestRun##name(const Function& function) |
| 110 | 126 |
| 111 | 127 |
| 112 // Generate code for two sequences of AST nodes and execute the first one. | 128 // Generate code for two sequences of AST nodes and execute the first one. |
| 113 // The first one may reference the Function object generated by the second one. | 129 // The first one may reference the Function object generated by the second one. |
| 114 #define CODEGEN_TEST2_RUN(name1, name2, expected) \ | 130 #define CODEGEN_TEST2_RUN(name1, name2, expected) \ |
| 115 static void CodeGenTestRun##name1(const Function& function); \ | 131 static void CodeGenTestRun##name1(const Function& function); \ |
| 116 TEST_CASE(name1) { \ | 132 VM_TEST_CASE(name1) { \ |
| 117 /* Generate code for name2 */ \ | 133 /* Generate code for name2 */ \ |
| 118 CodeGenTest __test2__(""#name2); \ | 134 CodeGenTest __test2__(""#name2); \ |
| 119 CodeGenTestGenerate##name2(&__test2__); \ | 135 CodeGenTestGenerate##name2(&__test2__); \ |
| 120 __test2__.Compile(); \ | 136 __test2__.Compile(); \ |
| 121 /* Generate code for name1, providing function2 */ \ | 137 /* Generate code for name1, providing function2 */ \ |
| 122 CodeGenTest __test1__(""#name1); \ | 138 CodeGenTest __test1__(""#name1); \ |
| 123 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ | 139 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ |
| 124 __test1__.Compile(); \ | 140 __test1__.Compile(); \ |
| 125 CodeGenTestRun##name1(__test1__.function()); \ | 141 CodeGenTestRun##name1(__test1__.function()); \ |
| 126 } \ | 142 } \ |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 549 // Yields: | 565 // Yields: |
| 550 // | 566 // |
| 551 // out = "\"id\":\"\"" | 567 // out = "\"id\":\"\"" |
| 552 // | 568 // |
| 553 void ElideJSONSubstring(const char* prefix, const char* in, char* out); | 569 void ElideJSONSubstring(const char* prefix, const char* in, char* out); |
| 554 | 570 |
| 555 | 571 |
| 556 } // namespace dart | 572 } // namespace dart |
| 557 | 573 |
| 558 #endif // VM_UNIT_TEST_H_ | 574 #endif // VM_UNIT_TEST_H_ |
| OLD | NEW |