1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Copyright (c) 2012 The Chromium Authors. All rights reserved. 5 Use of this source code is governed by a BSD-style license that can be 6 found in the LICENSE file. 7 --> 8 <head> 9 <title>Thread tests</title> 10 <script src="/src/base.js"></script> 11 <script> 12 base.require('unittest'); 13 base.require('test_utils'); 14 base.require('model'); 15 </script> 16 </head> 17 <body> 18 <script> 19 'use strict'; 20 21 var ThreadSlice = tracing.model.ThreadSlice; 22 var Process = tracing.model.Process; 23 var Thread = tracing.model.Thread; 24 var newSliceNamed = test_utils.newSliceNamed; 25 var newAsyncSlice = test_utils.newAsyncSlice; 26 var newAsyncSliceNamed = test_utils.newAsyncSliceNamed; 27 28 function testThreadBounds_Empty() { 29 var t = new Thread(new Process(7), 1); 30 t.updateBounds(); 31 assertEquals(undefined, t.bounds.min); 32 assertEquals(undefined, t.bounds.max); 33 } 34 35 function testThreadBounds_SubRow() { 36 var t = new Thread(new Process(7), 1); 37 t.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 3)); 38 t.updateBounds(); 39 assertEquals(1, t.bounds.min); 40 assertEquals(4, t.bounds.max); 41 } 42 43 function testThreadBounds_AsyncSliceGroup() { 44 var t = new Thread(new Process(7), 1); 45 t.pushSlice(new ThreadSlice('', 'a', 0, 1, {}, 3)); 46 t.asyncSlices.push(newAsyncSlice(0.1, 5, t, t)); 47 t.updateBounds(); 48 assertEquals(0.1, t.bounds.min); 49 assertEquals(5.1, t.bounds.max); 50 } 51 52 function testThreadBounds_Cpu() { 53 var t = new Thread(new Process(7), 1); 54 t.cpuSlices = [newSliceNamed('x', 0, 1)]; 55 t.updateBounds(); 56 assertEquals(0, t.bounds.min); 57 assertEquals(1, t.bounds.max); 58 } 59 60 function testShiftTimestampsForwardWithCpu() { 61 var t = new Thread(new Process(7), 1); 62 t.pushSlice(new ThreadSlice('', 'a', 0, 0, {}, 3)); 63 t.asyncSlices.push(newAsyncSlice(0, 5, t, t)); 64 t.cpuSlices = [newSliceNamed('x', 0, 1)]; 65 66 var shiftCount = 0; 67 t.asyncSlices.shiftTimestampsForward = function(ts) { 68 if (ts == 0.32) 69 shiftCount++; 70 }; 71 72 t.shiftTimestampsForward(0.32); 73 74 assertEquals(1, shiftCount); 75 assertEquals(0.32, t.slices[0].start); 76 assertEquals(0.32, t.cpuSlices[0].start); 77 } 78 79 function testShiftTimestampsForwardWithoutCpu() { 80 var t = new Thread(new Process(7), 1); 81 t.pushSlice(new ThreadSlice('', 'a', 0, 0, {}, 3)); 82 t.asyncSlices.push(newAsyncSlice(0, 5, t, t)); 83 84 var shiftCount = 0; 85 t.asyncSlices.shiftTimestampsForward = function(ts) { 86 if (ts == 0.32) 87 shiftCount++; 88 }; 89 90 t.shiftTimestampsForward(0.32); 91 92 assertEquals(1, shiftCount); 93 assertEquals(0.32, t.slices[0].start); 94 } 95 </script> 96 </body> 97 </html> 98