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/heap_snapshot.dart'; | 6 import 'package:observatory/heap_snapshot.dart'; |
7 import 'package:observatory/models.dart' as M; | 7 import 'package:observatory/models.dart' as M; |
8 import 'package:observatory/service_io.dart'; | 8 import 'package:observatory/service_io.dart'; |
9 import 'package:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
10 import 'test_helper.dart'; | 10 import 'test_helper.dart'; |
11 | 11 |
12 // small example from [Lenguaer & Tarjan 1979] | 12 // small example from [Lenguaer & Tarjan 1979] |
13 class R { | 13 class R { var x; var y; var z; } |
14 var x; | 14 class A { var x; } |
15 var y; | 15 class B { var x; var y; var z; } |
16 var z; | 16 class C { var x; var y; } |
17 } | 17 class D { var x; } |
18 | 18 class E { var x; } |
19 class A { | 19 class F { var x; } |
20 var x; | 20 class G { var x; var y; } |
21 } | 21 class H { var x; var y; } |
22 | 22 class I { var x; } |
23 class B { | 23 class J { var x; } |
24 var x; | 24 class K { var x; var y; } |
25 var y; | 25 class L { var x; } |
26 var z; | |
27 } | |
28 | |
29 class C { | |
30 var x; | |
31 var y; | |
32 } | |
33 | |
34 class D { | |
35 var x; | |
36 } | |
37 | |
38 class E { | |
39 var x; | |
40 } | |
41 | |
42 class F { | |
43 var x; | |
44 } | |
45 | |
46 class G { | |
47 var x; | |
48 var y; | |
49 } | |
50 | |
51 class H { | |
52 var x; | |
53 var y; | |
54 } | |
55 | |
56 class I { | |
57 var x; | |
58 } | |
59 | |
60 class J { | |
61 var x; | |
62 } | |
63 | |
64 class K { | |
65 var x; | |
66 var y; | |
67 } | |
68 | |
69 class L { | |
70 var x; | |
71 } | |
72 | 26 |
73 var r; | 27 var r; |
74 | 28 |
75 buildGraph() { | 29 buildGraph() { |
76 r = new R(); | 30 r = new R(); |
77 var a = new A(); | 31 var a = new A(); |
78 var b = new B(); | 32 var b = new B(); |
79 var c = new C(); | 33 var c = new C(); |
80 var d = new D(); | 34 var d = new D(); |
81 var e = new E(); | 35 var e = new E(); |
82 var f = new F(); | 36 var f = new F(); |
83 var g = new G(); | 37 var g = new G(); |
84 var h = new H(); | 38 var h = new H(); |
85 var i = new I(); | 39 var i = new I(); |
86 var j = new J(); | 40 var j = new J(); |
87 var k = new K(); | 41 var k = new K(); |
88 var l = new L(); | 42 var l = new L(); |
89 | 43 |
90 r.x = a; | 44 r.x = a; r.y = b; r.z = c; |
91 r.y = b; | |
92 r.z = c; | |
93 a.x = d; | 45 a.x = d; |
94 b.x = a; | 46 b.x = a; b.y = d; b.z = e; |
95 b.y = d; | 47 c.x = f; c.y = g; |
96 b.z = e; | |
97 c.x = f; | |
98 c.y = g; | |
99 d.x = l; | 48 d.x = l; |
100 e.x = h; | 49 e.x = h; |
101 f.x = i; | 50 f.x = i; |
102 g.x = i; | 51 g.x = i; g.y = j; |
103 g.y = j; | 52 h.x = e; h.y = k; |
104 h.x = e; | |
105 h.y = k; | |
106 i.x = k; | 53 i.x = k; |
107 j.x = i; | 54 j.x = i; |
108 k.x = i; | 55 k.x = i; k.y = r; |
109 k.y = r; | |
110 l.x = h; | 56 l.x = h; |
111 } | 57 } |
112 | 58 |
113 var tests = [ | 59 var tests = [ |
114 (Isolate isolate) async { | 60 (Isolate isolate) async { |
115 final rootLib = await isolate.rootLibrary.load(); | 61 final rootLib = await isolate.rootLibrary.load(); |
116 final raw = | 62 final raw = |
117 await isolate.fetchHeapSnapshot(M.HeapSnapshotRoots.user, false).last; | 63 await isolate.fetchHeapSnapshot(M.HeapSnapshotRoots.user, false).last; |
118 final snapshot = new HeapSnapshot(); | 64 final snapshot = new HeapSnapshot(); |
119 await snapshot.loadProgress(isolate, raw).last; | 65 await snapshot.loadProgress(isolate, raw).last; |
120 | 66 |
121 node(String className) { | 67 node(String className) { |
122 var cls = rootLib.classes.singleWhere((cls) => cls.name == className); | 68 var cls = rootLib.classes.singleWhere((cls) => cls.name == className); |
123 return snapshot.graph.vertices.singleWhere((v) => v.vmCid == cls.vmCid); | 69 return snapshot.graph.vertices.singleWhere((v) => v.vmCid == cls.vmCid); |
124 } | 70 } |
125 | 71 |
126 expect(node('I').dominator, equals(node('R'))); | 72 expect(node('I').dominator, equals(node('R'))); |
127 expect(node('K').dominator, equals(node('R'))); | 73 expect(node('K').dominator, equals(node('R'))); |
128 expect(node('C').dominator, equals(node('R'))); | 74 expect(node('C').dominator, equals(node('R'))); |
129 expect(node('H').dominator, equals(node('R'))); | 75 expect(node('H').dominator, equals(node('R'))); |
130 expect(node('E').dominator, equals(node('R'))); | 76 expect(node('E').dominator, equals(node('R'))); |
131 expect(node('A').dominator, equals(node('R'))); | 77 expect(node('A').dominator, equals(node('R'))); |
132 expect(node('D').dominator, equals(node('R'))); | 78 expect(node('D').dominator, equals(node('R'))); |
133 expect(node('B').dominator, equals(node('R'))); | 79 expect(node('B').dominator, equals(node('R'))); |
134 | 80 |
135 expect(node('F').dominator, equals(node('C'))); | 81 expect(node('F').dominator, equals(node('C'))); |
136 expect(node('G').dominator, equals(node('C'))); | 82 expect(node('G').dominator, equals(node('C'))); |
137 expect(node('J').dominator, equals(node('G'))); | 83 expect(node('J').dominator, equals(node('G'))); |
138 expect(node('L').dominator, equals(node('D'))); | 84 expect(node('L').dominator, equals(node('D'))); |
139 | 85 |
140 expect(node('R'), isNotNull); // The field. | 86 expect(node('R'), isNotNull); // The field. |
141 }, | 87 }, |
142 ]; | 88 ]; |
143 | 89 |
144 main(args) => runIsolateTests(args, tests, testeeBefore: buildGraph); | 90 main(args) => runIsolateTests(args, tests, testeeBefore: buildGraph); |
OLD | NEW |