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

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

Issue 8380020: Refactor the dart api a bit: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/unit_test.cc » ('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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/snapshot.h" 5 #include "vm/snapshot.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/bigint_operations.h" 8 #include "vm/bigint_operations.h"
9 #include "vm/class_finalizer.h" 9 #include "vm/class_finalizer.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 " final int fld2;\n" 318 " final int fld2;\n"
319 " static int fld3;\n" 319 " static int fld3;\n"
320 " static final int fld4 = 10;\n" 320 " static final int fld4 = 10;\n"
321 "}\n" 321 "}\n"
322 "class FieldsTest {\n" 322 "class FieldsTest {\n"
323 " static Fields testMain() {\n" 323 " static Fields testMain() {\n"
324 " Fields obj = new Fields(10, 20);\n" 324 " Fields obj = new Fields(10, 20);\n"
325 " return obj;\n" 325 " return obj;\n"
326 " }\n" 326 " }\n"
327 "}\n"; 327 "}\n";
328 Dart_Result result; 328 Dart_Handle result;
329 329
330 uint8_t* buffer; 330 uint8_t* buffer;
331 331
332 // Start an Isolate, load a script and create a full snapshot. 332 // Start an Isolate, load a script and create a full snapshot.
333 Timer timer1(true, "Snapshot_test"); 333 Timer timer1(true, "Snapshot_test");
334 timer1.Start(); 334 timer1.Start();
335 Dart_CreateIsolate(NULL, NULL); 335 Dart_CreateIsolate(NULL, NULL);
336 { 336 {
337 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 337 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
338 338
(...skipping 21 matching lines...) Expand all
360 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 360 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
361 timer2.Stop(); 361 timer2.Stop();
362 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); 362 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime());
363 363
364 // Invoke a function which returns an object. 364 // Invoke a function which returns an object.
365 result = Dart_InvokeStatic(TestCase::lib(), 365 result = Dart_InvokeStatic(TestCase::lib(),
366 Dart_NewString("FieldsTest"), 366 Dart_NewString("FieldsTest"),
367 Dart_NewString("testMain"), 367 Dart_NewString("testMain"),
368 0, 368 0,
369 NULL); 369 NULL);
370 EXPECT(Dart_IsValidResult(result)); 370 EXPECT(Dart_IsValid(result));
371 Dart_Handle retobj = Dart_GetResult(result); 371 EXPECT(!Dart_ExceptionOccurred(result));
372 EXPECT(!Dart_ExceptionOccurred(retobj));
373 372
374 Dart_ExitScope(); // Exit the Dart API scope. 373 Dart_ExitScope(); // Exit the Dart API scope.
375 } 374 }
376 Dart_ShutdownIsolate(); 375 Dart_ShutdownIsolate();
377 376
378 free(buffer); 377 free(buffer);
379 } 378 }
380 379
381 380
382 UNIT_TEST_CASE(FullSnapshot1) { 381 UNIT_TEST_CASE(FullSnapshot1) {
(...skipping 20 matching lines...) Expand all
403 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 402 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
404 ClassFinalizer::FinalizePendingClasses(); 403 ClassFinalizer::FinalizePendingClasses();
405 timer1.Stop(); 404 timer1.Stop();
406 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime()); 405 OS::PrintErr("Without Snapshot: %dus\n", timer1.TotalElapsedTime());
407 406
408 // Write snapshot with object content. 407 // Write snapshot with object content.
409 SnapshotWriter writer(true, &buffer, &allocator); 408 SnapshotWriter writer(true, &buffer, &allocator);
410 writer.WriteFullSnapshot(); 409 writer.WriteFullSnapshot();
411 410
412 // Invoke a function which returns an object. 411 // Invoke a function which returns an object.
413 Dart_Result result = Dart_InvokeStatic(lib, 412 Dart_Handle result = Dart_InvokeStatic(lib,
414 Dart_NewString("FieldsTest"), 413 Dart_NewString("FieldsTest"),
415 Dart_NewString("testMain"), 414 Dart_NewString("testMain"),
416 0, 415 0,
417 NULL); 416 NULL);
418 EXPECT(Dart_IsValidResult(result)); 417 EXPECT(Dart_IsValid(result));
419 Dart_Handle retobj = Dart_GetResult(result); 418 EXPECT(!Dart_ExceptionOccurred(result));
420 EXPECT(!Dart_ExceptionOccurred(retobj));
421 419
422 Dart_ExitScope(); // Exit the Dart API scope. 420 Dart_ExitScope(); // Exit the Dart API scope.
423 } 421 }
424 Dart_ShutdownIsolate(); 422 Dart_ShutdownIsolate();
425 423
426 // Now Create another isolate using the snapshot and execute a method 424 // Now Create another isolate using the snapshot and execute a method
427 // from the script. 425 // from the script.
428 Timer timer2(true, "Snapshot_test"); 426 Timer timer2(true, "Snapshot_test");
429 timer2.Start(); 427 timer2.Start();
430 Dart_CreateIsolate(buffer, NULL); 428 Dart_CreateIsolate(buffer, NULL);
431 { 429 {
432 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 430 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
433 timer2.Stop(); 431 timer2.Stop();
434 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime()); 432 OS::PrintErr("From Snapshot: %dus\n", timer2.TotalElapsedTime());
435 433
436 // Invoke a function which returns an object. 434 // Invoke a function which returns an object.
437 Dart_Result result = Dart_InvokeStatic(TestCase::lib(), 435 Dart_Handle result = Dart_InvokeStatic(TestCase::lib(),
438 Dart_NewString("FieldsTest"), 436 Dart_NewString("FieldsTest"),
439 Dart_NewString("testMain"), 437 Dart_NewString("testMain"),
440 0, 438 0,
441 NULL); 439 NULL);
442 EXPECT(Dart_IsValidResult(result)); 440 EXPECT(Dart_IsValid(result));
443 Dart_Handle retobj = Dart_GetResult(result); 441 if (Dart_ExceptionOccurred(result)) {
444 if (Dart_ExceptionOccurred(retobj)) {
445 // Print the exception object. 442 // Print the exception object.
446 fprintf(stderr, "An unhandled exception has been thrown\n"); 443 fprintf(stderr, "An unhandled exception has been thrown\n");
447 Dart_Result exception_result = Dart_GetException(retobj); 444 Dart_Handle exception_result = Dart_GetException(result);
448 assert(Dart_IsValidResult(exception_result)); 445 assert(Dart_IsValid(exception_result));
449 Dart_Handle retval_string = Dart_GetResult(exception_result); 446 const char* obj_cstring = NULL;
450 Dart_Result retstr = Dart_StringToCString(retval_string); 447 Dart_Handle retstr = Dart_StringToCString(exception_result, &obj_cstring);
451 const char* obj_cstring = Dart_IsValidResult(retstr) ? 448 if (!Dart_IsValid(retstr)) {
452 Dart_GetResultAsCString(retstr) : Dart_GetErrorCString(retstr); 449 obj_cstring = Dart_GetError(retstr);
450 }
453 fprintf(stderr, "%s", obj_cstring); 451 fprintf(stderr, "%s", obj_cstring);
454 } 452 }
455 EXPECT(!Dart_ExceptionOccurred(retobj)); 453 EXPECT(!Dart_ExceptionOccurred(result));
456 454
457 Dart_ExitScope(); // Exit the Dart API scope. 455 Dart_ExitScope(); // Exit the Dart API scope.
458 } 456 }
459 Dart_ShutdownIsolate(); 457 Dart_ShutdownIsolate();
460 458
461 free(buffer); 459 free(buffer);
462 } 460 }
463 #endif // TARGET_ARCH_IA32. 461 #endif // TARGET_ARCH_IA32.
464 462
465 } // namespace dart 463 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/parser.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698