OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, 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 | |
5 import 'dart:async'; | |
6 import 'package:observatory/object_graph.dart'; | |
7 import 'package:observatory/service_io.dart'; | |
8 import 'package:unittest/unittest.dart'; | |
9 import 'test_helper.dart'; | |
10 | |
11 class Foo { | |
12 Object left; | |
13 Object right; | |
14 } | |
15 Foo r; | |
16 | |
17 List lst; | |
18 | |
19 void script() { | |
20 // Create 3 instances of Foo, with out-degrees | |
21 // 0 (for b), 1 (for a), and 2 (for staticFoo). | |
22 r = new Foo(); | |
23 var a = new Foo(); | |
24 var b = new Foo(); | |
25 r.left = a; | |
26 r.right = b; | |
27 a.left = b; | |
28 | |
29 lst = new List(2); | |
30 lst[0] = lst; // Self-loop. | |
31 // Larger than any other fixed-size list in a fresh heap. | |
32 lst[1] = new List(123456); | |
33 } | |
34 | |
35 int fooId; | |
36 | |
37 var tests = [ | |
38 | |
39 (Isolate isolate) { | |
40 Completer completer = new Completer(); | |
41 isolate.vm.events.stream.listen((ServiceEvent event) { | |
42 if (event.eventType == '_Graph') { | |
43 ReadStream reader = new ReadStream(event.data); | |
44 ObjectGraph graph = new ObjectGraph(reader); | |
45 expect(fooId, isNotNull); | |
46 Iterable<ObjectVertex> foos = graph.vertices.where( | |
47 (ObjectVertex obj) => obj.classId == fooId); | |
48 expect(foos.length, equals(3)); | |
49 expect(foos.where( | |
50 (ObjectVertex obj) => obj.succ.length == 0).length, equals(1)); | |
51 expect(foos.where( | |
52 (ObjectVertex obj) => obj.succ.length == 1).length, equals(1)); | |
53 expect(foos.where( | |
54 (ObjectVertex obj) => obj.succ.length == 2).length, equals(1)); | |
55 | |
56 ObjectVertex bVertex = foos.where( | |
57 (ObjectVertex obj) => obj.succ.length == 0).first; | |
58 ObjectVertex aVertex = foos.where( | |
59 (ObjectVertex obj) => obj.succ.length == 1).first; | |
60 ObjectVertex rVertex = foos.where( | |
61 (ObjectVertex obj) => obj.succ.length == 2).first; | |
62 | |
63 // TODO(koda): Check actual byte sizes. | |
64 | |
65 expect(aVertex.retainedSize, equals(aVertex.shallowSize)); | |
66 expect(bVertex.retainedSize, equals(bVertex.shallowSize)); | |
67 expect(rVertex.retainedSize, equals(aVertex.shallowSize + | |
68 bVertex.shallowSize + | |
69 rVertex.shallowSize)); | |
70 | |
71 const int fixedSizeListCid = 62; | |
72 List<ObjectVertex> lists = new List.from(graph.vertices.where( | |
73 (ObjectVertex obj) => obj.classId == fixedSizeListCid)); | |
74 expect(lists.length >= 2, isTrue); | |
75 // Order by decreasing retained size. | |
76 lists.sort((u, v) => v.retainedSize - u.retainedSize); | |
77 ObjectVertex first = lists[0]; | |
78 ObjectVertex second = lists[1]; | |
79 // Check that the short list retains more than the long list inside. | |
80 expect(first.succ.length, equals(2 + second.succ.length)); | |
81 // ... and specifically, that it retains exactly itself + the long one. | |
82 expect(first.retainedSize, | |
83 equals(first.shallowSize + second.shallowSize)); | |
84 completer.complete(); | |
85 } | |
86 }); | |
87 return isolate.rootLib.load().then((Library lib) { | |
88 expect(lib.classes.length, equals(1)); | |
89 Class fooClass = lib.classes.first; | |
90 fooId = fooClass.vmCid; | |
91 isolate.get('graph'); | |
92 return completer.future; | |
93 }); | |
94 }, | |
95 | |
96 ]; | |
97 | |
98 main(args) => runIsolateTests(args, tests, testeeBefore: script); | |
OLD | NEW |