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

Side by Side Diff: runtime/vm/unit_test.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/vm/kernel_isolate.cc ('k') | no next file » | 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 "vm/unit_test.h" 5 #include "vm/unit_test.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "bin/builtin.h" 9 #include "bin/builtin.h"
10 #include "bin/dartutils.h" 10 #include "bin/dartutils.h"
(...skipping 10 matching lines...) Expand all
21 #include "vm/parser.h" 21 #include "vm/parser.h"
22 #include "vm/symbols.h" 22 #include "vm/symbols.h"
23 #include "vm/thread.h" 23 #include "vm/thread.h"
24 #include "vm/virtual_memory.h" 24 #include "vm/virtual_memory.h"
25 25
26 using dart::bin::Builtin; 26 using dart::bin::Builtin;
27 using dart::bin::DartUtils; 27 using dart::bin::DartUtils;
28 28
29 namespace dart { 29 namespace dart {
30 30
31 DECLARE_FLAG(bool, use_dart_frontend);
32
31 TestCaseBase* TestCaseBase::first_ = NULL; 33 TestCaseBase* TestCaseBase::first_ = NULL;
32 TestCaseBase* TestCaseBase::tail_ = NULL; 34 TestCaseBase* TestCaseBase::tail_ = NULL;
33 35
34 36
35 TestCaseBase::TestCaseBase(const char* name) 37 TestCaseBase::TestCaseBase(const char* name)
36 : raw_test_(false), next_(NULL), name_(name) { 38 : raw_test_(false), next_(NULL), name_(name) {
37 if (first_ == NULL) { 39 if (first_ == NULL) {
38 first_ = this; 40 first_ = this;
39 } else { 41 } else {
40 tail_->next_ = this; 42 tail_->next_ = this;
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 Dart_Handle source = DartUtils::ReadStringFromFile(resolved_url_chars); 253 Dart_Handle source = DartUtils::ReadStringFromFile(resolved_url_chars);
252 EXPECT_VALID(source); 254 EXPECT_VALID(source);
253 if (tag == Dart_kImportTag) { 255 if (tag == Dart_kImportTag) {
254 return Dart_LoadLibrary(url, resolved_url, source, 0, 0); 256 return Dart_LoadLibrary(url, resolved_url, source, 0, 0);
255 } else { 257 } else {
256 ASSERT(tag == Dart_kSourceTag); 258 ASSERT(tag == Dart_kSourceTag);
257 return Dart_LoadSource(library, url, resolved_url, source, 0, 0); 259 return Dart_LoadSource(library, url, resolved_url, source, 0, 0);
258 } 260 }
259 } 261 }
260 262
261 263 static Dart_Handle LoadTestScriptWithVMParser(const char* script,
262 Dart_Handle TestCase::LoadTestScript(const char* script, 264 Dart_NativeEntryResolver resolver,
263 Dart_NativeEntryResolver resolver, 265 const char* lib_url,
264 const char* lib_url, 266 bool finalize_classes) {
265 bool finalize_classes) {
266 Dart_Handle url = NewString(lib_url); 267 Dart_Handle url = NewString(lib_url);
267 Dart_Handle source = NewString(script); 268 Dart_Handle source = NewString(script);
268 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); 269 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
269 EXPECT_VALID(result); 270 EXPECT_VALID(result);
270 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0); 271 Dart_Handle lib = Dart_LoadScript(url, Dart_Null(), source, 0, 0);
271 DART_CHECK_VALID(lib); 272 DART_CHECK_VALID(lib);
272 result = Dart_SetNativeResolver(lib, resolver, NULL); 273 result = Dart_SetNativeResolver(lib, resolver, NULL);
273 DART_CHECK_VALID(result); 274 DART_CHECK_VALID(result);
274 if (finalize_classes) { 275 if (finalize_classes) {
275 result = Dart_FinalizeLoading(false); 276 result = Dart_FinalizeLoading(false);
276 DART_CHECK_VALID(result); 277 DART_CHECK_VALID(result);
277 } 278 }
278 return lib; 279 return lib;
279 } 280 }
280 281
282 Dart_Handle TestCase::LoadTestScript(const char* script,
283 Dart_NativeEntryResolver resolver,
284 const char* lib_url,
285 bool finalize_classes) {
286 if (!FLAG_use_dart_frontend) {
287 return LoadTestScriptWithVMParser(script, resolver, lib_url,
288 finalize_classes);
289 }
290
291 Zone* zone = Thread::Current()->zone();
292 char* filename = OS::SCreate(zone, "file:///%s", lib_url);
293 // clang-format off
294 Dart_SourceFile sourcefiles[] = {
295 {
296 filename, script,
297 },
298 {
299 "file:///.packages", "untitled:/"
300 }};
301 // clang-format on
302
303 int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile);
304 Dart_KernelCompilationResult compilation_result =
305 Dart_CompileSourcesToKernel(filename, sourcefiles_count, sourcefiles);
306
307 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
308 return Dart_NewApiError(OS::SCreate(Thread::Current()->zone(),
309 "Compilation failed %s",
310 compilation_result.error));
311 }
312 const uint8_t* kernel_file = compilation_result.kernel;
313 intptr_t kernel_length = compilation_result.kernel_size;
314 if (kernel_file == NULL) {
315 return Dart_NewApiError(OS::SCreate(
316 Thread::Current()->zone(), "front end generated a NULL kernel file"));
317 }
318 void* kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
319 if (kernel_program == NULL) {
320 return Dart_NewApiError(OS::SCreate(
321 Thread::Current()->zone(), "Failed to read generated kernel binary"));
322 }
323 return Dart_LoadKernel(kernel_program);
324 }
281 325
282 #ifndef PRODUCT 326 #ifndef PRODUCT
283 327
284 328
285 void TestCase::SetReloadTestScript(const char* script) { 329 void TestCase::SetReloadTestScript(const char* script) {
286 if (script_reload_key == kUnsetThreadLocalKey) { 330 if (script_reload_key == kUnsetThreadLocalKey) {
287 script_reload_key = OSThread::CreateThreadLocal(); 331 script_reload_key = OSThread::CreateThreadLocal();
288 } 332 }
289 ASSERT(script_reload_key != kUnsetThreadLocalKey); 333 ASSERT(script_reload_key != kUnsetThreadLocalKey);
290 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0); 334 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 536 }
493 // Copy the remainder of in to out. 537 // Copy the remainder of in to out.
494 while (*in != '\0') { 538 while (*in != '\0') {
495 *out++ = *in++; 539 *out++ = *in++;
496 } 540 }
497 *out = '\0'; 541 *out = '\0';
498 } 542 }
499 543
500 544
501 } // namespace dart 545 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/kernel_isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698