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 |
index 99564d6ce2365b8bacb5f1a8663f588c94627862..1120c613ccd79c4cea18d96183709c41c468d3be 100644 |
--- a/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py |
+++ b/tools/telemetry/telemetry/core/platform/android_platform_backend_unittest.py |
@@ -5,16 +5,49 @@ |
import unittest |
from telemetry import benchmark |
-from telemetry.core.platform import android_device |
from telemetry.core.platform import android_platform_backend |
from telemetry.unittest import system_stub |
+class MockAdbCommands(object): |
+ def __init__(self, mock_content, system_properties): |
+ self.mock_content = mock_content |
+ self.system_properties = system_properties |
+ if self.system_properties.get('ro.product.cpu.abi') == None: |
+ self.system_properties['ro.product.cpu.abi'] = 'armeabi-v7a' |
+ |
+ def CanAccessProtectedFileContents(self): |
+ return True |
+ |
+ # pylint: disable=W0613 |
+ def GetProtectedFileContents(self, file_name): |
+ return self.mock_content |
+ |
+ def PushIfNeeded(self, host_binary, device_path): |
+ pass |
+ |
+ def RunShellCommand(self, command): |
+ return [] |
+ |
+ |
+class MockDevice(object): |
+ def __init__(self, mock_adb_commands): |
+ self.old_interface = mock_adb_commands |
+ |
+ def ReadFile(self, device_path, as_root=False): # pylint: disable=W0613 |
+ return self.old_interface.GetProtectedFileContents(device_path) |
+ |
+ def GetProp(self, property_name): |
+ return self.old_interface.system_properties[property_name] |
+ |
+ def SetProp(self, property_name, property_value): |
+ self.old_interface.system_properties[property_name] = property_value |
+ |
+ |
class AndroidPlatformBackendTest(unittest.TestCase): |
def setUp(self): |
- self._stubs = system_stub.Override( |
- android_platform_backend, |
- ['perf_control', 'thermal_throttle', 'adb_commands']) |
+ self._stubs = system_stub.Override(android_platform_backend, |
+ ['perf_control', 'thermal_throttle']) |
def tearDown(self): |
self._stubs.Restore() |
@@ -27,19 +60,18 @@ |
'4294967295 1074458624 1074463824 3197495984 3197494152 ' |
'1074767676 0 4612 0 38136 4294967295 0 0 17 0 0 0 0 0 0 ' |
'1074470376 1074470912 1102155776'] |
- self._stubs.adb_commands.adb_device.mock_content = proc_stat_content |
- old_interface = self._stubs.adb_commands.adb_device.old_interface |
- old_interface.can_access_protected_file_contents = True |
+ adb_valid_proc_content = MockDevice(MockAdbCommands(proc_stat_content, {})) |
backend = android_platform_backend.AndroidPlatformBackend( |
- android_device.AndroidDevice('12345')) |
+ adb_valid_proc_content, False) |
cpu_stats = backend.GetCpuStats('7702') |
self.assertEquals(cpu_stats, {'CpuProcessTime': 5.0}) |
@benchmark.Disabled('chromeos') |
def testGetCpuStatsInvalidPID(self): |
# Mock an empty /proc/pid/stat. |
+ adb_empty_proc_stat = MockDevice(MockAdbCommands([], {})) |
backend = android_platform_backend.AndroidPlatformBackend( |
- android_device.AndroidDevice('1234')) |
+ adb_empty_proc_stat, False) |
cpu_stats = backend.GetCpuStats('7702') |
self.assertEquals(cpu_stats, {}) |