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