OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 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 | 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 // VMOptions=--error_on_bad_type --error_on_bad_override --verbose-debug | 4 // VMOptions=--error_on_bad_type --error_on_bad_override --verbose-debug |
5 | 5 |
6 import 'package:observatory/service_io.dart'; | 6 import 'package:observatory/service_io.dart'; |
7 import 'package:unittest/unittest.dart'; | 7 import 'package:unittest/unittest.dart'; |
8 import 'test_helper.dart'; | 8 import 'test_helper.dart'; |
9 | 9 |
10 printSync() { | 10 printSync() { // Line 10 |
11 print('sync'); // Line 11 | 11 print('sync'); |
12 } | 12 } |
13 | 13 printAsync() async { // Line 13 |
14 printAsync() async { | 14 print('async'); |
15 print('async'); // Line 15 | |
16 } | 15 } |
17 | 16 printAsyncStar() async* { // Line 16 |
18 printAsyncStar() async* { | 17 print('async*'); |
19 print('async*'); // Line 19 | |
20 } | 18 } |
21 | 19 printSyncStar() sync* { // Line 19 |
22 printSyncStar() sync* { | 20 print('sync*'); |
23 print('sync*'); // Line 23 | |
24 } | 21 } |
25 | 22 |
26 var testerReady = false; | 23 var testerReady = false; |
27 testeeDo() { | 24 testeeDo() { |
28 // We block here rather than allowing the isolate to enter the | 25 // We block here rather than allowing the isolate to enter the |
29 // paused-on-exit state before the tester gets a chance to set | 26 // paused-on-exit state before the tester gets a chance to set |
30 // the breakpoints because we need the event loop to remain | 27 // the breakpoints because we need the event loop to remain |
31 // operational for the async bodies to run. | 28 // operational for the async bodies to run. |
32 print('testee waiting'); | 29 print('testee waiting'); |
33 while (!testerReady); | 30 while(!testerReady); |
34 | 31 |
35 printSync(); | 32 printSync(); |
36 var future = printAsync(); | 33 var future = printAsync(); |
37 var stream = printAsyncStar(); | 34 var stream = printAsyncStar(); |
38 var iterator = printSyncStar(); | 35 var iterator = printSyncStar(); |
39 | 36 |
40 print('middle'); // Line 40 | 37 print('middle'); // Line 37. |
41 | 38 |
42 future.then((v) => print(v)); | 39 future.then((v) => print(v)); |
43 stream.toList(); | 40 stream.toList(); |
44 iterator.toList(); | 41 iterator.toList(); |
45 } | 42 } |
46 | 43 |
47 testAsync(Isolate isolate) async { | 44 testAsync(Isolate isolate) async { |
48 await isolate.rootLibrary.load(); | 45 await isolate.rootLibrary.load(); |
49 var script = isolate.rootLibrary.scripts[0]; | 46 var script = isolate.rootLibrary.scripts[0]; |
50 | 47 |
51 var bp1 = await isolate.addBreakpoint(script, 11); | 48 var bp1 = await isolate.addBreakpoint(script, 10); |
52 expect(bp1, isNotNull); | 49 expect(bp1, isNotNull); |
53 expect(bp1 is Breakpoint, isTrue); | 50 expect(bp1 is Breakpoint, isTrue); |
54 var bp2 = await isolate.addBreakpoint(script, 15); | 51 var bp2 = await isolate.addBreakpoint(script, 13); |
55 expect(bp2, isNotNull); | 52 expect(bp2, isNotNull); |
56 expect(bp2 is Breakpoint, isTrue); | 53 expect(bp2 is Breakpoint, isTrue); |
57 var bp3 = await isolate.addBreakpoint(script, 19); | 54 var bp3 = await isolate.addBreakpoint(script, 16); |
58 expect(bp3, isNotNull); | 55 expect(bp3, isNotNull); |
59 expect(bp3 is Breakpoint, isTrue); | 56 expect(bp3 is Breakpoint, isTrue); |
60 var bp4 = await isolate.addBreakpoint(script, 23); | 57 var bp4 = await isolate.addBreakpoint(script, 19); |
61 expect(bp4, isNotNull); | 58 expect(bp4, isNotNull); |
62 expect(bp4 is Breakpoint, isTrue); | 59 expect(bp4 is Breakpoint, isTrue); |
63 var bp5 = await isolate.addBreakpoint(script, 40); | 60 var bp5 = await isolate.addBreakpoint(script, 37); |
64 print("BP5 - $bp5"); | 61 print("BP5 - $bp5"); |
65 expect(bp5, isNotNull); | 62 expect(bp5, isNotNull); |
66 expect(bp5 is Breakpoint, isTrue); | 63 expect(bp5 is Breakpoint, isTrue); |
67 | 64 |
68 var hits = []; | 65 var hits = []; |
69 | 66 |
70 isolate.rootLibrary.evaluate('testerReady = true;').then((Instance result) { | 67 isolate.rootLibrary.evaluate('testerReady = true;') |
71 expect(result.valueAsString, equals('true')); | 68 .then((Instance result) { |
72 }); | 69 expect(result.valueAsString, equals('true')); |
| 70 }); |
73 | 71 |
74 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | 72 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
75 await for (ServiceEvent event in stream) { | 73 await for (ServiceEvent event in stream) { |
76 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 74 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
77 var bp = event.breakpoint; | 75 var bp = event.breakpoint; |
78 print('Hit $bp'); | 76 print('Hit $bp'); |
79 hits.add(bp); | 77 hits.add(bp); |
80 await isolate.resume(); | 78 await isolate.resume(); |
81 | 79 |
82 if (hits.length == 5) break; | 80 if (hits.length == 5) break; |
83 } | 81 } |
84 } | 82 } |
85 | 83 |
86 expect(hits, equals([bp1, bp5, bp4, bp2, bp3])); | 84 expect(hits, equals([bp1, bp5, bp4, bp2, bp3])); |
87 } | 85 } |
88 | 86 |
89 var tests = [testAsync]; | 87 var tests = [testAsync]; |
90 | 88 |
91 main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeDo); | 89 main(args) => runIsolateTests(args, tests, testeeConcurrent: testeeDo); |
OLD | NEW |