Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (c) 2015 The Chromium Authors. All rights reserved. |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found in the LICENSE file. |
| 6 | --> |
| 7 | |
| 8 | <link rel="import" href="/core/test_utils.html"> |
| 9 | <link rel="import" href="/core/trace_model/selection_state.html"> |
| 10 | <link rel="import" href="/core/tracks/memory_dump_track_test_utils.html"> |
| 11 | <link rel="import" href="/core/tracks/memory_dump_track_util.html"> |
| 12 | |
| 13 | <script> |
| 14 | 'use strict'; |
| 15 | |
| 16 | tv.b.unittest.testSuite(function() { |
| 17 | var SelectionState = tv.c.trace_model.SelectionState; |
| 18 | var createTestGlobalMemoryDumps = tv.c.tracks.createTestGlobalMemoryDumps; |
| 19 | var createTestProcessMemoryDumps = tv.c.tracks.createTestProcessMemoryDumps; |
| 20 | |
| 21 | test('buildMemoryLetterDots_withoutVMRegions', function() { |
| 22 | var dumps = createTestGlobalMemoryDumps(false, false); |
| 23 | var items = tv.c.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 = tv.c.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 = tv.c.tracks.buildGlobalUsedMemoryChartSeries(dumps); |
| 56 | |
| 57 | assert.isUndefined(series); |
| 58 | }); |
| 59 | |
| 60 | test('buildGlobalUsedMemoryChartSeries_withVMRegions', function() { |
| 61 | var dumps = createTestGlobalMemoryDumps(true, false); |
| 62 | var series = tv.c.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 | |
| 84 | // Process A: VM regions undefined -> assume previous value (111). |
| 85 | // Process B: VM regions defined -> sum their PSS values (555). |
| 86 | // Process C: VM regions undefined -> assume previous value (0). |
| 87 | assert.equal(sa.points[1].x, 5); |
| 88 | assert.equal(sb.points[1].x, 5); |
| 89 | assert.equal(sc.points[1].x, 5); |
| 90 | assert.equal(sa.points[1].y, 111); |
| 91 | assert.equal(sb.points[1].y, 261); |
| 92 | assert.equal(sc.points[1].y, 261); |
| 93 | |
| 94 | // Process A: VM regions defined -> sum their PSS values (0). |
| 95 | // Process B: Memory dump not present -> assume process not alive (0). |
| 96 | // Process C: VM regions defined -> sum their PSS values (999). |
| 97 | assert.equal(sa.points[2].x, 15); |
| 98 | assert.equal(sb.points[2].x, 15); |
| 99 | assert.equal(sc.points[2].x, 15); |
| 100 | assert.equal(sa.points[2].y, 0); |
| 101 | assert.equal(sb.points[2].y, 0); |
| 102 | assert.equal(sc.points[2].y, 210); |
| 103 | |
| 104 | // All processes: Memory dump not present -> assume process not alive (0). |
| 105 | assert.equal(sa.points[3].x, 18); |
| 106 | assert.equal(sb.points[3].x, 18); |
| 107 | assert.equal(sc.points[3].x, 18); |
| 108 | assert.equal(sa.points[3].y, 0); |
| 109 | assert.equal(sb.points[3].y, 0); |
| 110 | assert.equal(sc.points[3].y, 0); |
| 111 | |
| 112 | // Check model mapping. |
| 113 | assert.equal(sa.points[1].selectionState, SelectionState.HIGHLIGHTED); |
| 114 | assert.isTrue(sb.points[2].selected); |
| 115 | assert.equal(sc.points[3].modelItem, dumps[3]); |
| 116 | }); |
| 117 | |
| 118 | test('buildGlobalAllocatedMemoryChartSeries_withoutMemoryAllocatorDumps', |
| 119 | function() { |
| 120 | var dumps = createTestGlobalMemoryDumps(false, false); |
| 121 | var series = tv.c.tracks.buildGlobalAllocatedMemoryChartSeries(dumps); |
| 122 | |
| 123 | assert.isUndefined(series); |
| 124 | }); |
| 125 | |
| 126 | test('buildGlobalAllocatedMemoryChartSeries_withMemoryAllocatorDumps', |
| 127 | function() { |
| 128 | var dumps = createTestGlobalMemoryDumps(false, true); |
| 129 | var series = tv.c.tracks.buildGlobalAllocatedMemoryChartSeries(dumps); |
| 130 | |
| 131 | assert.lengthOf(series, 2); |
| 132 | |
| 133 | var so = series[0]; |
| 134 | var sv = series[1]; |
| 135 | |
| 136 | assert.lengthOf(so.points, 4); |
| 137 | assert.lengthOf(sv.points, 4); |
| 138 | |
| 139 | // Oilpan: Only process B dumps allocated objects size (1024). |
| 140 | // V8: No process dumps allocated objects size (0). |
| 141 | assert.equal(so.points[0].x, 0); |
| 142 | assert.equal(sv.points[0].x, 0); |
| 143 | assert.equal(so.points[0].y, 1024); |
| 144 | assert.equal(sv.points[0].y, 0); |
| 145 | |
| 146 | // Oilpan: Process B did not provide a value and process C dumps (128). |
| 147 | // V8: Processes B and C dump (512 + 256). |
| 148 | assert.equal(so.points[1].x, 5); |
| 149 | assert.equal(sv.points[1].x, 5); |
| 150 | assert.equal(so.points[1].y, 128); |
| 151 | assert.equal(sv.points[1].y, 768); |
| 152 | |
| 153 | // Oilpan: Process B assumed not alive and process C dumps (512) |
| 154 | // V8: Process A dumps now, process B assumed not alive, process C did not |
| 155 | // provide a value (768). |
| 156 | assert.equal(so.points[2].x, 15); |
| 157 | assert.equal(sv.points[2].x, 15); |
| 158 | assert.equal(so.points[2].y, 512); |
| 159 | assert.equal(sv.points[2].y, 768); |
| 160 | |
| 161 | // All processes: Memory dump not present -> assume process not alive (0). |
| 162 | assert.equal(so.points[3].x, 18); |
| 163 | assert.equal(sv.points[3].x, 18); |
| 164 | assert.equal(so.points[3].y, 0); |
| 165 | assert.equal(sv.points[3].y, 0); |
| 166 | |
| 167 | // Check model mapping. |
| 168 | assert.equal(so.points[1].selectionState, SelectionState.HIGHLIGHTED); |
| 169 | assert.isTrue(sv.points[2].selected); |
| 170 | assert.equal(so.points[3].modelItem, dumps[3]); |
| 171 | }); |
| 172 | |
| 173 | test('buildProcessAllocatedMemoryChartSeries_withoutMemoryAllocatorDumps', |
| 174 | function() { |
| 175 | var dumps = createTestProcessMemoryDumps(false, false); |
| 176 | var series = tv.c.tracks.buildProcessAllocatedMemoryChartSeries(dumps); |
| 177 | |
| 178 | assert.isUndefined(series); |
| 179 | }); |
| 180 | |
| 181 | test('buildProcessAllocatedMemoryChartSeries_withMemoryAllocatorDumps', |
| 182 | function() { |
| 183 | var dumps = createTestProcessMemoryDumps(false, true); |
| 184 | var series = tv.c.tracks.buildProcessAllocatedMemoryChartSeries(dumps); |
| 185 | |
| 186 | assert.lengthOf(series, 2); |
| 187 | |
| 188 | var so = series[0]; |
| 189 | var sv = series[1]; |
| 190 | |
| 191 | assert.lengthOf(so.points, 2); |
| 192 | assert.lengthOf(sv.points, 2); |
| 193 | |
| 194 | // Oilpan: Process dumps (128). |
| 195 | // V8: Process dumps (256). |
| 196 | assert.equal(so.points[0].x, 5.12); |
| 197 | assert.equal(sv.points[0].x, 5.12); |
| 198 | assert.equal(so.points[0].y, 128); |
| 199 | assert.equal(sv.points[0].y, 256); |
| 200 | |
| 201 | // Oilpan: Process dumps (512). |
| 202 | // V8: Process did not provide a value (0). |
| 203 | assert.equal(so.points[1].x, 14.5); |
| 204 | assert.equal(sv.points[1].x, 14.5); |
| 205 | assert.equal(so.points[1].y, 512); |
| 206 | assert.equal(sv.points[1].y, 0); |
| 207 | |
| 208 | // Check model mapping. |
| 209 | assert.equal(so.points[1].selectionState, SelectionState.HIGHLIGHTED); |
| 210 | assert.isTrue(sv.points[0].selected); |
| 211 | assert.equal(so.points[1].modelItem, dumps[1]); |
| 212 | }); |
| 213 | }); |
| 214 | </script> |