Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Side by Side Diff: runtime/bin/run_vm_tests.cc

Issue 2898743003: Revert "Revert "Use Kernel frontend from run_vm_tests."" (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/BUILD.gn ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 if (!is_kernel_isolate) {
115 *error =
116 strdup("Spawning of only Kernel isolate is supported in run_vm_tests.");
117 return NULL;
118 }
119 if (kernel_snapshot == NULL) {
120 *error =
121 strdup("Kernel snapshot location has to be specified via --dfe option");
122 return NULL;
123 }
124 script_uri = kernel_snapshot;
125
126 bin::AppSnapshot* app_snapshot =
127 bin::Snapshot::TryReadAppSnapshot(script_uri);
128 if (app_snapshot == NULL) {
129 *error = strdup("Failed to read kernel service app snapshot");
130 return NULL;
131 }
132
133 const uint8_t* isolate_snapshot_data = bin::core_isolate_snapshot_data;
134 const uint8_t* isolate_snapshot_instructions =
135 bin::core_isolate_snapshot_instructions;
136
137 const uint8_t* ignore_vm_snapshot_data;
138 const uint8_t* ignore_vm_snapshot_instructions;
139 app_snapshot->SetBuffers(
140 &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions,
141 &isolate_snapshot_data, &isolate_snapshot_instructions);
142
143 bin::IsolateData* isolate_data = new bin::IsolateData(
144 script_uri, package_root, packages_config, NULL /* app_snapshot */);
145 Dart_Isolate isolate = Dart_CreateIsolate(
146 script_uri, main, isolate_snapshot_data, isolate_snapshot_instructions,
147 flags, isolate_data, error);
148 if (isolate == NULL) {
149 *error = strdup("Failed to create isolate");
150 delete isolate_data;
151 return NULL;
152 }
153
154 Dart_EnterScope();
155
156 bin::DartUtils::SetOriginalWorkingDirectory();
157 Dart_Handle result = bin::DartUtils::PrepareForScriptLoading(
158 false /* is_service_isolate */, false /* trace_loading */);
159 CHECK_RESULT(result);
160
161 Dart_ExitScope();
162 Dart_ExitIsolate();
163 bool retval = Dart_IsolateMakeRunnable(isolate);
164 if (!retval) {
165 *error = strdup("Invalid isolate state - Unable to make it runnable");
166 Dart_EnterIsolate(isolate);
167 Dart_ShutdownIsolate();
168 return NULL;
169 }
170
171 return isolate;
172 }
84 173
85 static int Main(int argc, const char** argv) { 174 static int Main(int argc, const char** argv) {
86 // Flags being passed to the Dart VM. 175 // Flags being passed to the Dart VM.
87 int dart_argc = 0; 176 int dart_argc = 0;
88 const char** dart_argv = NULL; 177 const char** dart_argv = NULL;
89 178
90 // Perform platform specific initialization. 179 // Perform platform specific initialization.
91 if (!dart::bin::Platform::Initialize()) { 180 if (!dart::bin::Platform::Initialize()) {
92 OS::PrintErr("Initialization failed\n"); 181 OS::PrintErr("Initialization failed\n");
93 } 182 }
94 183
95 if (argc < 2) { 184 if (argc < 2) {
96 // Bad parameter count. 185 // Bad parameter count.
97 PrintUsage(); 186 PrintUsage();
98 return 1; 187 return 1;
99 } else if (argc == 2) { 188 }
100 if (strcmp(argv[1], "--list") == 0) { 189
101 run_filter = kList; 190 if (argc == 2 && strcmp(argv[1], "--list") == 0) {
102 // List all tests and benchmarks and exit without initializing the VM. 191 run_filter = kList;
103 TestCaseBase::RunAll(); 192 // List all tests and benchmarks and exit without initializing the VM.
104 Benchmark::RunAll(argv[0]); 193 TestCaseBase::RunAll();
105 TestCaseBase::RunAllRaw(); 194 Benchmark::RunAll(argv[0]);
106 fflush(stdout); 195 TestCaseBase::RunAllRaw();
107 return 0; 196 fflush(stdout);
108 } else if (strcmp(argv[1], "--benchmarks") == 0) { 197 return 0;
109 run_filter = kAllBenchmarks; 198 }
110 } else { 199
111 run_filter = argv[1]; 200 int arg_pos = 1;
201 if (strstr(argv[arg_pos], "--dfe") == argv[arg_pos]) {
202 const char* delim = strstr(argv[1], "=");
203 if (delim == NULL || strlen(delim + 1) == 0) {
204 OS::PrintErr("Invalid value for the option: %s\n", argv[1]);
205 PrintUsage();
206 return 1;
112 } 207 }
208 kernel_snapshot = strdup(delim + 1);
209 // VM needs '--use-dart-frontend' option, which we will insert in place
210 // of '--dfe' option.
211 argv[arg_pos] = strdup("--use-dart-frontend");
212 ++arg_pos;
213 }
214
215 if (arg_pos == argc - 1 && strcmp(argv[arg_pos], "--benchmarks") == 0) {
216 // "--benchmarks" is the last argument.
217 run_filter = kAllBenchmarks;
113 } else { 218 } else {
114 // Last argument is the test name, the rest are vm flags. 219 // Last argument is the test name, the rest are vm flags.
115 run_filter = argv[argc - 1]; 220 run_filter = argv[argc - 1];
116 // Remove the first value (executable) from the arguments and 221 // Remove the first value (executable) from the arguments and
117 // exclude the last argument which is the test name. 222 // exclude the last argument which is the test name.
118 dart_argc = argc - 2; 223 dart_argc = argc - 2;
119 dart_argv = &argv[1]; 224 dart_argv = &argv[1];
120 } 225 }
226
121 bool set_vm_flags_success = 227 bool set_vm_flags_success =
122 Flags::ProcessCommandLineFlags(dart_argc, dart_argv); 228 Flags::ProcessCommandLineFlags(dart_argc, dart_argv);
123 ASSERT(set_vm_flags_success); 229 ASSERT(set_vm_flags_success);
124 const char* err_msg = Dart::InitOnce( 230 const char* err_msg = Dart::InitOnce(
125 dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions, NULL, 231 dart::bin::vm_snapshot_data, dart::bin::vm_snapshot_instructions,
126 NULL, NULL, NULL, dart::bin::DartUtils::OpenFile, 232 CreateIsolateAndSetup /* create */, NULL /* shutdown */,
127 dart::bin::DartUtils::ReadFile, dart::bin::DartUtils::WriteFile, 233 NULL /* cleanup */, NULL /* thread_exit */,
128 dart::bin::DartUtils::CloseFile, NULL, NULL); 234 dart::bin::DartUtils::OpenFile, dart::bin::DartUtils::ReadFile,
235 dart::bin::DartUtils::WriteFile, dart::bin::DartUtils::CloseFile,
236 NULL /* entropy_source */, NULL /* get_service_assets */);
237
129 ASSERT(err_msg == NULL); 238 ASSERT(err_msg == NULL);
130 // Apply the filter to all registered tests. 239 // Apply the filter to all registered tests.
131 TestCaseBase::RunAll(); 240 TestCaseBase::RunAll();
132 // Apply the filter to all registered benchmarks. 241 // Apply the filter to all registered benchmarks.
133 Benchmark::RunAll(argv[0]); 242 Benchmark::RunAll(argv[0]);
134 243
135 err_msg = Dart::Cleanup(); 244 err_msg = Dart::Cleanup();
136 ASSERT(err_msg == NULL); 245 ASSERT(err_msg == NULL);
137 246
138 TestCaseBase::RunAllRaw(); 247 TestCaseBase::RunAllRaw();
139 // Print a warning message if no tests or benchmarks were matched. 248 // Print a warning message if no tests or benchmarks were matched.
140 if (run_matches == 0) { 249 if (run_matches == 0) {
141 OS::PrintErr("No tests matched: %s\n", run_filter); 250 OS::PrintErr("No tests matched: %s\n", run_filter);
142 return 1; 251 return 1;
143 } 252 }
144 if (DynamicAssertionHelper::failed()) { 253 if (DynamicAssertionHelper::failed()) {
145 return 255; 254 return 255;
146 } 255 }
147 return 0; 256 return 0;
148 } 257 }
149 258
150 } // namespace dart 259 } // namespace dart
151 260
152 261
153 int main(int argc, const char** argv) { 262 int main(int argc, const char** argv) {
154 dart::bin::Platform::Exit(dart::Main(argc, argv)); 263 dart::bin::Platform::Exit(dart::Main(argc, argv));
155 } 264 }
OLDNEW
« no previous file with comments | « runtime/bin/BUILD.gn ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698