Home | History | Annotate | Download | only in trace_model
      1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 'use strict';
      6 
      7 base.require('tracing.test_utils');
      8 base.require('tracing.trace_model');
      9 
     10 base.unittest.testSuite('tracing.trace_model.thread', function() {
     11   var ThreadSlice = tracing.trace_model.ThreadSlice;
     12   var Process = tracing.trace_model.Process;
     13   var Thread = tracing.trace_model.Thread;
     14   var newSliceNamed = tracing.test_utils.newSliceNamed;
     15   var newAsyncSlice = tracing.test_utils.newAsyncSlice;
     16 
     17   test('threadBounds_Empty', function() {
     18     var model = new tracing.TraceModel();
     19     var t = new Thread(new Process(model, 7), 1);
     20     t.updateBounds();
     21     assertEquals(undefined, t.bounds.min);
     22     assertEquals(undefined, t.bounds.max);
     23   });
     24 
     25   test('threadBounds_SubRow', function() {
     26     var model = new tracing.TraceModel();
     27     var t = new Thread(new Process(model, 7), 1);
     28     t.sliceGroup.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 3));
     29     t.updateBounds();
     30     assertEquals(1, t.bounds.min);
     31     assertEquals(4, t.bounds.max);
     32   });
     33 
     34   test('threadBounds_AsyncSliceGroup', function() {
     35     var model = new tracing.TraceModel();
     36     var t = new Thread(new Process(model, 7), 1);
     37     t.sliceGroup.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 3));
     38     t.asyncSliceGroup.push(newAsyncSlice(0.1, 5, t, t));
     39     t.updateBounds();
     40     assertEquals(0.1, t.bounds.min);
     41     assertEquals(5.1, t.bounds.max);
     42   });
     43 
     44   test('threadBounds_Cpu', function() {
     45     var model = new tracing.TraceModel();
     46     var t = new Thread(new Process(model, 7), 1);
     47     t.cpuSlices = [newSliceNamed('x', 0, 1)];
     48     t.updateBounds();
     49     assertEquals(0, t.bounds.min);
     50     assertEquals(1, t.bounds.max);
     51   });
     52 
     53   test('shiftTimestampsForwardWithCpu', function() {
     54     var model = new tracing.TraceModel();
     55     var t = new Thread(new Process(model, 7), 1);
     56     t.sliceGroup.pushSlice(new ThreadSlice('', 'a', 0, 0, {}, 3));
     57     t.asyncSliceGroup.push(newAsyncSlice(0, 5, t, t));
     58     t.cpuSlices = [newSliceNamed('x', 0, 1)];
     59 
     60     var shiftCount = 0;
     61     t.asyncSliceGroup.shiftTimestampsForward = function(ts) {
     62       if (ts == 0.32)
     63         shiftCount++;
     64     };
     65 
     66     t.shiftTimestampsForward(0.32);
     67 
     68     assertEquals(1, shiftCount);
     69     assertEquals(0.32, t.sliceGroup.slices[0].start);
     70     assertEquals(0.32, t.cpuSlices[0].start);
     71   });
     72 
     73   test('shiftTimestampsForwardWithoutCpu', function() {
     74     var model = new tracing.TraceModel();
     75     var t = new Thread(new Process(model, 7), 1);
     76     t.sliceGroup.pushSlice(new ThreadSlice('', 'a', 0, 0, {}, 3));
     77     t.asyncSliceGroup.push(newAsyncSlice(0, 5, t, t));
     78 
     79     var shiftCount = 0;
     80     t.asyncSliceGroup.shiftTimestampsForward = function(ts) {
     81       if (ts == 0.32)
     82         shiftCount++;
     83     };
     84 
     85     t.shiftTimestampsForward(0.32);
     86 
     87     assertEquals(1, shiftCount);
     88     assertEquals(0.32, t.sliceGroup.slices[0].start);
     89   });
     90 });
     91