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 from telemetry.core.platform import android_platform_backend |
8 | 9 |
9 | 10 |
10 class SysfsPowerMonitorMonitorTest(unittest.TestCase): | 11 class SysfsPowerMonitorMonitorTest(unittest.TestCase): |
11 initial_freq = { | 12 initial_freq = { |
12 'cpu0': '1700000 6227\n1600000 0\n1500000 0\n1400000 28\n1300000 22\n' | 13 'cpu0': '1700000 6227\n1600000 0\n1500000 0\n1400000 28\n1300000 22\n' |
13 '1200000 14\n1100000 19\n1000000 22\n900000 14\n800000 20\n' | 14 '1200000 14\n1100000 19\n1000000 22\n900000 14\n800000 20\n' |
14 '700000 15\n600000 23\n500000 23\n400000 9\n300000 28\n200000 179', | 15 '700000 15\n600000 23\n500000 23\n400000 9\n300000 28\n200000 179', |
15 'cpu1': '1700000 11491\n1600000 0\n1500000 0\n1400000 248\n1300000 1166\n' | 16 'cpu1': '1700000 11491\n1600000 0\n1500000 0\n1400000 248\n1300000 1166\n' |
16 '1200000 2082\n1100000 2943\n1000000 6560\n900000 12517\n' | 17 '1200000 2082\n1100000 2943\n1000000 6560\n900000 12517\n' |
17 '800000 8690\n700000 5105\n600000 3800\n500000 5131\n400000 5479\n' | 18 '800000 8690\n700000 5105\n600000 3800\n500000 5131\n400000 5479\n' |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 self.assertDictEqual(initial, self.expected_initial_freq) | 187 self.assertDictEqual(initial, self.expected_initial_freq) |
187 self.assertDictEqual(final, self.expected_final_freq) | 188 self.assertDictEqual(final, self.expected_final_freq) |
188 | 189 |
189 def testComputeCpuStats(self): | 190 def testComputeCpuStats(self): |
190 results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats( | 191 results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats( |
191 self.expected_initial_freq, self.expected_final_freq) | 192 self.expected_initial_freq, self.expected_final_freq) |
192 for cpu in self.expected_freq_percents: | 193 for cpu in self.expected_freq_percents: |
193 for freq in results[cpu]: | 194 for freq in results[cpu]: |
194 self.assertAlmostEqual(results[cpu][freq], | 195 self.assertAlmostEqual(results[cpu][freq], |
195 self.expected_freq_percents[cpu][freq]) | 196 self.expected_freq_percents[cpu][freq]) |
| 197 |
| 198 def testGetCpuStateForAndroidDevices(self): |
| 199 class PlatformStub(object): |
| 200 def __init__(self, run_command_return_value): |
| 201 self._run_command_return_value = run_command_return_value |
| 202 def RunCommand(self, _cmd): |
| 203 return self._run_command_return_value |
| 204 |
| 205 cpu_state_from_samsung_note3 = ( |
| 206 "C0\n\nC1\n\nC2\n\nC3\n\n" |
| 207 "53658520886\n1809072\n7073\n1722554\n" |
| 208 "1\n35\n300\n500\n" |
| 209 "1412949256\n") |
| 210 expected_cstate_dict = { |
| 211 'C0': 1412895593940415, |
| 212 'C1': 1809072, |
| 213 'C2': 7073, |
| 214 'C3': 1722554, |
| 215 'WFI': 53658520886 |
| 216 } |
| 217 cpus = ["cpu%d" % cpu for cpu in range(2)] |
| 218 expected_result = dict(zip(cpus, [expected_cstate_dict]*len(cpus))) |
| 219 |
| 220 sysfsmon = sysfs_power_monitor.SysfsPowerMonitor( |
| 221 PlatformStub(cpu_state_from_samsung_note3)) |
| 222 # pylint: disable=W0212 |
| 223 sysfsmon._cpus = cpus |
| 224 cstate = sysfsmon.GetCpuState() |
| 225 result = android_platform_backend.AndroidPlatformBackend.ParseCStateSample( |
| 226 cstate) |
| 227 self.assertDictEqual(expected_result, result) |
OLD | NEW |