Index: runtime/vm/unit_test.cc |
diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc |
index 147d0eb73afce0358c8f37b00e447133a44d2de2..e7a468d3d814c1f533baaa159517d7ae5b16f434 100644 |
--- a/runtime/vm/unit_test.cc |
+++ b/runtime/vm/unit_test.cc |
@@ -28,6 +28,8 @@ using dart::bin::DartUtils; |
namespace dart { |
+DECLARE_FLAG(bool, use_dart_frontend); |
+ |
TestCaseBase* TestCaseBase::first_ = NULL; |
TestCaseBase* TestCaseBase::tail_ = NULL; |
@@ -258,11 +260,10 @@ static Dart_Handle LibraryTagHandler(Dart_LibraryTag tag, |
} |
} |
- |
-Dart_Handle TestCase::LoadTestScript(const char* script, |
- Dart_NativeEntryResolver resolver, |
- const char* lib_url, |
- bool finalize_classes) { |
+static Dart_Handle LoadTestScriptWithVMParser(const char* script, |
+ Dart_NativeEntryResolver resolver, |
+ const char* lib_url, |
+ bool finalize_classes) { |
Dart_Handle url = NewString(lib_url); |
Dart_Handle source = NewString(script); |
Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); |
@@ -278,6 +279,50 @@ Dart_Handle TestCase::LoadTestScript(const char* script, |
return lib; |
} |
+static char* Concat(const char* s1, const char* s2) { |
+ int len = strlen(s1) + strlen(s2); |
+ char* filename = new char[len + 1]; |
+ snprintf(filename, len + 1, "%s%s", s1, s2); |
+ return filename; |
+} |
siva
2017/05/18 00:02:38
The Concat function above may not be needed if you
aam
2017/05/18 01:03:00
Done.
|
+ |
+Dart_Handle TestCase::LoadTestScript(const char* script, |
+ Dart_NativeEntryResolver resolver, |
+ const char* lib_url, |
+ bool finalize_classes) { |
+ if (!FLAG_use_dart_frontend) { |
+ return LoadTestScriptWithVMParser(script, resolver, lib_url, |
+ finalize_classes); |
+ } |
siva
2017/05/18 00:02:38
Zone* zone = Thread::Current()->zone();
aam
2017/05/18 01:03:00
Done.
|
+ |
+ char* filename = Concat("file:///", lib_url); |
siva
2017/05/18 00:02:39
char* filename = OS::SCreate(zone, "file:///", lib
aam
2017/05/18 01:03:00
Done.
|
+ // clang-format off |
+ Dart_SourceFile sourcefiles[] = { |
+ { |
+ filename, script, |
+ }, |
+ { |
+ "file:///.packages", "untitled:/" |
+ }}; |
+ // clang-format on |
+ |
+ int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile); |
+ Dart_KernelCompilationResult compilation_result = |
+ Dart_CompileSourcesToKernel(filename, sourcefiles_count, sourcefiles); |
+ delete[] filename; |
siva
2017/05/18 00:02:38
delete not needed as 'filename' would be zone allo
aam
2017/05/18 01:03:00
Awesome, done!
|
+ |
+ EXPECT(compilation_result.status == Dart_KernelCompilationStatus_Ok) |
siva
2017/05/18 00:02:38
The EXPECT above would also print an error message
aam
2017/05/18 01:03:01
Right, done.
|
+ if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { |
+ OS::PrintErr("Compilation failed %s", compilation_result.error); |
+ return NULL; |
siva
2017/05/18 00:02:38
should return a Dart_Handle not NULL
return Dart_
aam
2017/05/18 01:03:01
Oh, nice! Done.
|
+ } |
+ const uint8_t* kernel_file = compilation_result.kernel; |
+ intptr_t kernel_length = compilation_result.kernel_size; |
+ EXPECT(kernel_file != NULL); |
siva
2017/05/18 00:02:38
Should this be ASSERT(kernel_file != NULL);
or
i
aam
2017/05/18 01:03:01
Yes, I like this better!
|
+ void* kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length); |
+ EXPECT(kernel_program != NULL); |
siva
2017/05/18 00:02:38
Ditto comment about this check here, should return
aam
2017/05/18 01:03:01
Done!
|
+ return Dart_LoadKernel(kernel_program); |
+} |
#ifndef PRODUCT |