Index: tools/telemetry/telemetry/internal/backends/android_command_line_backend_unittest.py |
diff --git a/tools/telemetry/telemetry/internal/backends/android_command_line_backend_unittest.py b/tools/telemetry/telemetry/internal/backends/android_command_line_backend_unittest.py |
index 4ff050c548302d7514ec86103968957e5d3daf6b..a7b1b8a7c56d621d1da5dc448de3bbb39e87892c 100644 |
--- a/tools/telemetry/telemetry/internal/backends/android_command_line_backend_unittest.py |
+++ b/tools/telemetry/telemetry/internal/backends/android_command_line_backend_unittest.py |
@@ -2,13 +2,18 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
+import logging |
import unittest |
-from telemetry import benchmark |
-from telemetry.internal.backends import adb_commands |
+from telemetry import decorators |
+from telemetry.core import util |
from telemetry.internal.backends import android_command_line_backend |
from telemetry.unittest_util import options_for_unittests |
+util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') |
+from pylib.device import device_utils # pylint: disable=import-error |
+ |
+ |
class _MockBackendSettings(object): |
pseudo_exec_name = 'chrome' |
@@ -21,6 +26,17 @@ class _MockBackendSettings(object): |
class AndroidCommandLineBackendTest(unittest.TestCase): |
+ def _GetDeviceForTest(self): |
+ serial = options_for_unittests.GetCopy().device |
+ if serial: |
+ device = device_utils.DeviceUtils(serial) |
+ return device |
+ else: |
+ devices = device_utils.DeviceUtils.HealthyDevices() |
+ if not devices: |
+ return None |
+ return devices[0] |
+ |
def testQuoteIfNeededNoEquals(self): |
string = 'value' |
self.assertEqual(string, |
@@ -42,46 +58,48 @@ class AndroidCommandLineBackendTest(unittest.TestCase): |
self.assertEqual(expected_output, |
android_command_line_backend._QuoteIfNeeded(string)) |
- @benchmark.Enabled('android') |
+ @decorators.Enabled('android') |
def testSetUpCommandLineFlagsCmdRestored(self): |
"""Test that a previous command line file is restored. |
Requires a device connected to the host. |
""" |
- serial = options_for_unittests.GetCopy().device |
- if not serial: |
- serial = adb_commands.GetAttachedDevices()[0] |
- cmd_file = '/data/local/tmp/test_cmd' |
- adb = adb_commands.AdbCommands(device=serial) |
- backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd') |
+ device = self._GetDeviceForTest() |
+ if not device: |
+ logging.warning('Skip the test because we cannot find any healthy device') |
+ return |
+ cmd_file = '/data/local/tmp/test_cmd2' |
+ backend_settings = _MockBackendSettings(cmd_file) |
startup_args = ['--some', '--test', '--args'] |
- device = adb.device() |
- device.WriteFile(cmd_file, 'chrome --args --to --save') |
- with android_command_line_backend.SetUpCommandLineFlags( |
- adb, backend_settings, startup_args): |
- self.assertEqual('chrome --some --test --args', |
+ try: |
+ device.WriteFile(cmd_file, 'chrome --args --to --save') |
+ self.assertEqual('chrome --args --to --save', |
device.ReadFile(cmd_file).strip()) |
- self.assertEqual('chrome --args --to --save', |
- device.ReadFile(cmd_file).strip()) |
- device.RunShellCommand(['rm', '-f', cmd_file], check_return=True) |
+ with android_command_line_backend.SetUpCommandLineFlags( |
+ device, backend_settings, startup_args): |
+ self.assertEqual('chrome --some --test --args', |
+ device.ReadFile(cmd_file).strip()) |
+ self.assertEqual('chrome --args --to --save', |
+ device.ReadFile(cmd_file).strip()) |
+ finally: |
+ device.RunShellCommand(['rm', '-f', cmd_file], check_return=True) |
- @benchmark.Enabled('android') |
+ @decorators.Enabled('android') |
def testSetUpCommandLineFlagsCmdRemoved(self): |
"""Test that the command line file is removed if it did not exist before. |
Requires a device connected to the host. |
""" |
- serial = options_for_unittests.GetCopy().device |
- if not serial: |
- serial = adb_commands.GetAttachedDevices()[0] |
+ device = self._GetDeviceForTest() |
+ if not device: |
+ logging.warning('Skip the test because we cannot find any healthy device') |
+ return |
cmd_file = '/data/local/tmp/test_cmd' |
- adb = adb_commands.AdbCommands(device=serial) |
- backend_settings = _MockBackendSettings('/data/local/tmp/test_cmd') |
+ backend_settings = _MockBackendSettings(cmd_file) |
startup_args = ['--some', '--test', '--args'] |
- device = adb.device() |
device.RunShellCommand(['rm', '-f', cmd_file], check_return=True) |
with android_command_line_backend.SetUpCommandLineFlags( |
- adb, backend_settings, startup_args): |
+ device, backend_settings, startup_args): |
self.assertEqual('chrome --some --test --args', |
device.ReadFile(cmd_file).strip()) |
self.assertFalse(device.FileExists(cmd_file)) |