1 # Copyright 2013 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.
6 from telemetry.core.platform import android_platform_backend
7 from telemetry.unittest import system_stub
10 class MockAdbCommands(object):
11 def __init__(self, mock_content):
12 self.mock_content = mock_content
14 def CanAccessProtectedFileContents(self):
17 # pylint: disable=W0613
18 def GetProtectedFileContents(self, file_name, log_result):
19 return self.mock_content
22 class AndroidPlatformBackendTest(unittest.TestCase):
24 self._stubs = system_stub.Override(android_platform_backend,
25 ['perf_control', 'thermal_throttle'])
30 def testGetCpuStats(self):
32 '7702 (.android.chrome) S 167 167 0 0 -1 1077936448 '
33 '3247 0 0 0 4 1 0 0 20 0 9 0 5603962 337379328 5867 '
34 '4294967295 1074458624 1074463824 3197495984 3197494152 '
35 '1074767676 0 4612 0 38136 4294967295 0 0 17 0 0 0 0 0 0 '
36 '1074470376 1074470912 1102155776']
37 adb_valid_proc_content = MockAdbCommands(proc_stat_content)
38 backend = android_platform_backend.AndroidPlatformBackend(
39 adb_valid_proc_content, False)
40 cpu_stats = backend.GetCpuStats('7702')
41 self.assertEquals(cpu_stats, {'CpuProcessTime': 5.0})
43 def testGetCpuStatsInvalidPID(self):
44 # Mock an empty /proc/pid/stat.
45 adb_empty_proc_stat = MockAdbCommands([])
46 backend = android_platform_backend.AndroidPlatformBackend(
47 adb_empty_proc_stat, False)
48 cpu_stats = backend.GetCpuStats('7702')
49 self.assertEquals(cpu_stats, {})