Index: runtime/observatory/tests/service/evaluate_activation_test.dart |
diff --git a/runtime/observatory/tests/service/evaluate_activation_test.dart b/runtime/observatory/tests/service/evaluate_activation_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2f1739a43c0f80121b92005f95420f5154974463 |
--- /dev/null |
+++ b/runtime/observatory/tests/service/evaluate_activation_test.dart |
@@ -0,0 +1,252 @@ |
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+// VMOptions=--compile-all --error_on_bad_type --error_on_bad_override |
+ |
+import 'package:observatory/service_io.dart'; |
+import 'package:unittest/unittest.dart'; |
+import 'test_helper.dart'; |
+import 'dart:async'; |
+ |
+import 'dart:math' as math; |
+ |
+breakHere() {} |
+ |
+class C { |
+ var instVar = 1; |
+ static var classVar = 2; |
+ |
+ method(methodParam) { |
+ var methodTemp = 4; |
+ [5].forEach((outerParam) { |
+ var outerTemp = 6; |
+ [7].forEach((innerParam) { |
+ var innerTemp = 8; |
+ breakHere(); |
+ }); |
+ }); |
+ } |
+ |
+ static method2(methodParam) { |
+ var methodTemp = 4; |
+ [5].forEach((outerParam) { |
+ var outerTemp = 6; |
+ [7].forEach((innerParam) { |
+ var innerTemp = 8; |
+ breakHere(); |
+ }); |
+ }); |
+ } |
+ |
+ method3(methodParam) { |
+ var methodTemp = 4; |
+ breakHere(); |
+ } |
+ |
+ static var closureWithReturnedHome; |
+ method4(methodParam) { |
+ var methodTemp = 4; |
+ [5].forEach((outerParam) { |
+ var outerTemp = 6; |
+ closureWithReturnedHome = (innerParam) { |
+ var innerTemp = 8; |
+ breakHere(); |
+ }; |
+ }); |
+ } |
+} |
+ |
+testMethod(Isolate isolate) async { |
+ Library rootLib = await isolate.rootLib.load(); |
+ ServiceFunction function = |
+ rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
+ Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
+ print("Breakpoint: $bpt"); |
+ expect(bpt is Breakpoint, isTrue); // I.e, not null. |
+ |
+ bool hitBreakpoint = false; |
+ var sub; |
+ sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
+ print("Event $event"); |
+ if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
+ var frameNumber = 1, r; |
+ r = await isolate.evalFrame(frameNumber, '123'); /// instance: ok |
+ expect(r.valueAsString, equals('123')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'this'); /// scope: ok |
+ expect(r.clazz.name, equals('C')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'instVar'); /// instance: continued |
+ expect(r.valueAsString, equals('1')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'classVar'); /// instance: continued |
+ expect(r.valueAsString, equals('2')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'methodParam'); /// scope: continued |
+ expect(r.valueAsString, equals('3')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'methodTemp'); /// scope: continued |
+ expect(r.valueAsString, equals('4')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'outerParam'); /// scope: continued |
+ expect(r.valueAsString, equals('5')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'outerTemp'); /// scope: continued |
+ expect(r.valueAsString, equals('6')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'innerParam'); /// instance: continued |
+ expect(r.valueAsString, equals('7')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'innerTemp'); /// instance: continued |
+ expect(r.valueAsString, equals('8')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'math.sqrt'); /// instance: continued |
+ expect(r.isClosure, isTrue); /// instance: continued |
+ |
+ hitBreakpoint = true; |
+ sub.cancel(); // Do not handle events for the other tests. |
+ isolate.resume(); |
+ } |
+ }); |
+ |
+ var result = await isolate.eval(rootLib, 'new C().method(3);'); |
+ print("Result $result"); |
+ expect(hitBreakpoint, isTrue); |
+} |
+ |
+testMethod2(Isolate isolate) async { |
+ Library rootLib = await isolate.rootLib.load(); |
+ ServiceFunction function = |
+ rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
+ Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
+ print("Breakpoint: $bpt"); |
+ expect(bpt is Breakpoint, isTrue); // I.e, not null. |
+ |
+ bool hitBreakpoint = false; |
+ var sub; |
+ sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
+ print("Event $event"); |
+ if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
+ var frameNumber = 1, r; |
+ r = await isolate.evalFrame(frameNumber, '123'); |
+ expect(r.valueAsString, equals('123')); |
+ r = await isolate.evalFrame(frameNumber, 'this'); |
+ expect(r is DartError, isTrue); |
+ r = await isolate.evalFrame(frameNumber, 'instVar'); |
+ expect(r is DartError, isTrue); |
+ r = await isolate.evalFrame(frameNumber, 'classVar'); |
+ expect(r.valueAsString, equals('2')); |
+ r = await isolate.evalFrame(frameNumber, 'methodParam'); |
+ expect(r.valueAsString, equals('3')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
+ expect(r.valueAsString, equals('4')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'outerParam'); |
+ expect(r.valueAsString, equals('5')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'outerTemp'); |
+ expect(r.valueAsString, equals('6')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'innerParam'); |
+ expect(r.valueAsString, equals('7')); |
+ r = await isolate.evalFrame(frameNumber, 'innerTemp'); |
+ expect(r.valueAsString, equals('8')); |
+ r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
+ expect(r.isClosure, isTrue); |
+ |
+ hitBreakpoint = true; |
+ sub.cancel(); // Do not handle events for the other tests. |
+ isolate.resume(); |
+ } |
+ }); |
+ |
+ var result = await isolate.eval(rootLib, 'C.method2(3);'); |
+ print("Result $result"); |
+ expect(hitBreakpoint, isTrue); |
+} |
+ |
+testMethod3(Isolate isolate) async { |
+ Library rootLib = await isolate.rootLib.load(); |
+ ServiceFunction function = |
+ rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
+ Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
+ print("Breakpoint: $bpt"); |
+ expect(bpt is Breakpoint, isTrue); // I.e, not null. |
+ |
+ bool hitBreakpoint = false; |
+ var sub; |
+ sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
+ print("Event $event"); |
+ if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
+ var frameNumber = 1, r; |
+ r = await isolate.evalFrame(frameNumber, '123'); |
+ expect(r.valueAsString, equals('123')); |
+ r = await isolate.evalFrame(frameNumber, 'this'); |
+ expect(r.clazz.name, equals('C')); |
+ r = await isolate.evalFrame(frameNumber, 'instVar'); |
+ expect(r.valueAsString, equals('1')); |
+ r = await isolate.evalFrame(frameNumber, 'classVar'); |
+ expect(r.valueAsString, equals('2')); |
+ r = await isolate.evalFrame(frameNumber, 'methodParam'); |
+ expect(r.valueAsString, equals('3')); |
+ r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
+ expect(r.valueAsString, equals('4')); |
+ r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
+ expect(r.isClosure, isTrue); |
+ |
+ hitBreakpoint = true; |
+ sub.cancel(); // Do not handle events for the other tests. |
+ isolate.resume(); |
+ } |
+ }); |
+ |
+ var result = await isolate.eval(rootLib, 'new C().method3(3);'); |
+ print("Result $result"); |
+ expect(hitBreakpoint, isTrue); |
+} |
+ |
+ |
+testMethod4(Isolate isolate) async { |
+ Library rootLib = await isolate.rootLib.load(); |
+ ServiceFunction function = |
+ rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
+ Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
+ print("Breakpoint: $bpt"); |
+ expect(bpt is Breakpoint, isTrue); // I.e, not null. |
+ |
+ bool hitBreakpoint = false; |
+ var sub; |
+ sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
+ print("Event $event"); |
+ if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
+ var frameNumber = 1, r; |
+ r = await isolate.evalFrame(frameNumber, '123'); /// instance: continued |
+ expect(r.valueAsString, equals('123')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'this'); /// scope: continued |
+ expect(r.clazz.name, equals('C')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'instVar'); /// instance: continued |
+ expect(r.valueAsString, equals('1')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'classVar'); /// instance: continued |
+ expect(r.valueAsString, equals('2')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'methodParam'); /// scope: continued |
+ expect(r.valueAsString, equals('3')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'methodTemp'); /// scope: continued |
+ expect(r.valueAsString, equals('4')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'outerParam'); /// scope: continued |
+ expect(r.valueAsString, equals('5')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'outerTemp'); /// scope: continued |
+ expect(r.valueAsString, equals('6')); /// scope: continued |
+ r = await isolate.evalFrame(frameNumber, 'innerParam'); /// instance: continued |
+ expect(r.valueAsString, equals('7')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'innerTemp'); /// instance: continued |
+ expect(r.valueAsString, equals('8')); /// instance: continued |
+ r = await isolate.evalFrame(frameNumber, 'math.sqrt'); /// instance: continued |
+ expect(r.isClosure, isTrue); /// instance: continued |
+ |
+ hitBreakpoint = true; |
+ sub.cancel(); // Do not handle events for the other tests. |
+ isolate.resume(); |
+ } |
+ }); |
+ |
+ var result = await isolate.eval(rootLib, |
+ '(){ new C().method4(3); C.closureWithReturnedHome(7); }()'); |
+ print("Result $result"); |
+ expect(hitBreakpoint, isTrue); |
+} |
+ |
+var tests = [ |
+ testMethod, |
+ testMethod2, |
+ testMethod3, |
+ testMethod4, |
+]; |
+ |
+main(args) => runIsolateTests(args, tests); |