OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "bin/dartutils.h" | 7 #include "bin/dartutils.h" |
8 #include "bin/file.h" | 8 #include "bin/file.h" |
9 #include "bin/loader.h" | |
9 #include "bin/platform.h" | 10 #include "bin/platform.h" |
11 #include "bin/snapshot_utils.h" | |
10 #include "platform/assert.h" | 12 #include "platform/assert.h" |
11 #include "vm/benchmark_test.h" | 13 #include "vm/benchmark_test.h" |
12 #include "vm/dart.h" | 14 #include "vm/dart.h" |
13 #include "vm/unit_test.h" | 15 #include "vm/unit_test.h" |
14 | 16 |
15 | 17 |
16 // TODO(iposva, asiva): This is a placeholder for the real unittest framework. | 18 // TODO(iposva, asiva): This is a placeholder for the real unittest framework. |
17 namespace dart { | 19 namespace dart { |
18 | 20 |
19 // Defined in vm/os_thread_win.cc | 21 // Defined in vm/os_thread_win.cc |
20 extern bool private_flag_windows_run_tls_destructors; | 22 extern bool private_flag_windows_run_tls_destructors; |
21 | 23 |
22 // vm_snapshot_data_buffer points to a snapshot for the vm isolate if we | 24 // vm_snapshot_data_buffer points to a snapshot for the vm isolate if we |
23 // link in a snapshot otherwise it is initialized to NULL. | 25 // link in a snapshot otherwise it is initialized to NULL. |
24 extern const uint8_t* bin::vm_snapshot_data; | 26 extern const uint8_t* bin::vm_snapshot_data; |
25 extern const uint8_t* bin::vm_snapshot_instructions; | 27 extern const uint8_t* bin::vm_snapshot_instructions; |
26 | 28 |
27 // Only run tests that match the filter string. The default does not match any | 29 // Only run tests that match the filter string. The default does not match any |
28 // tests. | 30 // tests. |
29 static const char* const kNone = "No Test or Benchmarks"; | 31 static const char* const kNone = "No Test or Benchmarks"; |
30 static const char* const kList = "List all Tests and Benchmarks"; | 32 static const char* const kList = "List all Tests and Benchmarks"; |
31 static const char* const kAllBenchmarks = "All Benchmarks"; | 33 static const char* const kAllBenchmarks = "All Benchmarks"; |
32 static const char* run_filter = kNone; | 34 static const char* run_filter = kNone; |
35 static const char* kernel_snapshot = NULL; | |
33 | 36 |
34 static int run_matches = 0; | 37 static int run_matches = 0; |
35 | 38 |
36 | 39 |
37 void TestCase::Run() { | 40 void TestCase::Run() { |
38 OS::Print("Running test: %s\n", name()); | 41 OS::Print("Running test: %s\n", name()); |
39 (*run_)(); | 42 (*run_)(); |
40 OS::Print("Done: %s\n", name()); | 43 OS::Print("Done: %s\n", name()); |
41 } | 44 } |
42 | 45 |
(...skipping 25 matching lines...) Expand all Loading... | |
68 run_matches++; | 71 run_matches++; |
69 } else if (run_filter == kList) { | 72 } else if (run_filter == kList) { |
70 OS::Print("%s\n", this->name()); | 73 OS::Print("%s\n", this->name()); |
71 run_matches++; | 74 run_matches++; |
72 } | 75 } |
73 } | 76 } |
74 | 77 |
75 | 78 |
76 static void PrintUsage() { | 79 static void PrintUsage() { |
77 OS::PrintErr( | 80 OS::PrintErr( |
78 "run_vm_tests [--list | --benchmarks | " | 81 "Usage: one of the following\n" |
79 "<test name> | <benchmark name>]\n"); | 82 " run_vm_tests --list\n" |
80 OS::PrintErr("run_vm_tests [vm-flags ...] <test name>\n"); | 83 " run_vm_tests [--dfe=<snapshot file name>] --benchmarks\n" |
81 OS::PrintErr("run_vm_tests [vm-flags ...] <benchmark name>\n"); | 84 " run_vm_tests [--dfe=<snapshot file name>] [vm-flags ...] <test name>\n" |
85 " run_vm_tests [--dfe=<snapshot file name>] [vm-flags ...] <benchmark " | |
86 "name>\n"); | |
82 } | 87 } |
83 | 88 |
89 #define CHECK_RESULT(result) \ | |
90 if (Dart_IsError(result)) { \ | |
91 *error = strdup(Dart_GetError(result)); \ | |
92 Dart_ExitScope(); \ | |
93 Dart_ShutdownIsolate(); \ | |
94 return NULL; \ | |
95 } | |
96 | |
97 | |
98 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | |
99 const char* main, | |
100 const char* package_root, | |
101 const char* packages_config, | |
102 Dart_IsolateFlags* flags, | |
103 void* data, | |
104 char** error) { | |
105 ASSERT(script_uri != NULL); | |
106 const bool is_service_isolate = | |
107 strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0; | |
108 if (is_service_isolate) { | |
109 // We don't need service isolate for VM tests. | |
110 return NULL; | |
111 } | |
112 const bool is_kernel_isolate = | |
113 strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0; | |
114 const uint8_t* isolate_snapshot_data = bin::core_isolate_snapshot_data; | |
115 const uint8_t* isolate_snapshot_instructions = | |
116 bin::core_isolate_snapshot_instructions; | |
117 if (is_kernel_isolate) { | |
118 if (kernel_snapshot == NULL) { | |
119 *error = strdup( | |
120 "Kernel snapshot location has to be specified via --dfe option"); | |
121 return NULL; | |
122 } | |
123 script_uri = kernel_snapshot; | |
124 bin::AppSnapshot* app_snapshot = | |
125 bin::Snapshot::TryReadAppSnapshot(script_uri); | |
126 if (app_snapshot == NULL) { | |
127 *error = strdup("Failed to read kernel service app snapshot"); | |
128 return NULL; | |
129 } | |
130 const uint8_t* ignore_vm_snapshot_data; | |
131 const uint8_t* ignore_vm_snapshot_instructions; | |
132 app_snapshot->SetBuffers( | |
133 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | |
134 &isolate_snapshot_data, &isolate_snapshot_instructions); | |
135 } | |
136 | |
137 bin::IsolateData* isolate_data = new bin::IsolateData( | |
138 script_uri, package_root, packages_config, NULL /* app_snapshot */); | |
139 Dart_Isolate isolate = Dart_CreateIsolate( | |
140 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, | |
141 flags, isolate_data, error); | |
142 if (isolate == NULL) { | |
143 *error = strdup("Failed to create isolate"); | |
144 delete isolate_data; | |
145 return NULL; | |
146 } | |
147 | |
148 Dart_EnterScope(); | |
149 | |
150 bin::DartUtils::SetOriginalWorkingDirectory(); | |
151 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading( | |
152 false /* is_service_isolate */, false /* trace_loading */); | |
153 CHECK_RESULT(result); | |
154 | |
155 Dart_ExitScope(); | |
156 Dart_ExitIsolate(); | |
157 bool retval = Dart_IsolateMakeRunnable(isolate); | |
158 if (!retval) { | |
159 *error = strdup("Invalid isolate state - Unable to make it runnable"); | |
160 Dart_EnterIsolate(isolate); | |
161 Dart_ShutdownIsolate(); | |
162 return NULL; | |
163 } | |
siva
2017/05/18 00:02:38
I wonder if all this code be just under if (is_ker
aam
2017/05/18 01:03:00
Done, I think that is fair assumption at this poin
| |
164 | |
165 return isolate; | |
166 } | |
84 | 167 |
85 static int Main(int argc, const char** argv) { | 168 static int Main(int argc, const char** argv) { |
86 // Flags being passed to the Dart VM. | 169 // Flags being passed to the Dart VM. |
87 int dart_argc = 0; | 170 int dart_argc = 0; |
88 const char** dart_argv = NULL; | 171 const char** dart_argv = NULL; |
89 | 172 |
90 // Perform platform specific initialization. | 173 // Perform platform specific initialization. |
91 if (!dart::bin::Platform::Initialize()) { | 174 if (!dart::bin::Platform::Initialize()) { |
92 OS::PrintErr("Initialization failed\n"); | 175 OS::PrintErr("Initialization failed\n"); |
93 } | 176 } |
94 | 177 |
95 if (argc < 2) { | 178 if (argc < 2) { |
96 // Bad parameter count. | 179 // Bad parameter count. |
97 PrintUsage(); | 180 PrintUsage(); |
98 return 1; | 181 return 1; |
99 } else if (argc == 2) { | 182 } |
100 if (strcmp(argv[1], "--list") == 0) { | 183 |
101 run_filter = kList; | 184 if (argc == 2 && strcmp(argv[1], "--list") == 0) { |
102 // List all tests and benchmarks and exit without initializing the VM. | 185 run_filter = kList; |
103 TestCaseBase::RunAll(); | 186 // List all tests and benchmarks and exit without initializing the VM. |
104 Benchmark::RunAll(argv[0]); | 187 TestCaseBase::RunAll(); |
105 TestCaseBase::RunAllRaw(); | 188 Benchmark::RunAll(argv[0]); |
106 fflush(stdout); | 189 TestCaseBase::RunAllRaw(); |
107 return 0; | 190 fflush(stdout); |
108 } else if (strcmp(argv[1], "--benchmarks") == 0) { | 191 return 0; |
109 run_filter = kAllBenchmarks; | 192 } |
110 } else { | 193 |
111 run_filter = argv[1]; | 194 int arg_pos = 1; |
195 if (strstr(argv[arg_pos], "--dfe") == argv[arg_pos]) { | |
196 const char* delim = strstr(argv[1], "="); | |
197 if (delim == NULL || strlen(delim + 1) == 0) { | |
198 OS::PrintErr("Invalid value for the option: %s\n", argv[1]); | |
199 PrintUsage(); | |
200 return 1; | |
112 } | 201 } |
202 kernel_snapshot = strdup(delim + 1); | |
203 ++arg_pos; | |
siva
2017/05/18 00:02:38
can we automatically add the --use-dart-frontend o
aam
2017/05/18 01:03:00
Sure, good idea. Done.
| |
204 } | |
205 | |
206 if (arg_pos == argc - 1 && strcmp(argv[arg_pos], "--benchmarks") == 0) { | |
207 // "--benchmarks" is the last argument. | |
208 run_filter = kAllBenchmarks; | |
113 } else { | 209 } else { |
114 // Last argument is the test name, the rest are vm flags. | 210 // Last argument is the test name, the rest are vm flags. |
115 run_filter = argv[argc - 1]; | 211 run_filter = argv[argc - 1]; |
116 // Remove the first value (executable) from the arguments and | 212 // Remove the first value (executable) from the arguments and |
117 // exclude the last argument which is the test name. | 213 // exclude the last argument which is the test name. |
118 dart_argc = argc - 2; | 214 dart_argc = argc - arg_pos; |
119 dart_argv = &argv[1]; | 215 dart_argv = &argv[arg_pos]; |
120 } | 216 } |
121 bool set_vm_flags_success = | 217 bool set_vm_flags_success = |
122 Flags::ProcessCommandLineFlags(dart_argc, dart_argv); | 218 Flags::ProcessCommandLineFlags(dart_argc, dart_argv); |
123 ASSERT(set_vm_flags_success); | 219 ASSERT(set_vm_flags_success); |
124 const char* err_msg = Dart::InitOnce( | 220 const char* err_msg = Dart::InitOnce( |
125 dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, NULL, | 221 dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, |
126 NULL, NULL, NULL, dart::bin::DartUtils::OpenFile, | 222 CreateIsolateAndSetup /* create */, NULL /* shutdown */, |
127 dart::bin::DartUtils::ReadFile, dart::bin::DartUtils::WriteFile, | 223 NULL /* cleanup */, NULL /* thread_exit */, |
128 dart::bin::DartUtils::CloseFile, NULL, NULL); | 224 dart::bin::DartUtils::OpenFile, dart::bin::DartUtils::ReadFile, |
225 dart::bin::DartUtils::WriteFile, dart::bin::DartUtils::CloseFile, | |
226 NULL /* entropy_source */, NULL /* get_service_assets */); | |
227 | |
129 ASSERT(err_msg == NULL); | 228 ASSERT(err_msg == NULL); |
130 // Apply the filter to all registered tests. | 229 // Apply the filter to all registered tests. |
131 TestCaseBase::RunAll(); | 230 TestCaseBase::RunAll(); |
132 // Apply the filter to all registered benchmarks. | 231 // Apply the filter to all registered benchmarks. |
133 Benchmark::RunAll(argv[0]); | 232 Benchmark::RunAll(argv[0]); |
134 | 233 |
135 err_msg = Dart::Cleanup(); | 234 err_msg = Dart::Cleanup(); |
136 ASSERT(err_msg == NULL); | 235 ASSERT(err_msg == NULL); |
137 | 236 |
138 TestCaseBase::RunAllRaw(); | 237 TestCaseBase::RunAllRaw(); |
139 // Print a warning message if no tests or benchmarks were matched. | 238 // Print a warning message if no tests or benchmarks were matched. |
140 if (run_matches == 0) { | 239 if (run_matches == 0) { |
141 OS::PrintErr("No tests matched: %s\n", run_filter); | 240 OS::PrintErr("No tests matched: %s\n", run_filter); |
142 return 1; | 241 return 1; |
143 } | 242 } |
144 if (DynamicAssertionHelper::failed()) { | 243 if (DynamicAssertionHelper::failed()) { |
145 return 255; | 244 return 255; |
146 } | 245 } |
147 return 0; | 246 return 0; |
148 } | 247 } |
149 | 248 |
150 } // namespace dart | 249 } // namespace dart |
151 | 250 |
152 | 251 |
153 int main(int argc, const char** argv) { | 252 int main(int argc, const char** argv) { |
154 dart::bin::Platform::Exit(dart::Main(argc, argv)); | 253 dart::bin::Platform::Exit(dart::Main(argc, argv)); |
155 } | 254 } |
OLD | NEW |