Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 import logging | 4 import logging |
| 5 import os | 5 import os |
| 6 import unittest | 6 import unittest |
| 7 | 7 |
| 8 from telemetry.core import util | 8 from telemetry.core import util |
| 9 from telemetry.core.platform import linux_based_platform_backend | 9 from telemetry.core.platform import linux_based_platform_backend |
| 10 | 10 |
| 11 | 11 |
| 12 class TestBackend(linux_based_platform_backend.LinuxBasedPlatformBackend): | 12 class TestBackend(linux_based_platform_backend.LinuxBasedPlatformBackend): |
| 13 | 13 |
| 14 # pylint: disable=W0223 | 14 # pylint: disable=W0223 |
| 15 | 15 |
| 16 def __init__(self): | 16 def __init__(self): |
| 17 super(TestBackend, self).__init__() | 17 super(TestBackend, self).__init__() |
| 18 self._mock_files = {} | 18 self._mock_files = {} |
| 19 | 19 |
| 20 def SetMockFile(self, filename, output): | 20 def SetMockFile(self, filename, output): |
| 21 self._mock_files[filename] = output | 21 self._mock_files[filename] = output |
| 22 | 22 |
| 23 def GetFileContents(self, filename): | 23 def GetFileContents(self, filename): |
| 24 return self._mock_files[filename] | 24 return self._mock_files[filename] |
| 25 | 25 |
| 26 def GetClockTicks(self): | |
| 27 return 41 | |
| 26 | 28 |
| 27 class LinuxBasedPlatformBackendTest(unittest.TestCase): | 29 class LinuxBasedPlatformBackendTest(unittest.TestCase): |
| 28 | 30 |
| 31 def testGetCpuStatsBasic(self): | |
| 32 if not linux_based_platform_backend.resource: | |
| 33 logging.warning('Test not supported') | |
| 34 return | |
| 35 | |
| 36 backend = TestBackend() | |
| 37 with open(os.path.join(util.GetUnittestDataDir(), 'stat')) as f: | |
| 38 backend.SetMockFile('/proc/1/stat', f.read()) | |
|
jeremy
2014/10/29 06:11:32
IMHO it might be a bit cleaner if you split these
Lei Zhang
2014/10/29 07:03:08
Done. Can you take a look again to make sure I did
| |
| 39 result = backend.GetCpuStats(1) | |
| 40 self.assertEquals(result, {'CpuProcessTime': 22.0}) | |
| 41 | |
| 42 def testGetCpuTimestampBasic(self): | |
| 43 if not linux_based_platform_backend.resource: | |
| 44 logging.warning('Test not supported') | |
| 45 return | |
| 46 | |
| 47 backend = TestBackend() | |
| 48 with open(os.path.join(util.GetUnittestDataDir(), 'timer_list')) as f: | |
| 49 backend.SetMockFile('/proc/timer_list', f.read()) | |
| 50 result = backend.GetCpuTimestamp() | |
| 51 self.assertEquals(result, {'TotalTime': 105054633.0}) | |
| 52 | |
| 29 def testGetMemoryStatsBasic(self): | 53 def testGetMemoryStatsBasic(self): |
| 30 if not linux_based_platform_backend.resource: | 54 if not linux_based_platform_backend.resource: |
| 31 logging.warning('Test not supported') | 55 logging.warning('Test not supported') |
| 32 return | 56 return |
| 33 | 57 |
| 34 backend = TestBackend() | 58 backend = TestBackend() |
| 35 with open(os.path.join(util.GetUnittestDataDir(), 'stat')) as f: | 59 with open(os.path.join(util.GetUnittestDataDir(), 'stat')) as f: |
| 36 backend.SetMockFile('/proc/1/stat', f.read()) | 60 backend.SetMockFile('/proc/1/stat', f.read()) |
| 37 with open(os.path.join(util.GetUnittestDataDir(), 'status')) as f: | 61 with open(os.path.join(util.GetUnittestDataDir(), 'status')) as f: |
| 38 backend.SetMockFile('/proc/1/status', f.read()) | 62 backend.SetMockFile('/proc/1/status', f.read()) |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 56 with open(os.path.join(util.GetUnittestDataDir(), 'status_nohwm')) as f: | 80 with open(os.path.join(util.GetUnittestDataDir(), 'status_nohwm')) as f: |
| 57 backend.SetMockFile('/proc/1/status', f.read()) | 81 backend.SetMockFile('/proc/1/status', f.read()) |
| 58 with open(os.path.join(util.GetUnittestDataDir(), 'smaps')) as f: | 82 with open(os.path.join(util.GetUnittestDataDir(), 'smaps')) as f: |
| 59 backend.SetMockFile('/proc/1/smaps', f.read()) | 83 backend.SetMockFile('/proc/1/smaps', f.read()) |
| 60 result = backend.GetMemoryStats(1) | 84 result = backend.GetMemoryStats(1) |
| 61 self.assertEquals(result, {'PrivateDirty': 5324800, | 85 self.assertEquals(result, {'PrivateDirty': 5324800, |
| 62 'VM': 1025978368, | 86 'VM': 1025978368, |
| 63 'VMPeak': 1025978368, | 87 'VMPeak': 1025978368, |
| 64 'WorkingSetSize': 84000768, | 88 'WorkingSetSize': 84000768, |
| 65 'WorkingSetSizePeak': 84000768}) | 89 'WorkingSetSizePeak': 84000768}) |
| OLD | NEW |