blob: faae90bb5d29043e72968da98252fb58afb0c5e1 [file] [log] [blame]
<!DOCTYPE HTML>
<html>
<!--
Copyright (c) 2012 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
<title>Cpu tests</title>
<script src="base.js"></script>
<script>
base.require('unittest');
base.require('test_utils');
base.require('cpu');
</script>
</head>
<body>
<script>
'use strict';
var Cpu = tracing.Cpu;
var Slice = tracing.Slice;
function testCpuBounds_Empty() {
var cpu = new Cpu(undefined, 1);
cpu.updateBounds();
assertEquals(undefined, cpu.bounds.min);
assertEquals(undefined, cpu.bounds.max);
}
function testCpuBounds_OneSlice() {
var cpu = new Cpu(undefined, 1);
cpu.slices.push(test_utils.newSlice(1, 3));
cpu.updateBounds();
assertEquals(1, cpu.bounds.min);
assertEquals(4, cpu.bounds.max);
}
function testGetOrCreateCounter() {
var cpu = new Cpu(undefined, 1);
var ctrBar = cpu.getOrCreateCounter('foo', 'bar');
var ctrBar2 = cpu.getOrCreateCounter('foo', 'bar');
assertEquals(ctrBar2, ctrBar);
}
function testShiftTimestampsForward() {
var cpu = new Cpu(undefined, 1);
var ctr = cpu.getOrCreateCounter('foo', 'bar');
cpu.slices.push(test_utils.newSlice(1, 3));
var shiftCount = 0;
ctr.shiftTimestampsForward = function(ts) {
if (ts == 0.32)
shiftCount++;
};
cpu.slices.push(test_utils.newSlice(1, 3));
cpu.shiftTimestampsForward(0.32);
assertEquals(shiftCount, 1);
assertEquals(1.32, cpu.slices[0].start);
}
</script>
</body>
</html>