Chromium Code Reviews| 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 exception_caught = False | |
| 41 try: | |
| 42 results = self._CreateDictionaryFromResults( | |
|
bulach
2013/11/15 12:11:19
nit: self.assertRaises(Exception, self._CreateDict
| |
| 43 SurfaceStatsCollector._CalculateResults( | |
| 44 self.refresh_period, timestamps, '')) | |
| 45 except: | |
| 46 exception_caught = True | |
| 47 | |
| 48 self.assertTrue(exception_caught) | |
| 49 | |
| 50 def testSomeFramesTooShort(self): | |
| 51 timestamps = self._CreateUniformTimestamps(0, 5, self.refresh_period) | |
| 52 # The following timestamps should be skipped. | |
| 53 timestamps += self._CreateUniformTimestamps(timestamps[4], | |
| 54 5, | |
| 55 self.refresh_period / 100) | |
| 56 timestamps += self._CreateUniformTimestamps(timestamps[4], | |
| 57 5, | |
| 58 self.refresh_period) | |
| 59 print timestamps | |
|
bulach
2013/11/15 12:11:19
nit: remove?
| |
| 60 | |
| 61 results = self._CreateDictionaryFromResults( | |
| 62 SurfaceStatsCollector._CalculateResults( | |
| 63 self.refresh_period, timestamps, '')) | |
| 64 | |
| 65 self.assertEquals(len(results['frame_lengths'].value), 9) | |
| 66 | |
| 67 | |
| 68 if __name__ == '__main__': | |
| 69 unittest.main() | |
| OLD | NEW |