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

Side by Side Diff: runtime/vm/unit_test.cc

Issue 2948273002: Correctly set root_library based on the application script URI instead of looking for the library t… (Closed)
Patch Set: Integrate cl from Siggi for front end change to not require a 'main' method when using the memory f… Created 3 years, 5 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/unit_test.h ('k') | tests/co19/co19-kernel.status » ('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 "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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0); 82 return (strncmp(url_name, kPackageScheme, kPackageSchemeLen) == 0);
83 } 83 }
84 84
85 struct TestLibEntry { 85 struct TestLibEntry {
86 const char* url; 86 const char* url;
87 const char* source; 87 const char* source;
88 }; 88 };
89 89
90 static MallocGrowableArray<TestLibEntry>* test_libs_ = NULL; 90 static MallocGrowableArray<TestLibEntry>* test_libs_ = NULL;
91 91
92 const char* TestCase::url() {
93 return (FLAG_use_dart_frontend) ? RESOLVED_USER_TEST_URI : USER_TEST_URI;
94 }
95
92 void TestCase::AddTestLib(const char* url, const char* source) { 96 void TestCase::AddTestLib(const char* url, const char* source) {
93 if (test_libs_ == NULL) { 97 if (test_libs_ == NULL) {
94 test_libs_ = new MallocGrowableArray<TestLibEntry>(); 98 test_libs_ = new MallocGrowableArray<TestLibEntry>();
95 } 99 }
96 // If the test lib is already added, replace the source. 100 // If the test lib is already added, replace the source.
97 for (intptr_t i = 0; i < test_libs_->length(); i++) { 101 for (intptr_t i = 0; i < test_libs_->length(); i++) {
98 if (strcmp(url, (*test_libs_)[i].url) == 0) { 102 if (strcmp(url, (*test_libs_)[i].url) == 0) {
99 (*test_libs_)[i].source = source; 103 (*test_libs_)[i].source = source;
100 return; 104 return;
101 } 105 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 const int kNumArgs = 1; 152 const int kNumArgs = 1;
149 Dart_Handle dart_args[kNumArgs]; 153 Dart_Handle dart_args[kNumArgs];
150 dart_args[0] = DartUtils::NewString(uri_chars); 154 dart_args[0] = DartUtils::NewString(uri_chars);
151 return Dart_Invoke(DartUtils::BuiltinLib(), 155 return Dart_Invoke(DartUtils::BuiltinLib(),
152 DartUtils::NewString("_filePathFromUri"), kNumArgs, 156 DartUtils::NewString("_filePathFromUri"), kNumArgs,
153 dart_args); 157 dart_args);
154 } 158 }
155 159
156 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey; 160 static ThreadLocalKey script_reload_key = kUnsetThreadLocalKey;
157 161
158 static char* CompileTestScriptWithDFE(const char* url, 162 char* TestCase::CompileTestScriptWithDFE(const char* url,
159 const char* source, 163 const char* source,
160 void** kernel_pgm) { 164 void** kernel_pgm) {
161 Zone* zone = Thread::Current()->zone(); 165 Zone* zone = Thread::Current()->zone();
162 char* filename = OS::SCreate(zone, "file:///%s", url);
163 // clang-format off 166 // clang-format off
164 Dart_SourceFile sourcefiles[] = { 167 Dart_SourceFile sourcefiles[] = {
165 { 168 {
166 filename, source, 169 url, source,
167 }, 170 },
168 { 171 {
169 "file:///.packages", "untitled:/" 172 "file:///.packages", "untitled:/"
170 }}; 173 }};
171 // clang-format on 174 // clang-format on
172 int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile); 175 int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile);
173 Dart_KernelCompilationResult compilation_result = 176 Dart_KernelCompilationResult compilation_result =
174 Dart_CompileSourcesToKernel(filename, sourcefiles_count, sourcefiles); 177 Dart_CompileSourcesToKernel(url, sourcefiles_count, sourcefiles);
175 178
176 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { 179 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
177 return OS::SCreate(zone, "Compilation failed %s", compilation_result.error); 180 return OS::SCreate(zone, "Compilation failed %s", compilation_result.error);
178 } 181 }
179 const uint8_t* kernel_file = compilation_result.kernel; 182 const uint8_t* kernel_file = compilation_result.kernel;
180 intptr_t kernel_length = compilation_result.kernel_size; 183 intptr_t kernel_length = compilation_result.kernel_size;
181 if (kernel_file == NULL) { 184 if (kernel_file == NULL) {
182 return OS::SCreate(zone, "front end generated a NULL kernel file"); 185 return OS::SCreate(zone, "front end generated a NULL kernel file");
183 } 186 }
184 *kernel_pgm = Dart_ReadKernelBinary(kernel_file, kernel_length); 187 *kernel_pgm = Dart_ReadKernelBinary(kernel_file, kernel_length);
(...skipping 12 matching lines...) Expand all
197 const char* script_source = reinterpret_cast<const char*>( 200 const char* script_source = reinterpret_cast<const char*>(
198 OSThread::GetThreadLocal(script_reload_key)); 201 OSThread::GetThreadLocal(script_reload_key));
199 ASSERT(script_source != NULL); 202 ASSERT(script_source != NULL);
200 OSThread::SetThreadLocal(script_reload_key, 0); 203 OSThread::SetThreadLocal(script_reload_key, 0);
201 const char* urlstr = NULL; 204 const char* urlstr = NULL;
202 Dart_Handle result = Dart_StringToCString(url, &urlstr); 205 Dart_Handle result = Dart_StringToCString(url, &urlstr);
203 if (Dart_IsError(result)) { 206 if (Dart_IsError(result)) {
204 return Dart_NewApiError("accessing url characters failed"); 207 return Dart_NewApiError("accessing url characters failed");
205 } 208 }
206 void* kernel_pgm; 209 void* kernel_pgm;
207 char* error = CompileTestScriptWithDFE(urlstr, script_source, &kernel_pgm); 210 char* error =
211 TestCase::CompileTestScriptWithDFE(urlstr, script_source, &kernel_pgm);
208 if (error == NULL) { 212 if (error == NULL) {
209 return Dart_LoadKernel(kernel_pgm); 213 return Dart_LoadScript(url, Dart_Null(),
214 reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0);
210 } else { 215 } else {
211 return Dart_NewApiError(error); 216 return Dart_NewApiError(error);
212 } 217 }
213 } 218 }
214 if (tag == Dart_kCanonicalizeUrl) { 219 if (tag == Dart_kCanonicalizeUrl) {
215 Dart_Handle library_url = Dart_LibraryUrl(library); 220 Dart_Handle library_url = Dart_LibraryUrl(library);
216 if (Dart_IsError(library_url)) { 221 if (Dart_IsError(library_url)) {
217 return library_url; 222 return library_url;
218 } 223 }
219 return Dart_DefaultCanonicalizeUrl(library_url, url); 224 return Dart_DefaultCanonicalizeUrl(library_url, url);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 result = Dart_FinalizeLoading(false); 319 result = Dart_FinalizeLoading(false);
315 DART_CHECK_VALID(result); 320 DART_CHECK_VALID(result);
316 } 321 }
317 return lib; 322 return lib;
318 } 323 }
319 324
320 static Dart_Handle LoadTestScriptWithDFE(const char* script, 325 static Dart_Handle LoadTestScriptWithDFE(const char* script,
321 Dart_NativeEntryResolver resolver, 326 Dart_NativeEntryResolver resolver,
322 const char* lib_url, 327 const char* lib_url,
323 bool finalize_classes) { 328 bool finalize_classes) {
329 Dart_Handle url = NewString(lib_url);
324 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler); 330 Dart_Handle result = Dart_SetLibraryTagHandler(LibraryTagHandler);
325 EXPECT_VALID(result); 331 EXPECT_VALID(result);
326 void* kernel_pgm = NULL; 332 void* kernel_pgm = NULL;
327 char* error = CompileTestScriptWithDFE(lib_url, script, &kernel_pgm); 333 char* error =
334 TestCase::CompileTestScriptWithDFE(lib_url, script, &kernel_pgm);
328 if (error == NULL) { 335 if (error == NULL) {
329 Dart_Handle lib = Dart_LoadKernel(kernel_pgm); 336 Dart_Handle lib = Dart_LoadScript(
337 url, Dart_Null(), reinterpret_cast<Dart_Handle>(kernel_pgm), 0, 0);
330 DART_CHECK_VALID(lib); 338 DART_CHECK_VALID(lib);
331 result = Dart_SetNativeResolver(lib, resolver, NULL); 339 result = Dart_SetNativeResolver(lib, resolver, NULL);
332 DART_CHECK_VALID(result); 340 DART_CHECK_VALID(result);
333 if (finalize_classes) { 341 if (finalize_classes) {
334 result = Dart_FinalizeLoading(false); 342 result = Dart_FinalizeLoading(false);
335 DART_CHECK_VALID(result); 343 DART_CHECK_VALID(result);
336 } 344 }
337 return lib; 345 return lib;
338 } else { 346 } else {
339 return Dart_NewApiError(error); 347 return Dart_NewApiError(error);
340 } 348 }
341 } 349 }
342 350
343 Dart_Handle TestCase::LoadTestScript(const char* script, 351 Dart_Handle TestCase::LoadTestScript(const char* script,
344 Dart_NativeEntryResolver resolver, 352 Dart_NativeEntryResolver resolver,
345 const char* lib_url, 353 const char* lib_url,
346 bool finalize_classes) { 354 bool finalize_classes) {
347 if (!FLAG_use_dart_frontend) { 355 if (!FLAG_use_dart_frontend) {
348 return LoadTestScriptWithVMParser(script, resolver, lib_url, 356 return LoadTestScriptWithVMParser(script, resolver, lib_url,
349 finalize_classes); 357 finalize_classes);
350 } else { 358 } else {
351 return LoadTestScriptWithDFE(script, resolver, lib_url, finalize_classes); 359 Zone* zone = Thread::Current()->zone();
360 char* resolved_lib_url = OS::SCreate(zone, "file:///%s", lib_url);
361 return LoadTestScriptWithDFE(script, resolver, resolved_lib_url,
362 finalize_classes);
352 } 363 }
353 } 364 }
354 365
355 #ifndef PRODUCT 366 #ifndef PRODUCT
356 367
357 void TestCase::SetReloadTestScript(const char* script) { 368 void TestCase::SetReloadTestScript(const char* script) {
358 if (script_reload_key == kUnsetThreadLocalKey) { 369 if (script_reload_key == kUnsetThreadLocalKey) {
359 script_reload_key = OSThread::CreateThreadLocal(); 370 script_reload_key = OSThread::CreateThreadLocal();
360 } 371 }
361 ASSERT(script_reload_key != kUnsetThreadLocalKey); 372 ASSERT(script_reload_key != kUnsetThreadLocalKey);
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 pos = strstr(in, prefix); 560 pos = strstr(in, prefix);
550 } 561 }
551 // Copy the remainder of in to out. 562 // Copy the remainder of in to out.
552 while (*in != '\0') { 563 while (*in != '\0') {
553 *out++ = *in++; 564 *out++ = *in++;
554 } 565 }
555 *out = '\0'; 566 *out = '\0';
556 } 567 }
557 568
558 } // namespace dart 569 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/unit_test.h ('k') | tests/co19/co19-kernel.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698