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 | 4 // VMOptions=--error_on_bad_type --error_on_bad_override |
5 | 5 |
6 import 'package:observatory/models.dart' as M; | 6 import 'package:observatory/models.dart' as M; |
7 import 'package:observatory/service_io.dart'; | 7 import 'package:observatory/service_io.dart'; |
8 import 'package:unittest/unittest.dart'; | 8 import 'package:unittest/unittest.dart'; |
9 import 'test_helper.dart'; | 9 import 'test_helper.dart'; |
10 import 'dart:async'; | 10 import 'dart:async'; |
11 | 11 |
12 void testMain() { | 12 void testMain() { |
13 print('Hello'); | 13 print('Hello'); |
14 } | 14 } |
15 | 15 |
16 var tests = [ | 16 var tests = [ |
17 (Isolate isolate) async { | |
18 print('Getting stream...'); | |
19 Completer completer = new Completer(); | |
20 var stream = await isolate.vm.getEventStream(VM.kDebugStream); | |
21 print('Subscribing...'); | |
22 var subscription; | |
23 subscription = stream.listen((ServiceEvent event) { | |
24 if (event.kind == ServiceEvent.kPauseStart) { | |
25 print('Received $event'); | |
26 subscription.cancel(); | |
27 completer.complete(); | |
28 } else { | |
29 print('Ignoring event $event'); | |
30 } | |
31 }); | |
32 print('Subscribed. Pause event is ${isolate.pauseEvent}'); | |
33 | 17 |
34 if (isolate.pauseEvent != null && isolate.pauseEvent is M.PauseStartEvent) { | 18 (Isolate isolate) async { |
35 // Wait for the isolate to hit PauseStart. | 19 print('Getting stream...'); |
| 20 Completer completer = new Completer(); |
| 21 var stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 22 print('Subscribing...'); |
| 23 var subscription; |
| 24 subscription = stream.listen((ServiceEvent event) { |
| 25 if (event.kind == ServiceEvent.kPauseStart) { |
| 26 print('Received $event'); |
36 subscription.cancel(); | 27 subscription.cancel(); |
37 print('Subscription cancelled.'); | 28 completer.complete(); |
38 } else { | 29 } else { |
39 print('Waiting for pause start event.'); | 30 print('Ignoring event $event'); |
40 await completer.future; | |
41 } | 31 } |
42 print('Done waiting for pause event.'); | 32 }); |
| 33 print('Subscribed. Pause event is ${isolate.pauseEvent}'); |
43 | 34 |
44 // Grab the timestamp. | 35 if (isolate.pauseEvent != null && |
45 var pausetime1 = isolate.pauseEvent.timestamp; | 36 isolate.pauseEvent is M.PauseStartEvent) { |
46 expect(pausetime1, isNotNull); | 37 // Wait for the isolate to hit PauseStart. |
47 // Reload the isolate. | 38 subscription.cancel(); |
48 await isolate.reload(); | 39 print('Subscription cancelled.'); |
49 // Verify that it is the same. | 40 } else { |
50 expect(pausetime1.millisecondsSinceEpoch, | 41 print('Waiting for pause start event.'); |
51 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); | 42 await completer.future; |
| 43 } |
| 44 print('Done waiting for pause event.'); |
52 | 45 |
53 completer = new Completer(); | 46 // Grab the timestamp. |
54 stream = await isolate.vm.getEventStream(VM.kDebugStream); | 47 var pausetime1 = isolate.pauseEvent.timestamp; |
55 subscription = stream.listen((ServiceEvent event) { | 48 expect(pausetime1, isNotNull); |
56 if (event.kind == ServiceEvent.kPauseBreakpoint) { | 49 // Reload the isolate. |
57 print('Received PauseBreakpoint'); | 50 await isolate.reload(); |
58 subscription.cancel(); | 51 // Verify that it is the same. |
59 completer.complete(); | 52 expect(pausetime1.millisecondsSinceEpoch, |
60 } | 53 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); |
61 print('Got ${event.kind}'); | |
62 }); | |
63 | 54 |
64 print('Stepping...'); | 55 completer = new Completer(); |
65 isolate.stepInto(); | 56 stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 57 subscription = stream.listen((ServiceEvent event) { |
| 58 if (event.kind == ServiceEvent.kPauseBreakpoint) { |
| 59 print('Received PauseBreakpoint'); |
| 60 subscription.cancel(); |
| 61 completer.complete(); |
| 62 } |
| 63 print('Got ${event.kind}'); |
| 64 }); |
66 | 65 |
67 // Wait for the isolate to hit PauseBreakpoint. | 66 print('Stepping...'); |
68 print('Waiting for PauseBreakpoint'); | 67 isolate.stepInto(); |
69 await completer.future; | |
70 | 68 |
71 // Grab the timestamp. | 69 // Wait for the isolate to hit PauseBreakpoint. |
72 var pausetime2 = isolate.pauseEvent.timestamp; | 70 print('Waiting for PauseBreakpoint'); |
73 expect(pausetime2, isNotNull); | 71 await completer.future; |
74 // Reload the isolate. | |
75 await isolate.reload(); | |
76 // Verify that it is the same. | |
77 expect(pausetime2.millisecondsSinceEpoch, | |
78 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); | |
79 | 72 |
80 expect(pausetime2.millisecondsSinceEpoch, | 73 // Grab the timestamp. |
| 74 var pausetime2 = isolate.pauseEvent.timestamp; |
| 75 expect(pausetime2, isNotNull); |
| 76 // Reload the isolate. |
| 77 await isolate.reload(); |
| 78 // Verify that it is the same. |
| 79 expect(pausetime2.millisecondsSinceEpoch, |
| 80 equals(isolate.pauseEvent.timestamp.millisecondsSinceEpoch)); |
| 81 |
| 82 expect(pausetime2.millisecondsSinceEpoch, |
81 greaterThan(pausetime1.millisecondsSinceEpoch)); | 83 greaterThan(pausetime1.millisecondsSinceEpoch)); |
82 }, | 84 }, |
| 85 |
83 ]; | 86 ]; |
84 | 87 |
85 main(args) => runIsolateTests(args, tests, | 88 main(args) => runIsolateTests(args, tests, |
86 testeeConcurrent: testMain, | 89 testeeConcurrent: testMain, |
87 pause_on_start: true, | 90 pause_on_start: true, |
88 pause_on_exit: true, | 91 pause_on_exit: true, |
89 verbose_vm: true, | 92 verbose_vm: true, |
90 extraArgs: ['--trace-service', '--trace-service-verbose']); | 93 extraArgs: [ '--trace-service', |
| 94 '--trace-service-verbose' ]); |
OLD | NEW |