Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(745)

Side by Side Diff: tools/telemetry/telemetry/core/platform/power_monitor/sysfs_power_monitor_unittest.py

Issue 635313002: [Telemetry] Fix C-State stat reading for Note 3 and S5. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Unit test for SysfsPowerMonitor.GetCpuState Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/telemetry/telemetry/core/platform/power_monitor/sysfs_power_monitor.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
OLDNEW
« no previous file with comments | « tools/telemetry/telemetry/core/platform/power_monitor/sysfs_power_monitor.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698