Html程序  |  63行  |  1.58 KB

<!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="/src/base.js"></script>
<script>
  base.require('unittest');
  base.require('test_utils');
  base.require('model.cpu');
</script>
</head>
<body>
<script>
  'use strict';

  var Cpu = tracing.model.Cpu;
  var Slice = tracing.model.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>