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
3 # found in the LICENSE file.
7 from telemetry.core.platform.power_monitor import sysfs_power_monitor
10 class SysfsPowerMonitorMonitorTest(unittest.TestCase):
12 '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 '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 '1200000 2082\n1100000 2943\n1000000 6560\n900000 12517\n'
17 '800000 8690\n700000 5105\n600000 3800\n500000 5131\n400000 5479\n'
18 '300000 7571\n200000 133618',
19 'cpu2': '1700000 1131',
20 'cpu3': '1700000 1131'
23 'cpu0': '1700000 7159\n1600000 0\n1500000 0\n1400000 68\n1300000 134\n'
24 '1200000 194\n1100000 296\n1000000 716\n900000 1301\n800000 851\n'
25 '700000 554\n600000 343\n500000 612\n400000 691\n300000 855\n'
27 'cpu1': '1700000 12048\n1600000 0\n1500000 0\n1400000 280\n1300000 1267\n'
28 '1200000 2272\n1100000 3163\n1000000 7039\n900000 13800\n'
29 '800000 9599\n700000 5655\n600000 4144\n500000 5655\n400000 6005\n'
30 '300000 8288\n200000 149724',
34 expected_initial_freq = {
78 expected_final_freq = {
118 expected_freq_percents = {
120 1700000000: 3.29254111574526,
123 1400000000: 0.15926805099535601,
124 1300000000: 0.47124116307273645,
125 1200000000: 0.818756100807525,
126 1100000000: 1.099381692400982,
127 1000000000: 2.5942528544384302,
128 900000000: 5.68661122326737,
129 800000000: 3.850545467654628,
130 700000000: 2.409691872245393,
131 600000000: 1.4693702487650486,
132 500000000: 2.4623575553879373,
133 400000000: 2.672038150383057,
134 300000000: 3.415770495015825,
135 200000000: 69.59817400982045
138 1700000000: 4.113700564971752,
141 1400000000: 0.1765536723163842,
142 1300000000: 0.4943502824858757,
143 1200000000: 0.7944915254237288,
144 1100000000: 1.2226341807909604,
145 1000000000: 3.0632062146892656,
146 900000000: 5.680614406779661,
147 800000000: 3.6679025423728815,
148 700000000: 2.379060734463277,
149 600000000: 1.4124293785310735,
150 500000000: 2.599752824858757,
151 400000000: 3.0102401129943503,
152 300000000: 3.650247175141243,
153 200000000: 67.73481638418079
156 1700000000: 2.4713816665187682,
159 1400000000: 0.1419824296743278,
160 1300000000: 0.44813204365959713,
161 1200000000: 0.8430206761913214,
162 1100000000: 0.9761292040110037,
163 1000000000: 2.1252994941875945,
164 900000000: 5.69260803975508,
165 800000000: 4.033188392936374,
166 700000000: 2.4403230100275093,
167 600000000: 1.526311118999024,
168 500000000: 2.3249622859171177,
169 400000000: 2.3338361877717633,
170 300000000: 3.1812938148904073,
171 200000000: 71.46153163546012
181 def testParseCpuFreq(self):
182 initial = sysfs_power_monitor.SysfsPowerMonitor.ParseFreqSample(
184 final = sysfs_power_monitor.SysfsPowerMonitor.ParseFreqSample(
186 self.assertDictEqual(initial, self.expected_initial_freq)
187 self.assertDictEqual(final, self.expected_final_freq)
189 def testComputeCpuStats(self):
190 results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats(
191 self.expected_initial_freq, self.expected_final_freq)
192 for cpu in self.expected_freq_percents:
193 for freq in results[cpu]:
194 self.assertAlmostEqual(results[cpu][freq],
195 self.expected_freq_percents[cpu][freq])