| 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/dart_api_impl.h" | |
| 13 #include "vm/globals.h" | 12 #include "vm/globals.h" |
| 14 #include "vm/heap.h" | 13 #include "vm/heap.h" |
| 15 #include "vm/isolate.h" | 14 #include "vm/isolate.h" |
| 16 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
| 17 #include "vm/object.h" | 16 #include "vm/object.h" |
| 18 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
| 19 #include "vm/simulator.h" | 18 #include "vm/simulator.h" |
| 20 #include "vm/zone.h" | 19 #include "vm/zone.h" |
| 21 | 20 |
| 22 // 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 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 48 // for the assembler. | 47 // for the assembler. |
| 49 #define ASSEMBLER_TEST_EXTERN(name) \ | 48 #define ASSEMBLER_TEST_EXTERN(name) \ |
| 50 extern void AssemblerTestGenerate##name(Assembler* assembler); | 49 extern void AssemblerTestGenerate##name(Assembler* assembler); |
| 51 | 50 |
| 52 // The ASSEMBLER_TEST_RUN macro is used to execute the assembler unit | 51 // The ASSEMBLER_TEST_RUN macro is used to execute the assembler unit |
| 53 // test generated using the ASSEMBLER_TEST_GENERATE macro. | 52 // test generated using the ASSEMBLER_TEST_GENERATE macro. |
| 54 // C++ callee-saved registers are not preserved. Arguments may be passed in. | 53 // C++ callee-saved registers are not preserved. Arguments may be passed in. |
| 55 #define ASSEMBLER_TEST_RUN(name, test) \ | 54 #define ASSEMBLER_TEST_RUN(name, test) \ |
| 56 static void AssemblerTestRun##name(AssemblerTest* test); \ | 55 static void AssemblerTestRun##name(AssemblerTest* test); \ |
| 57 TEST_CASE(name) { \ | 56 TEST_CASE(name) { \ |
| 58 NativeToVmTimerScope timer(Isolate::Current()); \ | |
| 59 Assembler __assembler__; \ | 57 Assembler __assembler__; \ |
| 60 AssemblerTest test(""#name, &__assembler__); \ | 58 AssemblerTest test(""#name, &__assembler__); \ |
| 61 AssemblerTestGenerate##name(test.assembler()); \ | 59 AssemblerTestGenerate##name(test.assembler()); \ |
| 62 test.Assemble(); \ | 60 test.Assemble(); \ |
| 63 AssemblerTestRun##name(&test); \ | 61 AssemblerTestRun##name(&test); \ |
| 64 } \ | 62 } \ |
| 65 static void AssemblerTestRun##name(AssemblerTest* test) | 63 static void AssemblerTestRun##name(AssemblerTest* test) |
| 66 | 64 |
| 67 // Populate node list with AST nodes. | 65 // Populate node list with AST nodes. |
| 68 #define CODEGEN_TEST_GENERATE(name, test) \ | 66 #define CODEGEN_TEST_GENERATE(name, test) \ |
| 69 static void CodeGenTestGenerate##name(CodeGenTest* test) | 67 static void CodeGenTestGenerate##name(CodeGenTest* test) |
| 70 | 68 |
| 71 // Populate node list with AST nodes, possibly using the provided function | 69 // Populate node list with AST nodes, possibly using the provided function |
| 72 // object built by a previous CODEGEN_TEST_GENERATE. | 70 // object built by a previous CODEGEN_TEST_GENERATE. |
| 73 #define CODEGEN_TEST2_GENERATE(name, function, test) \ | 71 #define CODEGEN_TEST2_GENERATE(name, function, test) \ |
| 74 static void CodeGenTestGenerate##name(const Function& function, \ | 72 static void CodeGenTestGenerate##name(const Function& function, \ |
| 75 CodeGenTest* test) | 73 CodeGenTest* test) |
| 76 | 74 |
| 77 | 75 |
| 78 // Pass the name of test and the expected results as RawObject. | 76 // Pass the name of test and the expected results as RawObject. |
| 79 #define CODEGEN_TEST_RUN(name, expected) \ | 77 #define CODEGEN_TEST_RUN(name, expected) \ |
| 80 static void CodeGenTestRun##name(const Function& function); \ | 78 static void CodeGenTestRun##name(const Function& function); \ |
| 81 TEST_CASE(name) { \ | 79 TEST_CASE(name) { \ |
| 82 NativeToVmTimerScope timer(Isolate::Current()); \ | |
| 83 CodeGenTest __test__(""#name); \ | 80 CodeGenTest __test__(""#name); \ |
| 84 CodeGenTestGenerate##name(&__test__); \ | 81 CodeGenTestGenerate##name(&__test__); \ |
| 85 __test__.Compile(); \ | 82 __test__.Compile(); \ |
| 86 CodeGenTestRun##name(__test__.function()); \ | 83 CodeGenTestRun##name(__test__.function()); \ |
| 87 } \ | 84 } \ |
| 88 static void CodeGenTestRun##name(const Function& function) { \ | 85 static void CodeGenTestRun##name(const Function& function) { \ |
| 89 Object& result = Object::Handle(); \ | 86 Object& result = Object::Handle(); \ |
| 90 result = DartEntry::InvokeFunction(function, Object::empty_array()); \ | 87 result = DartEntry::InvokeFunction(function, Object::empty_array()); \ |
| 91 EXPECT(!result.IsError()); \ | 88 EXPECT(!result.IsError()); \ |
| 92 Instance& actual = Instance::Handle(); \ | 89 Instance& actual = Instance::Handle(); \ |
| 93 actual ^= result.raw(); \ | 90 actual ^= result.raw(); \ |
| 94 EXPECT(actual.Equals(Instance::Handle(expected))); \ | 91 EXPECT(actual.Equals(Instance::Handle(expected))); \ |
| 95 } | 92 } |
| 96 | 93 |
| 97 | 94 |
| 98 // Pass the name of test, and use the generated function to call it | 95 // Pass the name of test, and use the generated function to call it |
| 99 // and evaluate its result. | 96 // and evaluate its result. |
| 100 #define CODEGEN_TEST_RAW_RUN(name, function) \ | 97 #define CODEGEN_TEST_RAW_RUN(name, function) \ |
| 101 static void CodeGenTestRun##name(const Function& function); \ | 98 static void CodeGenTestRun##name(const Function& function); \ |
| 102 TEST_CASE(name) { \ | 99 TEST_CASE(name) { \ |
| 103 NativeToVmTimerScope timer(Isolate::Current()); \ | |
| 104 CodeGenTest __test__(""#name); \ | 100 CodeGenTest __test__(""#name); \ |
| 105 CodeGenTestGenerate##name(&__test__); \ | 101 CodeGenTestGenerate##name(&__test__); \ |
| 106 __test__.Compile(); \ | 102 __test__.Compile(); \ |
| 107 CodeGenTestRun##name(__test__.function()); \ | 103 CodeGenTestRun##name(__test__.function()); \ |
| 108 } \ | 104 } \ |
| 109 static void CodeGenTestRun##name(const Function& function) | 105 static void CodeGenTestRun##name(const Function& function) |
| 110 | 106 |
| 111 | 107 |
| 112 // Generate code for two sequences of AST nodes and execute the first one. | 108 // 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. | 109 // The first one may reference the Function object generated by the second one. |
| 114 #define CODEGEN_TEST2_RUN(name1, name2, expected) \ | 110 #define CODEGEN_TEST2_RUN(name1, name2, expected) \ |
| 115 static void CodeGenTestRun##name1(const Function& function); \ | 111 static void CodeGenTestRun##name1(const Function& function); \ |
| 116 TEST_CASE(name1) { \ | 112 TEST_CASE(name1) { \ |
| 117 NativeToVmTimerScope timer(Isolate::Current()); \ | |
| 118 /* Generate code for name2 */ \ | 113 /* Generate code for name2 */ \ |
| 119 CodeGenTest __test2__(""#name2); \ | 114 CodeGenTest __test2__(""#name2); \ |
| 120 CodeGenTestGenerate##name2(&__test2__); \ | 115 CodeGenTestGenerate##name2(&__test2__); \ |
| 121 __test2__.Compile(); \ | 116 __test2__.Compile(); \ |
| 122 /* Generate code for name1, providing function2 */ \ | 117 /* Generate code for name1, providing function2 */ \ |
| 123 CodeGenTest __test1__(""#name1); \ | 118 CodeGenTest __test1__(""#name1); \ |
| 124 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ | 119 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ |
| 125 __test1__.Compile(); \ | 120 __test1__.Compile(); \ |
| 126 CodeGenTestRun##name1(__test1__.function()); \ | 121 CodeGenTestRun##name1(__test1__.function()); \ |
| 127 } \ | 122 } \ |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 } \ | 382 } \ |
| 388 } else { \ | 383 } else { \ |
| 389 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \ | 384 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \ |
| 390 #handle); \ | 385 #handle); \ |
| 391 } \ | 386 } \ |
| 392 } while (0) | 387 } while (0) |
| 393 | 388 |
| 394 } // namespace dart | 389 } // namespace dart |
| 395 | 390 |
| 396 #endif // VM_UNIT_TEST_H_ | 391 #endif // VM_UNIT_TEST_H_ |
| OLD | NEW |