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

Unified Diff: tools/telemetry/telemetry/internal/platform/android_platform_backend_unittest.py

Issue 1242943005: [Android] Support idle wakeup measurement with /proc/timer_stats (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Working test Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/internal/platform/android_platform_backend_unittest.py
diff --git a/tools/telemetry/telemetry/internal/platform/android_platform_backend_unittest.py b/tools/telemetry/telemetry/internal/platform/android_platform_backend_unittest.py
index 22939f862b8e7524d7f7a08347c6a6fe8093e12a..6ce664f20ff4c52ee48e0b2309b479280a2753b0 100644
--- a/tools/telemetry/telemetry/internal/platform/android_platform_backend_unittest.py
+++ b/tools/telemetry/telemetry/internal/platform/android_platform_backend_unittest.py
@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import os
import unittest
from telemetry.core import util
@@ -17,6 +18,23 @@ util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
from pylib.device import battery_utils
from pylib.device import device_utils
+
+class TestBackend(android_platform_backend.AndroidPlatformBackend):
+
+ # pylint: disable=W0223
+
+ def __init__(self, device, finder_options):
+ super(TestBackend, self).__init__(device, finder_options)
+ self._mock_files = {}
+
+ def SetMockFile(self, real_file, mock_file):
+ with open(os.path.join(util.GetUnittestDataDir(), real_file)) as f:
+ self._mock_files[mock_file] = f.read()
+
+ def GetFileContents(self, filename):
+ return self._mock_files.get(filename)
+
+
class AndroidPlatformBackendTest(unittest.TestCase):
def setUp(self):
self._options = options_for_unittests.GetCopy()
@@ -45,12 +63,18 @@ class AndroidPlatformBackendTest(unittest.TestCase):
GetProp=mock.MagicMock(side_effect=get_prop))
self.device_patcher.start()
+ self.idle_wakeup_patcher = mock.patch.object(
+ android_platform_backend.AndroidPlatformBackend,
+ '_GetIdleWakeupCount', return_value=None)
+ self.idle_wakeup_patcher.start()
+
def tearDown(self):
self._stubs.Restore()
android_platform_backend.psutil = self._actual_ps_util
self.battery_patcher.stop()
self.setup_prebuilt_tool_patcher.stop()
self.device_patcher.stop()
+ self.idle_wakeup_patcher.stop()
@decorators.Disabled('chromeos')
def testGetCpuStats(self):
@@ -100,6 +124,34 @@ class AndroidPlatformBackendTest(unittest.TestCase):
for state in result[cpu]:
self.assertAlmostEqual(result[cpu][state], expected_cstate[cpu][state])
+ def testGetIdleWakeupCount(self):
+ self.idle_wakeup_patcher.stop()
+ with open(os.path.join(
+ util.GetUnittestDataDir(), 'ps_for_timer_stats')) as ps_return:
+ with mock.patch.object(
+ device_utils.DeviceUtils, 'RunShellCommand',
+ return_value=ps_return.read().splitlines()):
+ backend = TestBackend(
+ android_device.AndroidDevice('1234'), self._options)
+ backend.SetMockFile('timer_stats_empty', '/proc/timer_stats')
+ cpu_stats = backend.GetCpuStats('31735')
+ self.assertTrue('IdleWakeupCount' in cpu_stats)
+ result = cpu_stats['IdleWakeupCount'].total_sum()
+ self.assertEquals(result, 0)
+
+ backend.SetMockFile('timer_stats', '/proc/timer_stats')
+ cpu_stats = backend.GetCpuStats('31735')
+ self.assertTrue('IdleWakeupCount' in cpu_stats)
+ result = cpu_stats['IdleWakeupCount'].total_sum()
+ self.assertEquals(result, 111)
+
+ backend.SetMockFile('timer_stats_dup_pid', '/proc/timer_stats')
+ cpu_stats = backend.GetCpuStats('31735')
+ self.assertTrue('IdleWakeupCount' in cpu_stats)
+ result = cpu_stats['IdleWakeupCount'].total_sum()
+ self.assertEquals(result, 1400)
+ self.idle_wakeup_patcher.start()
+
def testInstallTestCaFailure(self):
backend = android_platform_backend.AndroidPlatformBackend(
android_device.AndroidDevice('failure'), self._options)

Powered by Google App Engine
This is Rietveld 408576698