OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 // VMOptions=--compile-all --error_on_bad_type --error_on_bad_override |
| 5 |
| 6 import 'package:observatory/service_io.dart'; |
| 7 import 'package:unittest/unittest.dart'; |
| 8 import 'test_helper.dart'; |
| 9 import 'dart:async'; |
| 10 |
| 11 import 'dart:math' as math; |
| 12 |
| 13 breakHere() {} |
| 14 |
| 15 class C { |
| 16 var instVar = 1; |
| 17 static var classVar = 2; |
| 18 |
| 19 method(methodParam) { |
| 20 var methodTemp = 4; |
| 21 [5].forEach((outerParam) { |
| 22 var outerTemp = 6; |
| 23 [7].forEach((innerParam) { |
| 24 var innerTemp = 8; |
| 25 breakHere(); |
| 26 }); |
| 27 }); |
| 28 } |
| 29 |
| 30 static method2(methodParam) { |
| 31 var methodTemp = 4; |
| 32 [5].forEach((outerParam) { |
| 33 var outerTemp = 6; |
| 34 [7].forEach((innerParam) { |
| 35 var innerTemp = 8; |
| 36 breakHere(); |
| 37 }); |
| 38 }); |
| 39 } |
| 40 |
| 41 method3(methodParam) { |
| 42 var methodTemp = 4; |
| 43 breakHere(); |
| 44 } |
| 45 |
| 46 static var closureWithReturnedHome; |
| 47 method4(methodParam) { |
| 48 var methodTemp = 4; |
| 49 [5].forEach((outerParam) { |
| 50 var outerTemp = 6; |
| 51 closureWithReturnedHome = (innerParam) { |
| 52 var innerTemp = 8; |
| 53 breakHere(); |
| 54 }; |
| 55 }); |
| 56 } |
| 57 } |
| 58 |
| 59 testMethod(Isolate isolate) async { |
| 60 Library rootLib = await isolate.rootLib.load(); |
| 61 ServiceFunction function = |
| 62 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
| 63 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
| 64 print("Breakpoint: $bpt"); |
| 65 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
| 66 |
| 67 bool hitBreakpoint = false; |
| 68 var sub; |
| 69 sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
| 70 print("Event $event"); |
| 71 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
| 72 var frameNumber = 1, r; |
| 73 r = await isolate.evalFrame(frameNumber, '123'); /// instance: ok |
| 74 expect(r.valueAsString, equals('123')); /// instance: continued |
| 75 r = await isolate.evalFrame(frameNumber, 'this'); /// scope: ok |
| 76 expect(r.clazz.name, equals('C')); /// scope: continued |
| 77 r = await isolate.evalFrame(frameNumber, 'instVar'); /// instance: contin
ued |
| 78 expect(r.valueAsString, equals('1')); /// instance: continued |
| 79 r = await isolate.evalFrame(frameNumber, 'classVar'); /// instance: contin
ued |
| 80 expect(r.valueAsString, equals('2')); /// instance: continued |
| 81 r = await isolate.evalFrame(frameNumber, 'methodParam'); /// scope: conti
nued |
| 82 expect(r.valueAsString, equals('3')); /// scope: continued |
| 83 r = await isolate.evalFrame(frameNumber, 'methodTemp'); /// scope: contin
ued |
| 84 expect(r.valueAsString, equals('4')); /// scope: continued |
| 85 r = await isolate.evalFrame(frameNumber, 'outerParam'); /// scope: contin
ued |
| 86 expect(r.valueAsString, equals('5')); /// scope: continued |
| 87 r = await isolate.evalFrame(frameNumber, 'outerTemp'); /// scope: continu
ed |
| 88 expect(r.valueAsString, equals('6')); /// scope: continued |
| 89 r = await isolate.evalFrame(frameNumber, 'innerParam'); /// instance: con
tinued |
| 90 expect(r.valueAsString, equals('7')); /// instance: continued |
| 91 r = await isolate.evalFrame(frameNumber, 'innerTemp'); /// instance: cont
inued |
| 92 expect(r.valueAsString, equals('8')); /// instance: continued |
| 93 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); /// instance: cont
inued |
| 94 expect(r.isClosure, isTrue); /// instance: continued |
| 95 |
| 96 hitBreakpoint = true; |
| 97 sub.cancel(); // Do not handle events for the other tests. |
| 98 isolate.resume(); |
| 99 } |
| 100 }); |
| 101 |
| 102 var result = await isolate.eval(rootLib, 'new C().method(3);'); |
| 103 print("Result $result"); |
| 104 expect(hitBreakpoint, isTrue); |
| 105 } |
| 106 |
| 107 testMethod2(Isolate isolate) async { |
| 108 Library rootLib = await isolate.rootLib.load(); |
| 109 ServiceFunction function = |
| 110 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
| 111 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
| 112 print("Breakpoint: $bpt"); |
| 113 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
| 114 |
| 115 bool hitBreakpoint = false; |
| 116 var sub; |
| 117 sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
| 118 print("Event $event"); |
| 119 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
| 120 var frameNumber = 1, r; |
| 121 r = await isolate.evalFrame(frameNumber, '123'); |
| 122 expect(r.valueAsString, equals('123')); |
| 123 r = await isolate.evalFrame(frameNumber, 'this'); |
| 124 expect(r is DartError, isTrue); |
| 125 r = await isolate.evalFrame(frameNumber, 'instVar'); |
| 126 expect(r is DartError, isTrue); |
| 127 r = await isolate.evalFrame(frameNumber, 'classVar'); |
| 128 expect(r.valueAsString, equals('2')); |
| 129 r = await isolate.evalFrame(frameNumber, 'methodParam'); |
| 130 expect(r.valueAsString, equals('3')); /// scope: continued |
| 131 r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
| 132 expect(r.valueAsString, equals('4')); /// scope: continued |
| 133 r = await isolate.evalFrame(frameNumber, 'outerParam'); |
| 134 expect(r.valueAsString, equals('5')); /// scope: continued |
| 135 r = await isolate.evalFrame(frameNumber, 'outerTemp'); |
| 136 expect(r.valueAsString, equals('6')); /// scope: continued |
| 137 r = await isolate.evalFrame(frameNumber, 'innerParam'); |
| 138 expect(r.valueAsString, equals('7')); |
| 139 r = await isolate.evalFrame(frameNumber, 'innerTemp'); |
| 140 expect(r.valueAsString, equals('8')); |
| 141 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
| 142 expect(r.isClosure, isTrue); |
| 143 |
| 144 hitBreakpoint = true; |
| 145 sub.cancel(); // Do not handle events for the other tests. |
| 146 isolate.resume(); |
| 147 } |
| 148 }); |
| 149 |
| 150 var result = await isolate.eval(rootLib, 'C.method2(3);'); |
| 151 print("Result $result"); |
| 152 expect(hitBreakpoint, isTrue); |
| 153 } |
| 154 |
| 155 testMethod3(Isolate isolate) async { |
| 156 Library rootLib = await isolate.rootLib.load(); |
| 157 ServiceFunction function = |
| 158 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
| 159 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
| 160 print("Breakpoint: $bpt"); |
| 161 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
| 162 |
| 163 bool hitBreakpoint = false; |
| 164 var sub; |
| 165 sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
| 166 print("Event $event"); |
| 167 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
| 168 var frameNumber = 1, r; |
| 169 r = await isolate.evalFrame(frameNumber, '123'); |
| 170 expect(r.valueAsString, equals('123')); |
| 171 r = await isolate.evalFrame(frameNumber, 'this'); |
| 172 expect(r.clazz.name, equals('C')); |
| 173 r = await isolate.evalFrame(frameNumber, 'instVar'); |
| 174 expect(r.valueAsString, equals('1')); |
| 175 r = await isolate.evalFrame(frameNumber, 'classVar'); |
| 176 expect(r.valueAsString, equals('2')); |
| 177 r = await isolate.evalFrame(frameNumber, 'methodParam'); |
| 178 expect(r.valueAsString, equals('3')); |
| 179 r = await isolate.evalFrame(frameNumber, 'methodTemp'); |
| 180 expect(r.valueAsString, equals('4')); |
| 181 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); |
| 182 expect(r.isClosure, isTrue); |
| 183 |
| 184 hitBreakpoint = true; |
| 185 sub.cancel(); // Do not handle events for the other tests. |
| 186 isolate.resume(); |
| 187 } |
| 188 }); |
| 189 |
| 190 var result = await isolate.eval(rootLib, 'new C().method3(3);'); |
| 191 print("Result $result"); |
| 192 expect(hitBreakpoint, isTrue); |
| 193 } |
| 194 |
| 195 |
| 196 testMethod4(Isolate isolate) async { |
| 197 Library rootLib = await isolate.rootLib.load(); |
| 198 ServiceFunction function = |
| 199 rootLib.functions.singleWhere((f) => f.name == 'breakHere'); |
| 200 Breakpoint bpt = await isolate.addBreakpointAtEntry(function); |
| 201 print("Breakpoint: $bpt"); |
| 202 expect(bpt is Breakpoint, isTrue); // I.e, not null. |
| 203 |
| 204 bool hitBreakpoint = false; |
| 205 var sub; |
| 206 sub = isolate.vm.events.stream.listen((ServiceEvent event) async { |
| 207 print("Event $event"); |
| 208 if (event.eventType == ServiceEvent.kPauseBreakpoint) { |
| 209 var frameNumber = 1, r; |
| 210 r = await isolate.evalFrame(frameNumber, '123'); /// instance: continued |
| 211 expect(r.valueAsString, equals('123')); /// instance: continued |
| 212 r = await isolate.evalFrame(frameNumber, 'this'); /// scope: continued |
| 213 expect(r.clazz.name, equals('C')); /// scope: continued |
| 214 r = await isolate.evalFrame(frameNumber, 'instVar'); /// instance: contin
ued |
| 215 expect(r.valueAsString, equals('1')); /// instance: continued |
| 216 r = await isolate.evalFrame(frameNumber, 'classVar'); /// instance: conti
nued |
| 217 expect(r.valueAsString, equals('2')); /// instance: continued |
| 218 r = await isolate.evalFrame(frameNumber, 'methodParam'); /// scope: conti
nued |
| 219 expect(r.valueAsString, equals('3')); /// scope: continued |
| 220 r = await isolate.evalFrame(frameNumber, 'methodTemp'); /// scope: contin
ued |
| 221 expect(r.valueAsString, equals('4')); /// scope: continued |
| 222 r = await isolate.evalFrame(frameNumber, 'outerParam'); /// scope: contin
ued |
| 223 expect(r.valueAsString, equals('5')); /// scope: continued |
| 224 r = await isolate.evalFrame(frameNumber, 'outerTemp'); /// scope: continu
ed |
| 225 expect(r.valueAsString, equals('6')); /// scope: continued |
| 226 r = await isolate.evalFrame(frameNumber, 'innerParam'); /// instance: con
tinued |
| 227 expect(r.valueAsString, equals('7')); /// instance: continued |
| 228 r = await isolate.evalFrame(frameNumber, 'innerTemp'); /// instance: cont
inued |
| 229 expect(r.valueAsString, equals('8')); /// instance: continued |
| 230 r = await isolate.evalFrame(frameNumber, 'math.sqrt'); /// instance: cont
inued |
| 231 expect(r.isClosure, isTrue); /// instance: continued |
| 232 |
| 233 hitBreakpoint = true; |
| 234 sub.cancel(); // Do not handle events for the other tests. |
| 235 isolate.resume(); |
| 236 } |
| 237 }); |
| 238 |
| 239 var result = await isolate.eval(rootLib, |
| 240 '(){ new C().method4(3); C.closureWithReturnedHome(7); }()'); |
| 241 print("Result $result"); |
| 242 expect(hitBreakpoint, isTrue); |
| 243 } |
| 244 |
| 245 var tests = [ |
| 246 testMethod, |
| 247 testMethod2, |
| 248 testMethod3, |
| 249 testMethod4, |
| 250 ]; |
| 251 |
| 252 main(args) => runIsolateTests(args, tests); |
OLD | NEW |