1# Copyright 2014 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 5import unittest 6 7from telemetry.timeline.slice import Slice 8 9 10class SliceTest(unittest.TestCase): 11 def testChildrenLogic(self): 12 # [ top ] 13 # [ a ] [ b ] 14 # [x] 15 top = Slice(None, 'cat', 'top', 0, duration=10, thread_timestamp=0, 16 thread_duration=5) 17 a = Slice(None, 'cat', 'a', 1, duration=2, thread_timestamp=0.5, 18 thread_duration=1) 19 x = Slice(None, 'cat', 'x', 1.5, duration=0.25, thread_timestamp=0.75, 20 thread_duration=0.125) 21 b = Slice(None, 'cat', 'b', 5, duration=2, thread_timestamp=None, 22 thread_duration=None) 23 top.sub_slices.extend([a, b]) 24 a.sub_slices.append(x) 25 26 all_children = list(top.IterEventsInThisContainerRecrusively()) 27 self.assertEquals([a, x, b], all_children) 28 29 self.assertEquals(x.self_time, 0.25) 30 self.assertEquals(a.self_time, 1.75) # 2 - 0.25 31 self.assertEquals(top.self_time, 6) # 10 - 2 - 2 32 33 self.assertEquals(x.self_thread_time, 0.125) 34 self.assertEquals(a.self_thread_time, 0.875) # 1 - 0.125 35 self.assertEquals(top.self_thread_time, None) # b has no thread time 36