blob: 48e93e3227a8e82961cfe8631e2618ba05e4c0d4 [file] [log] [blame]
Chris Craikb2cbf152015-07-28 16:26:29 -07001<!DOCTYPE html>
2<!--
3Copyright (c) 2015 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/core/test_utils.html">
9<link rel="import" href="/model/selection_state.html">
10<link rel="import" href="/ui/tracks/memory_dump_track_test_utils.html">
11<link rel="import" href="/ui/tracks/memory_dump_track_util.html">
12
13<script>
14'use strict';
15
16tr.b.unittest.testSuite(function() {
17 var SelectionState = tr.model.SelectionState;
18 var createTestGlobalMemoryDumps = tr.ui.tracks.createTestGlobalMemoryDumps;
19 var createTestProcessMemoryDumps = tr.ui.tracks.createTestProcessMemoryDumps;
20
21 test('buildMemoryLetterDots_withoutVMRegions', function() {
22 var dumps = createTestGlobalMemoryDumps(false, false);
23 var items = tr.ui.tracks.buildMemoryLetterDots(dumps);
24
25 assert.lengthOf(items, 4);
26 assert.equal(items[0].start, 0);
27 assert.equal(items[1].start, 5);
28 assert.equal(items[2].start, 15);
29 assert.equal(items[3].start, 18);
30
31 // Check model mapping.
32 assert.equal(items[1].selectionState, SelectionState.HIGHLIGHTED);
33 assert.isTrue(items[2].selected);
34 assert.equal(items[3].modelItem, dumps[3]);
35 });
36
37 test('buildMemoryLetterDots_withVMRegions', function() {
38 var dumps = createTestGlobalMemoryDumps(false, false);
39 var items = tr.ui.tracks.buildMemoryLetterDots(dumps);
40
41 assert.lengthOf(items, 4);
42 assert.equal(items[0].start, 0);
43 assert.equal(items[1].start, 5);
44 assert.equal(items[2].start, 15);
45 assert.equal(items[3].start, 18);
46
47 // Check model mapping.
48 assert.equal(items[1].selectionState, SelectionState.HIGHLIGHTED);
49 assert.isTrue(items[2].selected);
50 assert.equal(items[3].modelItem, dumps[3]);
51 });
52
53 test('buildGlobalUsedMemoryChartSeries_withoutVMRegions', function() {
54 var dumps = createTestGlobalMemoryDumps(false, false);
55 var series = tr.ui.tracks.buildGlobalUsedMemoryChartSeries(dumps);
56
57 assert.isUndefined(series);
58 });
59
60 test('buildGlobalUsedMemoryChartSeries_withVMRegions', function() {
61 var dumps = createTestGlobalMemoryDumps(true, false);
62 var series = tr.ui.tracks.buildGlobalUsedMemoryChartSeries(dumps);
63
64 assert.lengthOf(series, 3);
65
66 var sa = series[2];
67 var sb = series[1];
68 var sc = series[0];
69
70 assert.lengthOf(sa.points, 4);
71 assert.lengthOf(sb.points, 4);
72 assert.lengthOf(sc.points, 4);
73
74 // Process A: VM regions defined -> sum their PSS values (111).
75 // Process B: VM regions undefined and no previous value -> assume zero.
76 // Process C: Memory dump not present -> assume process not alive (0).
77 assert.equal(sa.points[0].x, 0);
78 assert.equal(sb.points[0].x, 0);
79 assert.equal(sc.points[0].x, 0);
80 assert.equal(sa.points[0].y, 111);
81 assert.equal(sb.points[0].y, 111);
82 assert.equal(sc.points[0].y, 111);
83 assert.equal(sa.points[0].yBase, 0);
84 assert.equal(sb.points[0].yBase, 111);
85 assert.equal(sc.points[0].yBase, 111);
86
87 // Process A: VM regions undefined -> assume previous value (111).
88 // Process B: VM regions defined -> sum their PSS values (555).
89 // Process C: VM regions undefined -> assume previous value (0).
90 assert.equal(sa.points[1].x, 5);
91 assert.equal(sb.points[1].x, 5);
92 assert.equal(sc.points[1].x, 5);
93 assert.equal(sa.points[1].y, 111);
94 assert.equal(sb.points[1].y, 261);
95 assert.equal(sc.points[1].y, 261);
96 assert.equal(sa.points[1].yBase, 0);
97 assert.equal(sb.points[1].yBase, 111);
98 assert.equal(sc.points[1].yBase, 261);
99
100 // Process A: VM regions defined -> sum their PSS values (0).
101 // Process B: Memory dump not present -> assume process not alive (0).
102 // Process C: VM regions defined -> sum their PSS values (999).
103 assert.equal(sa.points[2].x, 15);
104 assert.equal(sb.points[2].x, 15);
105 assert.equal(sc.points[2].x, 15);
106 assert.equal(sa.points[2].y, 0);
107 assert.equal(sb.points[2].y, 0);
108 assert.equal(sc.points[2].y, 210);
109 assert.equal(sa.points[2].yBase, 0);
110 assert.equal(sb.points[2].yBase, 0);
111 assert.equal(sc.points[2].yBase, 0);
112
113 // All processes: Memory dump not present -> assume process not alive (0).
114 assert.equal(sa.points[3].x, 18);
115 assert.equal(sb.points[3].x, 18);
116 assert.equal(sc.points[3].x, 18);
117 assert.equal(sa.points[3].y, 0);
118 assert.equal(sb.points[3].y, 0);
119 assert.equal(sc.points[3].y, 0);
120 assert.equal(sc.points[3].yBase, 0);
121 assert.equal(sc.points[3].yBase, 0);
122 assert.equal(sc.points[3].yBase, 0);
123
124 // Check model mapping.
125 assert.equal(sa.points[1].selectionState, SelectionState.HIGHLIGHTED);
126 assert.isTrue(sb.points[2].selected);
127 assert.equal(sc.points[3].modelItem, dumps[3]);
128 });
129
130 test('buildGlobalAllocatedMemoryChartSeries_withoutMemoryAllocatorDumps',
131 function() {
132 var dumps = createTestGlobalMemoryDumps(false, false);
133 var series = tr.ui.tracks.buildGlobalAllocatedMemoryChartSeries(dumps);
134
135 assert.isUndefined(series);
136 });
137
138 test('buildGlobalAllocatedMemoryChartSeries_withMemoryAllocatorDumps',
139 function() {
140 var dumps = createTestGlobalMemoryDumps(false, true);
141 var series = tr.ui.tracks.buildGlobalAllocatedMemoryChartSeries(dumps);
142
143 assert.lengthOf(series, 2);
144
145 var so = series[0];
146 var sv = series[1];
147
148 assert.lengthOf(so.points, 4);
149 assert.lengthOf(sv.points, 4);
150
151 // Oilpan: Only process B dumps allocated objects size (1024).
152 // V8: No process dumps allocated objects size (0).
153 assert.equal(so.points[0].x, 0);
154 assert.equal(sv.points[0].x, 0);
155 assert.equal(so.points[0].y, 1024);
156 assert.equal(sv.points[0].y, 0);
157
158 // Oilpan: Process B did not provide a value and process C dumps (128).
159 // V8: Processes B and C dump (512 + 256).
160 assert.equal(so.points[1].x, 5);
161 assert.equal(sv.points[1].x, 5);
162 assert.equal(so.points[1].y, 128);
163 assert.equal(sv.points[1].y, 768);
164
165 // Oilpan: Process B assumed not alive and process C dumps (512)
166 // V8: Process A dumps now, process B assumed not alive, process C did not
167 // provide a value (768).
168 assert.equal(so.points[2].x, 15);
169 assert.equal(sv.points[2].x, 15);
170 assert.equal(so.points[2].y, 512);
171 assert.equal(sv.points[2].y, 768);
172
173 // All processes: Memory dump not present -> assume process not alive (0).
174 assert.equal(so.points[3].x, 18);
175 assert.equal(sv.points[3].x, 18);
176 assert.equal(so.points[3].y, 0);
177 assert.equal(sv.points[3].y, 0);
178
179 // Check model mapping.
180 assert.equal(so.points[1].selectionState, SelectionState.HIGHLIGHTED);
181 assert.isTrue(sv.points[2].selected);
182 assert.equal(so.points[3].modelItem, dumps[3]);
183 });
184
185 test('buildProcessAllocatedMemoryChartSeries_withoutMemoryAllocatorDumps',
186 function() {
187 var dumps = createTestProcessMemoryDumps(false, false);
188 var series = tr.ui.tracks.buildProcessAllocatedMemoryChartSeries(dumps);
189
190 assert.isUndefined(series);
191 });
192
193 test('buildProcessAllocatedMemoryChartSeries_withMemoryAllocatorDumps',
194 function() {
195 var dumps = createTestProcessMemoryDumps(false, true);
196 var series = tr.ui.tracks.buildProcessAllocatedMemoryChartSeries(dumps);
197
198 // There should be only 2 series (because 'tracing' is not shown in the
199 // charts).
200 assert.lengthOf(series, 2);
201
202 var so = series[0];
203 var sv = series[1];
204
205 assert.lengthOf(so.points, 2);
206 assert.lengthOf(sv.points, 2);
207
208 // Oilpan: Process dumps (128).
209 // V8: Process dumps (256).
210 assert.equal(so.points[0].x, 5.12);
211 assert.equal(sv.points[0].x, 5.12);
212 assert.equal(so.points[0].y, 128);
213 assert.equal(sv.points[0].y, 256);
214
215 // Oilpan: Process dumps (512).
216 // V8: Process did not provide a value (0).
217 assert.equal(so.points[1].x, 14.5);
218 assert.equal(sv.points[1].x, 14.5);
219 assert.equal(so.points[1].y, 512);
220 assert.equal(sv.points[1].y, 0);
221
222 // Check model mapping.
223 assert.equal(so.points[1].selectionState, SelectionState.HIGHLIGHTED);
224 assert.isTrue(sv.points[0].selected);
225 assert.equal(so.points[1].modelItem, dumps[1]);
226 });
227});
228</script>