OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 """Unittests for SurfaceStatsCollector.""" |
| 6 |
| 7 import unittest |
| 8 |
| 9 from surface_stats_collector import SurfaceStatsCollector |
| 10 |
| 11 class TestSurfaceStatsCollector(unittest.TestCase): |
| 12 @staticmethod |
| 13 def _CreateUniformTimestamps(base, num, delta): |
| 14 return [base + i * delta for i in range(1, num + 1)] |
| 15 |
| 16 @staticmethod |
| 17 def _CreateDictionaryFromResults(results): |
| 18 dictionary = {} |
| 19 for result in results: |
| 20 dictionary[result.name] = result |
| 21 return dictionary |
| 22 |
| 23 def setUp(self): |
| 24 self.refresh_period = 0.1 |
| 25 |
| 26 def testOneFrameDelta(self): |
| 27 timestamps = self._CreateUniformTimestamps(0, 10, self.refresh_period) |
| 28 results = self._CreateDictionaryFromResults( |
| 29 SurfaceStatsCollector._CalculateResults( |
| 30 self.refresh_period, timestamps, '')) |
| 31 |
| 32 self.assertEquals(results['avg_surface_fps'].value, |
| 33 int(round(1 / self.refresh_period))) |
| 34 self.assertEquals(results['jank_count'].value, 0) |
| 35 self.assertEquals(results['max_frame_delay'].value, 1) |
| 36 self.assertEquals(len(results['frame_lengths'].value), len(timestamps) - 1) |
| 37 |
| 38 def testAllFramesTooShort(self): |
| 39 timestamps = self._CreateUniformTimestamps(0, 10, self.refresh_period / 100) |
| 40 self.assertRaises(Exception, |
| 41 SurfaceStatsCollector._CalculateResults, |
| 42 [self.refresh_period, timestamps, '']) |
| 43 |
| 44 def testSomeFramesTooShort(self): |
| 45 timestamps = self._CreateUniformTimestamps(0, 5, self.refresh_period) |
| 46 # The following timestamps should be skipped. |
| 47 timestamps += self._CreateUniformTimestamps(timestamps[4], |
| 48 5, |
| 49 self.refresh_period / 100) |
| 50 timestamps += self._CreateUniformTimestamps(timestamps[4], |
| 51 5, |
| 52 self.refresh_period) |
| 53 |
| 54 results = self._CreateDictionaryFromResults( |
| 55 SurfaceStatsCollector._CalculateResults( |
| 56 self.refresh_period, timestamps, '')) |
| 57 |
| 58 self.assertEquals(len(results['frame_lengths'].value), 9) |
| 59 |
| 60 |
| 61 if __name__ == '__main__': |
| 62 unittest.main() |
OLD | NEW |