Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 | 4 |
| 5 import unittest | 5 import unittest |
| 6 | 6 |
| 7 from telemetry.core.platform.power_monitor import sysfs_power_monitor | 7 from telemetry.core.platform.power_monitor import sysfs_power_monitor |
| 8 | 8 |
| 9 | 9 |
| 10 class SysfsPowerMonitorMonitorTest(unittest.TestCase): | 10 class SysfsPowerMonitorMonitorTest(unittest.TestCase): |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 self.assertDictEqual(initial, self.expected_initial_freq) | 186 self.assertDictEqual(initial, self.expected_initial_freq) |
| 187 self.assertDictEqual(final, self.expected_final_freq) | 187 self.assertDictEqual(final, self.expected_final_freq) |
| 188 | 188 |
| 189 def testComputeCpuStats(self): | 189 def testComputeCpuStats(self): |
| 190 results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats( | 190 results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats( |
| 191 self.expected_initial_freq, self.expected_final_freq) | 191 self.expected_initial_freq, self.expected_final_freq) |
| 192 for cpu in self.expected_freq_percents: | 192 for cpu in self.expected_freq_percents: |
| 193 for freq in results[cpu]: | 193 for freq in results[cpu]: |
| 194 self.assertAlmostEqual(results[cpu][freq], | 194 self.assertAlmostEqual(results[cpu][freq], |
| 195 self.expected_freq_percents[cpu][freq]) | 195 self.expected_freq_percents[cpu][freq]) |
| 196 | |
| 197 def testGetCpuState(self): | |
| 198 class PlatformStub(object): | |
| 199 def __init__(self, run_command_return_value): | |
| 200 self._run_command_return_value = run_command_return_value | |
| 201 def RunCommand(self, _cmd): | |
| 202 return self._run_command_return_value | |
| 203 | |
| 204 cpu_state_from_samsung_note3 = ( | |
| 205 "C0\n\nC1\n\nC2\n\nC3\n\n" | |
| 206 "53658520886\n1809072\n7073\n1722554\n" | |
| 207 "1\n35\n300\n500\n" | |
| 208 "1412949256\n") | |
| 209 numOfCStates = 4 | |
| 210 | |
| 211 sysfsmon = sysfs_power_monitor.SysfsPowerMonitor( | |
| 212 PlatformStub(cpu_state_from_samsung_note3)) | |
| 213 # pylint: disable=W0212 | |
| 214 sysfsmon._cpus = ["cpu%d" % cpu for cpu in range(2)] | |
| 215 state = sysfsmon.GetCpuState() | |
| 216 | |
|
nednguyen
2014/10/10 16:11:52
Instead of the assertions below, how about asserti
| |
| 217 self.assertSetEqual(set(state.iterkeys()), set(sysfsmon._cpus)) | |
| 218 for cpuState in state.itervalues(): | |
| 219 lines = cpuState.splitlines() | |
| 220 self.assertEquals(len(lines), numOfCStates * 3 + 1) | |
| 221 try: | |
| 222 [int(line) for line in lines[numOfCStates:]] | |
| 223 except ValueError: | |
| 224 self.fail("Invalid integer in CPU state string: '%s'" % line) | |
| OLD | NEW |