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

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

Issue 2881953002: Use Kernel frontend from run_vm_tests. (Closed)
Patch Set: Rename --run_vm_test_with_kernel_snapshot option to --dfe 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
« runtime/bin/run_vm_tests.cc ('K') | « 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 static char* Concat(const char* s1, const char* s2) {
283 int len = strlen(s1) + strlen(s2);
284 char* filename = new char[len + 1];
285 snprintf(filename, len + 1, "%s%s", s1, s2);
286 return filename;
287 }
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.
288
289 Dart_Handle TestCase::LoadTestScript(const char* script,
290 Dart_NativeEntryResolver resolver,
291 const char* lib_url,
292 bool finalize_classes) {
293 if (!FLAG_use_dart_frontend) {
294 return LoadTestScriptWithVMParser(script, resolver, lib_url,
295 finalize_classes);
296 }
siva 2017/05/18 00:02:38 Zone* zone = Thread::Current()->zone();
aam 2017/05/18 01:03:00 Done.
297
298 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.
299 // clang-format off
300 Dart_SourceFile sourcefiles[] = {
301 {
302 filename, script,
303 },
304 {
305 "file:///.packages", "untitled:/"
306 }};
307 // clang-format on
308
309 int sourcefiles_count = sizeof(sourcefiles) / sizeof(Dart_SourceFile);
310 Dart_KernelCompilationResult compilation_result =
311 Dart_CompileSourcesToKernel(filename, sourcefiles_count, sourcefiles);
312 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!
313
314 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.
315 if (compilation_result.status != Dart_KernelCompilationStatus_Ok) {
316 OS::PrintErr("Compilation failed %s", compilation_result.error);
317 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.
318 }
319 const uint8_t* kernel_file = compilation_result.kernel;
320 intptr_t kernel_length = compilation_result.kernel_size;
321 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!
322 void* kernel_program = Dart_ReadKernelBinary(kernel_file, kernel_length);
323 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!
324 return Dart_LoadKernel(kernel_program);
325 }
281 326
282 #ifndef PRODUCT 327 #ifndef PRODUCT
283 328
284 329
285 void TestCase::SetReloadTestScript(const char* script) { 330 void TestCase::SetReloadTestScript(const char* script) {
286 if (script_reload_key == kUnsetThreadLocalKey) { 331 if (script_reload_key == kUnsetThreadLocalKey) {
287 script_reload_key = OSThread::CreateThreadLocal(); 332 script_reload_key = OSThread::CreateThreadLocal();
288 } 333 }
289 ASSERT(script_reload_key != kUnsetThreadLocalKey); 334 ASSERT(script_reload_key != kUnsetThreadLocalKey);
290 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0); 335 ASSERT(OSThread::GetThreadLocal(script_reload_key) == 0);
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 } 537 }
493 // Copy the remainder of in to out. 538 // Copy the remainder of in to out.
494 while (*in != '\0') { 539 while (*in != '\0') {
495 *out++ = *in++; 540 *out++ = *in++;
496 } 541 }
497 *out = '\0'; 542 *out = '\0';
498 } 543 }
499 544
500 545
501 } // namespace dart 546 } // namespace dart
OLDNEW
« runtime/bin/run_vm_tests.cc ('K') | « runtime/vm/kernel_isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698