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

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

Issue 27054002: Add unit tests to cover stack inspect in the presence of closure calls (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | runtime/vm/deopt_instructions.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) 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 "include/dart_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "include/dart_mirrors_api.h" 6 #include "include/dart_mirrors_api.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/thread.h" 9 #include "vm/thread.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 LoadScript(kScriptChars); 424 LoadScript(kScriptChars);
425 425
426 // Save/restore some compiler flags. 426 // Save/restore some compiler flags.
427 Dart_Handle dart_args[2]; 427 Dart_Handle dart_args[2];
428 int saved_threshold = FLAG_optimization_counter_threshold; 428 int saved_threshold = FLAG_optimization_counter_threshold;
429 const int kLowThreshold = 100; 429 const int kLowThreshold = 100;
430 const int kHighThreshold = 10000; 430 const int kHighThreshold = 10000;
431 bool saved_osr = FLAG_use_osr; 431 bool saved_osr = FLAG_use_osr;
432 FLAG_use_osr = false; 432 FLAG_use_osr = false;
433 433
434 // Set up the breakpoint.
435 Dart_SetPausedEventHandler(InspectOptimizedStack_Breakpoint);
436 SetBreakpointAtEntry("", "breakpointNow");
437
438 if (optimize) { 434 if (optimize) {
439 // Warm up the code to make sure it gets optimized. We ignore any 435 // Warm up the code to make sure it gets optimized. We ignore any
440 // breakpoints that get hit during warm-up. 436 // breakpoints that get hit during warm-up.
441 FLAG_optimization_counter_threshold = kLowThreshold; 437 FLAG_optimization_counter_threshold = kLowThreshold;
442 dart_args[0] = Dart_False(); 438 dart_args[0] = Dart_False();
443 dart_args[1] = Dart_NewInteger(kLowThreshold); 439 dart_args[1] = Dart_NewInteger(kLowThreshold);
444 EXPECT_VALID(Dart_Invoke(script_lib, NewString("test"), 2, dart_args)); 440 EXPECT_VALID(Dart_Invoke(script_lib, NewString("test"), 2, dart_args));
445 } else { 441 } else {
446 // Try to ensure that none of the test code gets optimized. 442 // Try to ensure that none of the test code gets optimized.
447 FLAG_optimization_counter_threshold = kHighThreshold; 443 FLAG_optimization_counter_threshold = kHighThreshold;
448 } 444 }
449 445
446 // Set up the breakpoint.
447 Dart_SetPausedEventHandler(InspectOptimizedStack_Breakpoint);
448 SetBreakpointAtEntry("", "breakpointNow");
449
450 // Run the code and inspect the stack. 450 // Run the code and inspect the stack.
451 stack_buffer[0] = '\0'; 451 stack_buffer[0] = '\0';
452 dart_args[0] = Dart_True(); 452 dart_args[0] = Dart_True();
453 dart_args[1] = Dart_NewInteger(kLowThreshold); 453 dart_args[1] = Dart_NewInteger(kLowThreshold);
454 EXPECT_VALID(Dart_Invoke(script_lib, NewString("test"), 2, dart_args)); 454 EXPECT_VALID(Dart_Invoke(script_lib, NewString("test"), 2, dart_args));
455 if (optimize) { 455 if (optimize) {
456 // Note that several variables have the value 'null' in the 456 // Note that several variables have the value 'null' in the
457 // optimized case. This is because these values were determined 457 // optimized case. This is because these values were determined
458 // to be dead by the optimizing compiler and their values were not 458 // to be dead by the optimizing compiler and their values were not
459 // preserved by the deopt information. 459 // preserved by the deopt information.
(...skipping 22 matching lines...) Expand all
482 TEST_CASE(Debug_InspectStack_NotOptimized) { 482 TEST_CASE(Debug_InspectStack_NotOptimized) {
483 InspectStackTest(false); 483 InspectStackTest(false);
484 } 484 }
485 485
486 486
487 TEST_CASE(Debug_InspectStack_Optimized) { 487 TEST_CASE(Debug_InspectStack_Optimized) {
488 InspectStackTest(true); 488 InspectStackTest(true);
489 } 489 }
490 490
491 491
492 static void InspectStackWithClosureTest(bool optimize) {
493 const char* kScriptChars =
494 "void breakpointNow() {\n"
495 "}\n"
496 "int helper(int a, int b, bool stop) {\n"
497 " if (b == 99 && stop) {\n"
498 " breakpointNow();\n"
499 " }\n"
500 " int c = a*b;\n"
501 " return c;\n"
502 "}\n"
503 "int anotherMiddleMan(func) {\n"
504 " return func(10);\n"
505 "}\n"
506 "int middleMan(int x, int limit, bool stop) {\n"
507 " int value = 0;\n"
508 " for (int i = 0; i < limit; i++) {\n"
509 " value += anotherMiddleMan((value) {\n"
510 " return helper((x * value), i, stop);\n"
511 " });\n"
512 " }\n"
513 " return value;\n"
514 "}\n"
515 "int test(bool stop, int limit) {\n"
516 " return middleMan(5, limit, stop);\n"
517 "}\n";
518
519 LoadScript(kScriptChars);
520
521 // Save/restore some compiler flags.
522 Dart_Handle dart_args[2];
523 int saved_threshold = FLAG_optimization_counter_threshold;
524 const int kLowThreshold = 100;
525 const int kHighThreshold = 10000;
526 bool saved_osr = FLAG_use_osr;
527 FLAG_use_osr = false;
528
529 if (optimize) {
530 // Warm up the code to make sure it gets optimized. We ignore any
531 // breakpoints that get hit during warm-up.
532 FLAG_optimization_counter_threshold = kLowThreshold;
533 dart_args[0] = Dart_False();
534 dart_args[1] = Dart_NewInteger(kLowThreshold);
535 EXPECT_VALID(Dart_Invoke(script_lib, NewString("test"), 2, dart_args));
536 } else {
537 // Try to ensure that none of the test code gets optimized.
538 FLAG_optimization_counter_threshold = kHighThreshold;
539 }
540
541 // Set up the breakpoint.
542 Dart_SetPausedEventHandler(InspectOptimizedStack_Breakpoint);
543 SetBreakpointAtEntry("", "breakpointNow");
544
545 // Run the code and inspect the stack.
546 stack_buffer[0] = '\0';
547 dart_args[0] = Dart_True();
548 dart_args[1] = Dart_NewInteger(kLowThreshold);
549 EXPECT_VALID(Dart_Invoke(script_lib, NewString("test"), 2, dart_args));
550 if (optimize) {
551 EXPECT_STREQ("[0] breakpointNow { }\n"
552 "[1] helper { a = 50 b = 99 stop = null }\n"
553 "[2] <anonymous closure> { x = <unknown>"
554 " stop = <unknown> value = null }\n"
555 "[3] anotherMiddleMan { func = null }\n"
556 "[4] middleMan { limit = 100 value = 242550 }\n"
557 "[5] test { stop = true limit = 100 }\n",
558 stack_buffer);
559 } else {
560 EXPECT_STREQ("[0] breakpointNow { }\n"
561 "[1] helper { a = 50 b = 99 stop = true }\n"
562 "[2] <anonymous closure> { x = 5 i = 99"
563 " stop = <unknown> value = 10 }\n"
564 "[3] anotherMiddleMan {"
565 " func = Closure: (dynamic) => dynamic }\n"
566 "[4] middleMan { x = 5 limit = 100 stop = <unknown>"
567 " value = 242550 i = 99 }\n"
568 "[5] test { stop = true limit = 100 }\n",
569 stack_buffer);
570 }
571
572 FLAG_optimization_counter_threshold = saved_threshold;
573 FLAG_use_osr = saved_osr;
574 }
575
576
577 TEST_CASE(Debug_InspectStackWithClosure_NotOptimized) {
578 InspectStackWithClosureTest(false);
579 }
580
581
582 TEST_CASE(Debug_InspectStackWithClosure_Optimized) {
583 InspectStackWithClosureTest(true);
584 }
585
586
492 void TestStepOutHandler(Dart_IsolateId isolate_id, 587 void TestStepOutHandler(Dart_IsolateId isolate_id,
493 const Dart_CodeLocation& location) { 588 const Dart_CodeLocation& location) {
494 Dart_StackTrace trace; 589 Dart_StackTrace trace;
495 Dart_GetStackTrace(&trace); 590 Dart_GetStackTrace(&trace);
496 const char* expected_bpts[] = {"f1", "foo", "main"}; 591 const char* expected_bpts[] = {"f1", "foo", "main"};
497 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); 592 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts);
498 intptr_t trace_len; 593 intptr_t trace_len;
499 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 594 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
500 EXPECT_VALID(res); 595 EXPECT_VALID(res);
501 EXPECT(breakpoint_hit_counter < expected_bpts_length); 596 EXPECT(breakpoint_hit_counter < expected_bpts_length);
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after
1921 2016
1922 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj); 2017 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj);
1923 Dart_Handle super_type = Dart_GetSupertype(list_type); 2018 Dart_Handle super_type = Dart_GetSupertype(list_type);
1924 EXPECT(!Dart_IsError(super_type)); 2019 EXPECT(!Dart_IsError(super_type));
1925 super_type = Dart_GetSupertype(super_type); 2020 super_type = Dart_GetSupertype(super_type);
1926 EXPECT(!Dart_IsError(super_type)); 2021 EXPECT(!Dart_IsError(super_type));
1927 EXPECT(super_type == Dart_Null()); 2022 EXPECT(super_type == Dart_Null());
1928 } 2023 }
1929 2024
1930 } // namespace dart 2025 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/deopt_instructions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698