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

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

Issue 25002005: Telemetry / Android: do not crash on GetCpuStats() if the process is gone. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unittests! Created 7 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 side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py
diff --git a/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py b/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py
new file mode 100644
index 0000000000000000000000000000000000000000..8bb827383e3408924061ac8194004c14f8fc6297
--- /dev/null
+++ b/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py
@@ -0,0 +1,49 @@
+# Copyright 2013 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 import android_platform_backend
+from telemetry.unittest import system_stub
+
+
+class MockAdbCommands(object):
+ def __init__(self, mock_content):
+ self.mock_content = mock_content
+
+ def CanAccessProtectedFileContents(self):
+ return True
+
+ # pylint: disable=W0613
+ def GetProtectedFileContents(self, file_name, log_result):
+ return self.mock_content
+
+
+class AndroidPlatformBackendTest(unittest.TestCase):
+ def setUp(self):
+ self._stubs = system_stub.Override(android_platform_backend,
+ ['perf_control', 'thermal_throttle'])
+
+ def tearDown(self):
+ self._stubs.Restore()
+
+ def testGetCpuStats(self):
+ proc_stat_content = [
+ '7702 (.android.chrome) S 167 167 0 0 -1 1077936448 '
+ '3247 0 0 0 4 1 0 0 20 0 9 0 5603962 337379328 5867 '
+ '4294967295 1074458624 1074463824 3197495984 3197494152 '
+ '1074767676 0 4612 0 38136 4294967295 0 0 17 0 0 0 0 0 0 '
+ '1074470376 1074470912 1102155776']
+ adb_valid_proc_content = MockAdbCommands(proc_stat_content)
+ backend = android_platform_backend.AndroidPlatformBackend(
+ adb_valid_proc_content, False)
+ cpu_stats = backend.GetCpuStats('7702')
+ self.assertEquals(cpu_stats, {'CpuProcessTime': 5.0})
+
+ def testGetCpuStatsInvalidPID(self):
+ # Mock an empty /proc/pid/stat.
+ adb_empty_proc_stat = MockAdbCommands([])
+ backend = android_platform_backend.AndroidPlatformBackend(
+ adb_empty_proc_stat, False)
+ cpu_stats = backend.GetCpuStats('7702')
+ self.assertEquals(cpu_stats, {})
« no previous file with comments | « tools/telemetry/telemetry/core/platform/android_platform_backend.py ('k') | tools/telemetry/telemetry/unittest/system_stub.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698