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 --complete_timeline | 4 // VMOptions=--error_on_bad_type --error_on_bad_override --complete_timeline |
5 | 5 |
6 import 'dart:developer'; | 6 import 'dart:developer'; |
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 | 9 |
10 import 'test_helper.dart'; | 10 import 'test_helper.dart'; |
11 | 11 |
12 primeTimeline() { | 12 primeTimeline() { |
13 Timeline.startSync('apple'); | 13 Timeline.startSync('apple'); |
| 14 Timeline.instantSync('ISYNC'); |
14 Timeline.finishSync(); | 15 Timeline.finishSync(); |
| 16 TimelineTask task = new TimelineTask(); |
| 17 task.start('TASK1'); |
| 18 task.instant('ITASK'); |
| 19 task.finish(); |
15 } | 20 } |
16 | 21 |
17 List<Map> filterForDartEvents(List<Map> events) { | 22 List<Map> filterForDartEvents(List<Map> events) { |
18 return events.where((event) => event['cat'] == 'Dart').toList(); | 23 return events.where((event) => event['cat'] == 'Dart').toList(); |
19 } | 24 } |
20 | 25 |
| 26 bool eventsContains(List<Map> events, String phase, String name) { |
| 27 for (Map event in events) { |
| 28 if ((event['ph'] == phase) && (event['name'] == name)) { |
| 29 return true; |
| 30 } |
| 31 } |
| 32 return false; |
| 33 } |
| 34 |
21 var tests = [ | 35 var tests = [ |
22 (VM vm) async { | 36 (VM vm) async { |
23 Map result = await vm.invokeRpcNoUpgrade('_getVMTimeline', {}); | 37 Map result = await vm.invokeRpcNoUpgrade('_getVMTimeline', {}); |
24 expect(result['type'], equals('_Timeline')); | 38 expect(result['type'], equals('_Timeline')); |
25 expect(result['traceEvents'], new isInstanceOf<List>()); | 39 expect(result['traceEvents'], new isInstanceOf<List>()); |
26 List<Map> dartEvents = filterForDartEvents(result['traceEvents']); | 40 List<Map> dartEvents = filterForDartEvents(result['traceEvents']); |
27 expect(dartEvents.length, equals(1)); | 41 expect(dartEvents.length, equals(5)); |
28 Map dartEvent = dartEvents[0]; | 42 expect(eventsContains(dartEvents, 'I', 'ISYNC'), isTrue); |
29 expect(dartEvent['name'], equals('apple')); | 43 expect(eventsContains(dartEvents, 'X', 'apple'), isTrue); |
| 44 expect(eventsContains(dartEvents, 'b', 'TASK1'), isTrue); |
| 45 expect(eventsContains(dartEvents, 'e', 'TASK1'), isTrue); |
| 46 expect(eventsContains(dartEvents, 'n', 'ITASK'), isTrue); |
| 47 expect(eventsContains(dartEvents, 'q', 'ITASK'), isFalse); |
30 }, | 48 }, |
31 ]; | 49 ]; |
32 | 50 |
33 main(args) async => runVMTests(args, tests, testeeBefore: primeTimeline); | 51 main(args) async => runVMTests(args, tests, testeeBefore: primeTimeline); |
OLD | NEW |