Index: tools/telemetry/telemetry/core/platform/power_monitor/sysfs_power_monitor_unittest.py |
diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/sysfs_power_monitor_unittest.py b/tools/telemetry/telemetry/core/platform/power_monitor/sysfs_power_monitor_unittest.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..ed59e855f3e872ad1b2a1ff6f0fbfd5b45d26b54 |
--- /dev/null |
+++ b/tools/telemetry/telemetry/core/platform/power_monitor/sysfs_power_monitor_unittest.py |
@@ -0,0 +1,177 @@ |
+# Copyright 2014 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import unittest |
+ |
+from telemetry.core.platform.power_monitor import sysfs_power_monitor |
+ |
+ |
+class SysfsPowerMonitorMonitorTest(unittest.TestCase): |
+ initial_freq = { |
+ 'cpu0': '1700000 6227\n1600000 0\n1500000 0\n1400000 28\n1300000 22\n' |
+ '1200000 14\n1100000 19\n1000000 22\n900000 14\n800000 20\n' |
+ '700000 15\n600000 23\n500000 23\n400000 9\n300000 28\n200000 179', |
+ 'cpu1': '1700000 11491\n1600000 0\n1500000 0\n1400000 248\n1300000 1166\n' |
+ '1200000 2082\n1100000 2943\n1000000 6560\n900000 12517\n' |
+ '800000 8690\n700000 5105\n600000 3800\n500000 5131\n400000 5479\n' |
+ '300000 7571\n200000 133618' |
+ } |
+ final_freq = { |
+ 'cpu0': '1700000 7159\n1600000 0\n1500000 0\n1400000 68\n1300000 134\n' |
+ '1200000 194\n1100000 296\n1000000 716\n900000 1301\n800000 851\n' |
+ '700000 554\n600000 343\n500000 612\n400000 691\n300000 855\n' |
+ '200000 15525', |
+ 'cpu1': '1700000 12048\n1600000 0\n1500000 0\n1400000 280\n1300000 1267\n' |
+ '1200000 2272\n1100000 3163\n1000000 7039\n900000 13800\n' |
+ '800000 9599\n700000 5655\n600000 4144\n500000 5655\n400000 6005\n' |
+ '300000 8288\n200000 149724' |
+ } |
+ expected_initial_freq = { |
+ 'cpu0': { |
+ 1700000000: 6227, |
+ 1600000000: 0, |
+ 1500000000: 0, |
+ 1400000000: 28, |
+ 1300000000: 22, |
+ 1200000000: 14, |
+ 1100000000: 19, |
+ 1000000000: 22, |
+ 900000000: 14, |
+ 800000000: 20, |
+ 700000000: 15, |
+ 600000000: 23, |
+ 500000000: 23, |
+ 400000000: 9, |
+ 300000000: 28, |
+ 200000000: 179 |
+ }, |
+ 'cpu1': { |
+ 1700000000: 11491, |
+ 1600000000: 0, |
+ 1500000000: 0, |
+ 1400000000: 248, |
+ 1300000000: 1166, |
+ 1200000000: 2082, |
+ 1100000000: 2943, |
+ 1000000000: 6560, |
+ 900000000: 12517, |
+ 800000000: 8690, |
+ 700000000: 5105, |
+ 600000000: 3800, |
+ 500000000: 5131, |
+ 400000000: 5479, |
+ 300000000: 7571, |
+ 200000000: 133618 |
+ } |
+ } |
+ expected_final_freq = { |
+ 'cpu0': { |
+ 1700000000: 7159, |
+ 1600000000: 0, |
+ 1500000000: 0, |
+ 1400000000: 68, |
+ 1300000000: 134, |
+ 1200000000: 194, |
+ 1100000000: 296, |
+ 1000000000: 716, |
+ 900000000: 1301, |
+ 800000000: 851, |
+ 700000000: 554, |
+ 600000000: 343, |
+ 500000000: 612, |
+ 400000000: 691, |
+ 300000000: 855, |
+ 200000000: 15525 |
+ }, |
+ 'cpu1': { |
+ 1700000000: 12048, |
+ 1600000000: 0, |
+ 1500000000: 0, |
+ 1400000000: 280, |
+ 1300000000: 1267, |
+ 1200000000: 2272, |
+ 1100000000: 3163, |
+ 1000000000: 7039, |
+ 900000000: 13800, |
+ 800000000: 9599, |
+ 700000000: 5655, |
+ 600000000: 4144, |
+ 500000000: 5655, |
+ 400000000: 6005, |
+ 300000000: 8288, |
+ 200000000: 149724 |
+ } |
+ } |
+ expected_freq_percents = { |
+ 'whole_package': { |
+ 1700000000: 3.29254111574526, |
+ 1600000000: 0.0, |
+ 1500000000: 0.0, |
+ 1400000000: 0.15926805099535601, |
+ 1300000000: 0.47124116307273645, |
+ 1200000000: 0.818756100807525, |
+ 1100000000: 1.099381692400982, |
+ 1000000000: 2.5942528544384302, |
+ 900000000: 5.68661122326737, |
+ 800000000: 3.850545467654628, |
+ 700000000: 2.409691872245393, |
+ 600000000: 1.4693702487650486, |
+ 500000000: 2.4623575553879373, |
+ 400000000: 2.672038150383057, |
+ 300000000: 3.415770495015825, |
+ 200000000: 69.59817400982045 |
+ }, |
+ 'cpu0': { |
+ 1700000000: 4.113700564971752, |
+ 1600000000: 0.0, |
+ 1500000000: 0.0, |
+ 1400000000: 0.1765536723163842, |
+ 1300000000: 0.4943502824858757, |
+ 1200000000: 0.7944915254237288, |
+ 1100000000: 1.2226341807909604, |
+ 1000000000: 3.0632062146892656, |
+ 900000000: 5.680614406779661, |
+ 800000000: 3.6679025423728815, |
+ 700000000: 2.379060734463277, |
+ 600000000: 1.4124293785310735, |
+ 500000000: 2.599752824858757, |
+ 400000000: 3.0102401129943503, |
+ 300000000: 3.650247175141243, |
+ 200000000: 67.73481638418079 |
+ }, |
+ 'cpu1': { |
+ 1700000000: 2.4713816665187682, |
+ 1600000000: 0.0, |
+ 1500000000: 0.0, |
+ 1400000000: 0.1419824296743278, |
+ 1300000000: 0.44813204365959713, |
+ 1200000000: 0.8430206761913214, |
+ 1100000000: 0.9761292040110037, |
+ 1000000000: 2.1252994941875945, |
+ 900000000: 5.69260803975508, |
+ 800000000: 4.033188392936374, |
+ 700000000: 2.4403230100275093, |
+ 600000000: 1.526311118999024, |
+ 500000000: 2.3249622859171177, |
+ 400000000: 2.3338361877717633, |
+ 300000000: 3.1812938148904073, |
+ 200000000: 71.46153163546012 |
+ } |
+ } |
+ def testParseCpuFreq(self): |
+ initial = sysfs_power_monitor.SysfsPowerMonitor.ParseFreqSample( |
+ self.initial_freq) |
+ final = sysfs_power_monitor.SysfsPowerMonitor.ParseFreqSample( |
+ self.final_freq) |
+ self.assertDictEqual(initial, self.expected_initial_freq) |
+ self.assertDictEqual(final, self.expected_final_freq) |
+ |
+ def testComputeCpuStats(self): |
+ results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats( |
+ self.expected_initial_freq, self.expected_final_freq) |
+ for cpu in results: |
+ for freq in results[cpu]: |
+ self.assertAlmostEqual(results[cpu][freq], |
+ self.expected_freq_percents[cpu][freq]) |
+ |