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 [--run_vm_test_with_kernel_snapshot=<snapshot file " |
81 OS::PrintErr("run_vm_tests [vm-flags ...] <benchmark name>\n"); | 84 "name>] --benchmarks\n" |
85 " run_vm_tests [--run_vm_test_with_kernel_snapshot=<snapshot file " | |
86 "name>] [vm-flags ...] <test name>\n" | |
87 " run_vm_tests [--run_vm_test_with_kernel_snapshot=<snapshot file " | |
88 "name>] [vm-flags ...] <benchmark name>\n"); | |
82 } | 89 } |
83 | 90 |
91 #define CHECK_RESULT(result) \ | |
92 if (Dart_IsError(result)) { \ | |
93 *error = strdup(Dart_GetError(result)); \ | |
94 Dart_ExitScope(); \ | |
95 Dart_ShutdownIsolate(); \ | |
96 return NULL; \ | |
97 } | |
98 | |
99 | |
100 static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, | |
101 const char* main, | |
102 const char* package_root, | |
103 const char* packages_config, | |
104 Dart_IsolateFlags* flags, | |
105 void* data, | |
106 char** error) { | |
107 ASSERT(script_uri != NULL); | |
108 const bool is_service_isolate = | |
109 strcmp(script_uri, DART_VM_SERVICE_ISOLATE_NAME) == 0; | |
110 if (is_service_isolate) { | |
111 // We don't need service isolate for VM tests. | |
112 return NULL; | |
113 } | |
114 const bool is_kernel_isolate = | |
115 strcmp(script_uri, DART_KERNEL_ISOLATE_NAME) == 0; | |
116 const uint8_t* isolate_snapshot_data = bin::core_isolate_snapshot_data; | |
117 const uint8_t* isolate_snapshot_instructions = | |
118 bin::core_isolate_snapshot_instructions; | |
119 if (is_kernel_isolate) { | |
120 if (kernel_snapshot == NULL) { | |
121 *error = strdup( | |
122 "Kernel snapshot location has to be specified via " | |
123 "--run_vm_test_with_kernel_snapshot option"); | |
124 return NULL; | |
125 } | |
126 script_uri = kernel_snapshot; | |
127 bin::AppSnapshot* app_snapshot = | |
128 bin::Snapshot::TryReadAppSnapshot(script_uri); | |
129 if (app_snapshot == NULL) { | |
130 *error = strdup("Failed to read kernel service app snapshot"); | |
131 return NULL; | |
132 } | |
133 const uint8_t* ignore_vm_snapshot_data; | |
134 const uint8_t* ignore_vm_snapshot_instructions; | |
135 app_snapshot->SetBuffers( | |
136 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, | |
137 &isolate_snapshot_data, &isolate_snapshot_instructions); | |
138 } | |
139 | |
siva
2017/05/15 04:34:26
Will this code run for non kernel isolates too?
aam
2017/05/15 23:49:14
Yes, if I understand correctly, this callback will
| |
140 bin::IsolateData* isolate_data = new bin::IsolateData( | |
141 script_uri, package_root, packages_config, NULL /* app_snapshot */); | |
142 Dart_Isolate isolate = Dart_CreateIsolate( | |
143 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions, | |
144 flags, isolate_data, error); | |
145 if (isolate == NULL) { | |
146 *error = strdup("Failed to create isolate"); | |
147 delete isolate_data; | |
148 return NULL; | |
149 } | |
150 | |
151 Dart_EnterScope(); | |
152 | |
153 bin::DartUtils::SetOriginalWorkingDirectory(); | |
154 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading( | |
155 false /* is_service_isolate */, false /* trace_loading */); | |
156 CHECK_RESULT(result); | |
157 | |
158 Dart_ExitScope(); | |
159 Dart_ExitIsolate(); | |
160 bool retval = Dart_IsolateMakeRunnable(isolate); | |
161 if (!retval) { | |
162 *error = strdup("Invalid isolate state - Unable to make it runnable"); | |
163 Dart_EnterIsolate(isolate); | |
164 Dart_ShutdownIsolate(); | |
165 return NULL; | |
166 } | |
167 | |
168 return isolate; | |
169 } | |
84 | 170 |
85 static int Main(int argc, const char** argv) { | 171 static int Main(int argc, const char** argv) { |
86 // Flags being passed to the Dart VM. | 172 // Flags being passed to the Dart VM. |
87 int dart_argc = 0; | 173 int dart_argc = 0; |
88 const char** dart_argv = NULL; | 174 const char** dart_argv = NULL; |
89 | 175 |
90 // Perform platform specific initialization. | 176 // Perform platform specific initialization. |
91 if (!dart::bin::Platform::Initialize()) { | 177 if (!dart::bin::Platform::Initialize()) { |
92 OS::PrintErr("Initialization failed\n"); | 178 OS::PrintErr("Initialization failed\n"); |
93 } | 179 } |
94 | 180 |
95 if (argc < 2) { | 181 if (argc < 2) { |
96 // Bad parameter count. | 182 // Bad parameter count. |
97 PrintUsage(); | 183 PrintUsage(); |
98 return 1; | 184 return 1; |
99 } else if (argc == 2) { | 185 } |
100 if (strcmp(argv[1], "--list") == 0) { | 186 |
101 run_filter = kList; | 187 if (argc == 2 && strcmp(argv[1], "--list") == 0) { |
102 // List all tests and benchmarks and exit without initializing the VM. | 188 run_filter = kList; |
103 TestCaseBase::RunAll(); | 189 // List all tests and benchmarks and exit without initializing the VM. |
104 Benchmark::RunAll(argv[0]); | 190 TestCaseBase::RunAll(); |
105 TestCaseBase::RunAllRaw(); | 191 Benchmark::RunAll(argv[0]); |
106 fflush(stdout); | 192 TestCaseBase::RunAllRaw(); |
107 return 0; | 193 fflush(stdout); |
108 } else if (strcmp(argv[1], "--benchmarks") == 0) { | 194 return 0; |
109 run_filter = kAllBenchmarks; | 195 } |
110 } else { | 196 |
111 run_filter = argv[1]; | 197 int arg_pos = 1; |
198 if (strstr(argv[arg_pos], "--run_vm_test_with_kernel_snapshot") == | |
siva
2017/05/15 04:34:26
Can we rename this option to --dfe same as the one
aam
2017/05/15 23:49:14
--dfe option is picked up by VM, not run_vm_test o
aam
2017/05/16 00:48:32
Thanks for clarifying main.cc(embedder) '--dfe' ve
| |
199 argv[arg_pos]) { | |
200 const char* delim = strstr(argv[1], "="); | |
201 if (delim == NULL || strlen(delim + 1) == 0) { | |
202 OS::PrintErr("Invalid value for the option: %s\n", argv[1]); | |
203 PrintUsage(); | |
204 return 1; | |
112 } | 205 } |
206 kernel_snapshot = strdup(delim + 1); | |
207 ++arg_pos; | |
208 } | |
209 | |
210 if (arg_pos == argc - 1 && strcmp(argv[arg_pos], "--benchmarks") == 0) { | |
211 // "--benchmarks" is the last argument. | |
212 run_filter = kAllBenchmarks; | |
113 } else { | 213 } else { |
114 // Last argument is the test name, the rest are vm flags. | 214 // Last argument is the test name, the rest are vm flags. |
115 run_filter = argv[argc - 1]; | 215 run_filter = argv[argc - 1]; |
116 // Remove the first value (executable) from the arguments and | 216 // Remove the first value (executable) from the arguments and |
117 // exclude the last argument which is the test name. | 217 // exclude the last argument which is the test name. |
118 dart_argc = argc - 2; | 218 dart_argc = argc - arg_pos; |
119 dart_argv = &argv[1]; | 219 dart_argv = &argv[arg_pos]; |
120 } | 220 } |
121 bool set_vm_flags_success = | 221 bool set_vm_flags_success = |
122 Flags::ProcessCommandLineFlags(dart_argc, dart_argv); | 222 Flags::ProcessCommandLineFlags(dart_argc, dart_argv); |
123 ASSERT(set_vm_flags_success); | 223 ASSERT(set_vm_flags_success); |
124 const char* err_msg = Dart::InitOnce( | 224 const char* err_msg = Dart::InitOnce( |
125 dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, NULL, | 225 dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, |
126 NULL, NULL, NULL, dart::bin::DartUtils::OpenFile, | 226 CreateIsolateAndSetup /* create */, NULL /* shutdown */, |
127 dart::bin::DartUtils::ReadFile, dart::bin::DartUtils::WriteFile, | 227 NULL /* cleanup */, NULL /* thread_exit */, |
128 dart::bin::DartUtils::CloseFile, NULL, NULL); | 228 dart::bin::DartUtils::OpenFile, dart::bin::DartUtils::ReadFile, |
229 dart::bin::DartUtils::WriteFile, dart::bin::DartUtils::CloseFile, | |
230 NULL /* entropy_source */, NULL /* get_service_assets */); | |
231 | |
129 ASSERT(err_msg == NULL); | 232 ASSERT(err_msg == NULL); |
130 // Apply the filter to all registered tests. | 233 // Apply the filter to all registered tests. |
131 TestCaseBase::RunAll(); | 234 TestCaseBase::RunAll(); |
132 // Apply the filter to all registered benchmarks. | 235 // Apply the filter to all registered benchmarks. |
133 Benchmark::RunAll(argv[0]); | 236 Benchmark::RunAll(argv[0]); |
134 | 237 |
135 err_msg = Dart::Cleanup(); | 238 err_msg = Dart::Cleanup(); |
136 ASSERT(err_msg == NULL); | 239 ASSERT(err_msg == NULL); |
137 | 240 |
138 TestCaseBase::RunAllRaw(); | 241 TestCaseBase::RunAllRaw(); |
139 // Print a warning message if no tests or benchmarks were matched. | 242 // Print a warning message if no tests or benchmarks were matched. |
140 if (run_matches == 0) { | 243 if (run_matches == 0) { |
141 OS::PrintErr("No tests matched: %s\n", run_filter); | 244 OS::PrintErr("No tests matched: %s\n", run_filter); |
142 return 1; | 245 return 1; |
143 } | 246 } |
144 if (DynamicAssertionHelper::failed()) { | 247 if (DynamicAssertionHelper::failed()) { |
145 return 255; | 248 return 255; |
146 } | 249 } |
147 return 0; | 250 return 0; |
148 } | 251 } |
149 | 252 |
150 } // namespace dart | 253 } // namespace dart |
151 | 254 |
152 | 255 |
153 int main(int argc, const char** argv) { | 256 int main(int argc, const char** argv) { |
154 dart::bin::Platform::Exit(dart::Main(argc, argv)); | 257 dart::bin::Platform::Exit(dart::Main(argc, argv)); |
155 } | 258 } |
OLD | NEW |