1 # Copyright 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.
5 """Unittests for SurfaceStatsCollector."""
6 # pylint: disable=W0212
10 from pylib
.perf
.surface_stats_collector
import SurfaceStatsCollector
13 class TestSurfaceStatsCollector(unittest
.TestCase
):
15 def _CreateUniformTimestamps(base
, num
, delta
):
16 return [base
+ i
* delta
for i
in range(1, num
+ 1)]
19 def _CreateDictionaryFromResults(results
):
21 for result
in results
:
22 dictionary
[result
.name
] = result
26 self
.refresh_period
= 0.1
28 def testOneFrameDelta(self
):
29 timestamps
= self
._CreateUniformTimestamps
(0, 10, self
.refresh_period
)
30 results
= self
._CreateDictionaryFromResults
(
31 SurfaceStatsCollector
._CalculateResults
(
32 self
.refresh_period
, timestamps
, ''))
34 self
.assertEquals(results
['avg_surface_fps'].value
,
35 int(round(1 / self
.refresh_period
)))
36 self
.assertEquals(results
['jank_count'].value
, 0)
37 self
.assertEquals(results
['max_frame_delay'].value
, 1)
38 self
.assertEquals(len(results
['frame_lengths'].value
), len(timestamps
) - 1)
40 def testAllFramesTooShort(self
):
41 timestamps
= self
._CreateUniformTimestamps
(0, 10, self
.refresh_period
/ 100)
42 self
.assertRaises(Exception,
43 SurfaceStatsCollector
._CalculateResults
,
44 [self
.refresh_period
, timestamps
, ''])
46 def testSomeFramesTooShort(self
):
47 timestamps
= self
._CreateUniformTimestamps
(0, 5, self
.refresh_period
)
48 # The following timestamps should be skipped.
49 timestamps
+= self
._CreateUniformTimestamps
(timestamps
[4],
51 self
.refresh_period
/ 100)
52 timestamps
+= self
._CreateUniformTimestamps
(timestamps
[4],
56 results
= self
._CreateDictionaryFromResults
(
57 SurfaceStatsCollector
._CalculateResults
(
58 self
.refresh_period
, timestamps
, ''))
60 self
.assertEquals(len(results
['frame_lengths'].value
), 9)
63 if __name__
== '__main__':