Commit 4551d0dc authored by jbudorick's avatar jbudorick Committed by Commit bot

[Android] Remove more uses of android_commands from build/android/pylib. (RELAND)

BUG=267773,482367,482406

Review URL: https://codereview.chromium.org/1112843002

Cr-Commit-Position: refs/heads/master@{#327501}
parent 1162a2e5
...@@ -42,6 +42,7 @@ def CommonChecks(input_api, output_api): ...@@ -42,6 +42,7 @@ def CommonChecks(input_api, output_api):
input_api, input_api,
output_api, output_api,
unit_tests=[ unit_tests=[
J('pylib', 'base', 'test_dispatcher_unittest.py'),
J('pylib', 'device', 'battery_utils_test.py'), J('pylib', 'device', 'battery_utils_test.py'),
J('pylib', 'device', 'device_utils_test.py'), J('pylib', 'device', 'device_utils_test.py'),
J('pylib', 'device', 'logcat_monitor_test.py'), J('pylib', 'device', 'logcat_monitor_test.py'),
......
...@@ -26,14 +26,15 @@ NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' ...@@ -26,14 +26,15 @@ NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports'
class BaseTestRunner(object): class BaseTestRunner(object):
"""Base class for running tests on a single device.""" """Base class for running tests on a single device."""
def __init__(self, device_serial, tool): def __init__(self, device, tool):
""" """
Args: Args:
device: Tests will run on the device of this ID. device: An instance of DeviceUtils that the tests will run on.
tool: Name of the Valgrind tool. tool: Name of the Valgrind tool.
""" """
self.device_serial = device_serial assert isinstance(device, device_utils.DeviceUtils)
self.device = device_utils.DeviceUtils(device_serial) self.device = device
self.device_serial = self.device.adb.GetDeviceSerial()
self.tool = CreateTool(tool, self.device) self.tool = CreateTool(tool, self.device)
self._http_server = None self._http_server = None
self._forwarder_device_port = 8000 self._forwarder_device_port = 8000
......
...@@ -21,7 +21,6 @@ Performs the following steps: ...@@ -21,7 +21,6 @@ Performs the following steps:
import logging import logging
import threading import threading
from pylib import android_commands
from pylib import constants from pylib import constants
from pylib.base import base_test_result from pylib.base import base_test_result
from pylib.base import test_collection from pylib.base import test_collection
...@@ -102,7 +101,7 @@ def _RunTestsFromQueue(runner, collection, out_results, watcher, ...@@ -102,7 +101,7 @@ def _RunTestsFromQueue(runner, collection, out_results, watcher,
for test in collection: for test in collection:
watcher.Reset() watcher.Reset()
try: try:
if runner.device_serial not in android_commands.GetAttachedDevices(): if not runner.device.IsOnline():
# Device is unresponsive, stop handling tests on this device. # Device is unresponsive, stop handling tests on this device.
msg = 'Device %s is unresponsive.' % runner.device_serial msg = 'Device %s is unresponsive.' % runner.device_serial
logging.warning(msg) logging.warning(msg)
...@@ -150,10 +149,7 @@ def _SetUp(runner_factory, device, out_runners, threadsafe_counter): ...@@ -150,10 +149,7 @@ def _SetUp(runner_factory, device, out_runners, threadsafe_counter):
runner = runner_factory(device, index) runner = runner_factory(device, index)
runner.SetUp() runner.SetUp()
out_runners.append(runner) out_runners.append(runner)
except (device_errors.DeviceUnreachableError, except device_errors.DeviceUnreachableError as e:
# TODO(jbudorick) Remove this once the underlying implementations
# for the above are switched or wrapped.
android_commands.errors.DeviceUnresponsiveError) as e:
logging.warning('Failed to create shard for %s: [%s]', device, e) logging.warning('Failed to create shard for %s: [%s]', device, e)
...@@ -195,10 +191,7 @@ def _RunAllTests(runners, test_collection_factory, num_retries, timeout=None, ...@@ -195,10 +191,7 @@ def _RunAllTests(runners, test_collection_factory, num_retries, timeout=None,
# Catch DeviceUnreachableErrors and set a warning exit code # Catch DeviceUnreachableErrors and set a warning exit code
try: try:
workers.JoinAll(watcher) workers.JoinAll(watcher)
except (device_errors.DeviceUnreachableError, except device_errors.DeviceUnreachableError as e:
# TODO(jbudorick) Remove this once the underlying implementations
# for the above are switched or wrapped.
android_commands.errors.DeviceUnresponsiveError) as e:
logging.error(e) logging.error(e)
if not all((len(tc) == 0 for tc in test_collections)): if not all((len(tc) == 0 for tc in test_collections)):
...@@ -236,7 +229,7 @@ def _CreateRunners(runner_factory, devices, timeout=None): ...@@ -236,7 +229,7 @@ def _CreateRunners(runner_factory, devices, timeout=None):
threads = reraiser_thread.ReraiserThreadGroup( threads = reraiser_thread.ReraiserThreadGroup(
[reraiser_thread.ReraiserThread(_SetUp, [reraiser_thread.ReraiserThread(_SetUp,
[runner_factory, d, runners, counter], [runner_factory, d, runners, counter],
name=d[-4:]) name=str(d)[-4:])
for d in devices]) for d in devices])
threads.StartAll() threads.StartAll()
threads.JoinAll(watchdog_timer.WatchdogTimer(timeout)) threads.JoinAll(watchdog_timer.WatchdogTimer(timeout))
...@@ -333,10 +326,7 @@ def RunTests(tests, runner_factory, devices, shard=True, ...@@ -333,10 +326,7 @@ def RunTests(tests, runner_factory, devices, shard=True,
finally: finally:
try: try:
_TearDownRunners(runners, setup_timeout) _TearDownRunners(runners, setup_timeout)
except (device_errors.DeviceUnreachableError, except device_errors.DeviceUnreachableError as e:
# TODO(jbudorick) Remove this once the underlying implementations
# for the above are switched or wrapped.
android_commands.errors.DeviceUnresponsiveError) as e:
logging.warning('Device unresponsive during TearDown: [%s]', e) logging.warning('Device unresponsive during TearDown: [%s]', e)
except Exception as e: except Exception as e:
logging.error('Unexpected exception caught during TearDown: %s' % str(e)) logging.error('Unexpected exception caught during TearDown: %s' % str(e))
#!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved. # Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
...@@ -10,27 +11,38 @@ import os ...@@ -10,27 +11,38 @@ import os
import sys import sys
import unittest import unittest
sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)),
os.pardir, os.pardir))
# Mock out android_commands.GetAttachedDevices().
from pylib import android_commands
android_commands.GetAttachedDevices = lambda: ['0', '1']
from pylib import constants from pylib import constants
from pylib.base import base_test_result from pylib.base import base_test_result
from pylib.base import test_collection from pylib.base import test_collection
from pylib.base import test_dispatcher from pylib.base import test_dispatcher
from pylib.device import adb_wrapper
from pylib.device import device_utils
from pylib.utils import watchdog_timer from pylib.utils import watchdog_timer
sys.path.append(
os.path.join(constants.DIR_SOURCE_ROOT, 'third_party', 'pymock'))
import mock
class TestException(Exception): class TestException(Exception):
pass pass
def _MockDevice(serial):
d = mock.MagicMock(spec=device_utils.DeviceUtils)
d.__str__.return_value = serial
d.adb = mock.MagicMock(spec=adb_wrapper.AdbWrapper)
d.adb.GetDeviceSerial = mock.MagicMock(return_value=serial)
d.IsOnline = mock.MagicMock(return_value=True)
return d
class MockRunner(object): class MockRunner(object):
"""A mock TestRunner.""" """A mock TestRunner."""
def __init__(self, device='0', shard_index=0): def __init__(self, device=None, shard_index=0):
self.device_serial = device self.device = device or _MockDevice('0')
self.device_serial = self.device.adb.GetDeviceSerial()
self.shard_index = shard_index self.shard_index = shard_index
self.setups = 0 self.setups = 0
self.teardowns = 0 self.teardowns = 0
...@@ -57,7 +69,7 @@ class MockRunnerFail(MockRunner): ...@@ -57,7 +69,7 @@ class MockRunnerFail(MockRunner):
class MockRunnerFailTwice(MockRunner): class MockRunnerFailTwice(MockRunner):
def __init__(self, device='0', shard_index=0): def __init__(self, device=None, shard_index=0):
super(MockRunnerFailTwice, self).__init__(device, shard_index) super(MockRunnerFailTwice, self).__init__(device, shard_index)
self._fails = 0 self._fails = 0
...@@ -111,7 +123,7 @@ class TestFunctions(unittest.TestCase): ...@@ -111,7 +123,7 @@ class TestFunctions(unittest.TestCase):
def testSetUp(self): def testSetUp(self):
runners = [] runners = []
counter = test_dispatcher._ThreadSafeCounter() counter = test_dispatcher._ThreadSafeCounter()
test_dispatcher._SetUp(MockRunner, '0', runners, counter) test_dispatcher._SetUp(MockRunner, _MockDevice('0'), runners, counter)
self.assertEqual(len(runners), 1) self.assertEqual(len(runners), 1)
self.assertEqual(runners[0].setups, 1) self.assertEqual(runners[0].setups, 1)
...@@ -135,7 +147,8 @@ class TestThreadGroupFunctions(unittest.TestCase): ...@@ -135,7 +147,8 @@ class TestThreadGroupFunctions(unittest.TestCase):
self.test_collection_factory = lambda: shared_test_collection self.test_collection_factory = lambda: shared_test_collection
def testCreate(self): def testCreate(self):
runners = test_dispatcher._CreateRunners(MockRunner, ['0', '1']) runners = test_dispatcher._CreateRunners(
MockRunner, [_MockDevice('0'), _MockDevice('1')])
for runner in runners: for runner in runners:
self.assertEqual(runner.setups, 1) self.assertEqual(runner.setups, 1)
self.assertEqual(set([r.device_serial for r in runners]), self.assertEqual(set([r.device_serial for r in runners]),
...@@ -144,27 +157,29 @@ class TestThreadGroupFunctions(unittest.TestCase): ...@@ -144,27 +157,29 @@ class TestThreadGroupFunctions(unittest.TestCase):
set([0, 1])) set([0, 1]))
def testRun(self): def testRun(self):
runners = [MockRunner('0'), MockRunner('1')] runners = [MockRunner(_MockDevice('0')), MockRunner(_MockDevice('1'))]
results, exit_code = test_dispatcher._RunAllTests( results, exit_code = test_dispatcher._RunAllTests(
runners, self.test_collection_factory, 0) runners, self.test_collection_factory, 0)
self.assertEqual(len(results.GetPass()), len(self.tests)) self.assertEqual(len(results.GetPass()), len(self.tests))
self.assertEqual(exit_code, 0) self.assertEqual(exit_code, 0)
def testTearDown(self): def testTearDown(self):
runners = [MockRunner('0'), MockRunner('1')] runners = [MockRunner(_MockDevice('0')), MockRunner(_MockDevice('1'))]
test_dispatcher._TearDownRunners(runners) test_dispatcher._TearDownRunners(runners)
for runner in runners: for runner in runners:
self.assertEqual(runner.teardowns, 1) self.assertEqual(runner.teardowns, 1)
def testRetry(self): def testRetry(self):
runners = test_dispatcher._CreateRunners(MockRunnerFail, ['0', '1']) runners = test_dispatcher._CreateRunners(
MockRunnerFail, [_MockDevice('0'), _MockDevice('1')])
results, exit_code = test_dispatcher._RunAllTests( results, exit_code = test_dispatcher._RunAllTests(
runners, self.test_collection_factory, 0) runners, self.test_collection_factory, 0)
self.assertEqual(len(results.GetFail()), len(self.tests)) self.assertEqual(len(results.GetFail()), len(self.tests))
self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
def testReraise(self): def testReraise(self):
runners = test_dispatcher._CreateRunners(MockRunnerException, ['0', '1']) runners = test_dispatcher._CreateRunners(
MockRunnerException, [_MockDevice('0'), _MockDevice('1')])
with self.assertRaises(TestException): with self.assertRaises(TestException):
test_dispatcher._RunAllTests(runners, self.test_collection_factory, 0) test_dispatcher._RunAllTests(runners, self.test_collection_factory, 0)
...@@ -174,7 +189,8 @@ class TestShard(unittest.TestCase): ...@@ -174,7 +189,8 @@ class TestShard(unittest.TestCase):
@staticmethod @staticmethod
def _RunShard(runner_factory): def _RunShard(runner_factory):
return test_dispatcher.RunTests( return test_dispatcher.RunTests(
['a', 'b', 'c'], runner_factory, ['0', '1'], shard=True) ['a', 'b', 'c'], runner_factory, [_MockDevice('0'), _MockDevice('1')],
shard=True)
def testShard(self): def testShard(self):
results, exit_code = TestShard._RunShard(MockRunner) results, exit_code = TestShard._RunShard(MockRunner)
...@@ -189,7 +205,7 @@ class TestShard(unittest.TestCase): ...@@ -189,7 +205,7 @@ class TestShard(unittest.TestCase):
def testNoTests(self): def testNoTests(self):
results, exit_code = test_dispatcher.RunTests( results, exit_code = test_dispatcher.RunTests(
[], MockRunner, ['0', '1'], shard=True) [], MockRunner, [_MockDevice('0'), _MockDevice('1')], shard=True)
self.assertEqual(len(results.GetAll()), 0) self.assertEqual(len(results.GetAll()), 0)
self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
...@@ -199,7 +215,8 @@ class TestReplicate(unittest.TestCase): ...@@ -199,7 +215,8 @@ class TestReplicate(unittest.TestCase):
@staticmethod @staticmethod
def _RunReplicate(runner_factory): def _RunReplicate(runner_factory):
return test_dispatcher.RunTests( return test_dispatcher.RunTests(
['a', 'b', 'c'], runner_factory, ['0', '1'], shard=False) ['a', 'b', 'c'], runner_factory, [_MockDevice('0'), _MockDevice('1')],
shard=False)
def testReplicate(self): def testReplicate(self):
results, exit_code = TestReplicate._RunReplicate(MockRunner) results, exit_code = TestReplicate._RunReplicate(MockRunner)
...@@ -215,7 +232,7 @@ class TestReplicate(unittest.TestCase): ...@@ -215,7 +232,7 @@ class TestReplicate(unittest.TestCase):
def testNoTests(self): def testNoTests(self):
results, exit_code = test_dispatcher.RunTests( results, exit_code = test_dispatcher.RunTests(
[], MockRunner, ['0', '1'], shard=False) [], MockRunner, [_MockDevice('0'), _MockDevice('1')], shard=False)
self.assertEqual(len(results.GetAll()), 0) self.assertEqual(len(results.GetAll()), 0)
self.assertEqual(exit_code, constants.ERROR_EXIT_CODE) self.assertEqual(exit_code, constants.ERROR_EXIT_CODE)
......
...@@ -542,6 +542,24 @@ class AdbWrapper(object): ...@@ -542,6 +542,24 @@ class AdbWrapper(object):
raise device_errors.AdbCommandFailedError( raise device_errors.AdbCommandFailedError(
['root'], output, device_serial=self._device_serial) ['root'], output, device_serial=self._device_serial)
def Emu(self, cmd, timeout=_DEFAULT_TIMEOUT,
retries=_DEFAULT_RETRIES):
"""Runs an emulator console command.
See http://developer.android.com/tools/devices/emulator.html#console
Args:
cmd: The command to run on the emulator console.
timeout: (optional) Timeout per try in seconds.
retries: (optional) Number of retries to attempt.
Returns:
The output of the emulator console command.
"""
if isinstance(cmd, basestring):
cmd = [cmd]
return self._RunDeviceAdbCmd(['emu'] + cmd, timeout, retries)
@property @property
def is_emulator(self): def is_emulator(self):
return _EMULATOR_RE.match(self._device_serial) return _EMULATOR_RE.match(self._device_serial)
......
...@@ -14,7 +14,6 @@ import os ...@@ -14,7 +14,6 @@ import os
import sys import sys
import unittest import unittest
from pylib import android_commands
from pylib import constants from pylib import constants
from pylib.device import battery_utils from pylib.device import battery_utils
from pylib.device import device_errors from pylib.device import device_errors
...@@ -62,8 +61,7 @@ class BatteryUtilsInitTest(unittest.TestCase): ...@@ -62,8 +61,7 @@ class BatteryUtilsInitTest(unittest.TestCase):
def testInitWithDeviceUtil(self): def testInitWithDeviceUtil(self):
serial = '0fedcba987654321' serial = '0fedcba987654321'
a = android_commands.AndroidCommands(device=serial) d = device_utils.DeviceUtils(serial)
d = device_utils.DeviceUtils(a)
b = battery_utils.BatteryUtils(d) b = battery_utils.BatteryUtils(d)
self.assertEqual(d, b._device) self.assertEqual(d, b._device)
......
...@@ -175,6 +175,29 @@ class DeviceUtils(object): ...@@ -175,6 +175,29 @@ class DeviceUtils(object):
assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR)
assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR)
def __eq__(self, other):
"""Checks whether |other| refers to the same device as |self|.
Args:
other: The object to compare to. This can be a basestring, an instance
of adb_wrapper.AdbWrapper, or an instance of DeviceUtils.
Returns:
Whether |other| refers to the same device as |self|.
"""
return self.adb.GetDeviceSerial() == str(other)
def __lt__(self, other):
"""Compares two instances of DeviceUtils.
This merely compares their serial numbers.
Args:
other: The instance of DeviceUtils to compare to.
Returns:
Whether |self| is less than |other|.
"""
return self.adb.GetDeviceSerial() < other.adb.GetDeviceSerial()
def __str__(self): def __str__(self):
"""Returns the device serial.""" """Returns the device serial."""
return self.adb.GetDeviceSerial() return self.adb.GetDeviceSerial()
...@@ -535,7 +558,7 @@ class DeviceUtils(object): ...@@ -535,7 +558,7 @@ class DeviceUtils(object):
with device_temp_file.DeviceTempFile(self.adb) as large_output_file: with device_temp_file.DeviceTempFile(self.adb) as large_output_file:
cmd = '%s > %s' % (cmd, large_output_file.name) cmd = '%s > %s' % (cmd, large_output_file.name)
logging.info('Large output mode enabled. Will write output to device ' logging.info('Large output mode enabled. Will write output to device '
' and read results from file.') 'and read results from file.')
handle_large_command(cmd) handle_large_command(cmd)
return self.ReadFile(large_output_file.name) return self.ReadFile(large_output_file.name)
else: else:
......
...@@ -161,6 +161,73 @@ class DeviceUtilsTest(mock_calls.TestCase): ...@@ -161,6 +161,73 @@ class DeviceUtilsTest(mock_calls.TestCase):
msg, str(self.device))) msg, str(self.device)))
class DeviceUtilsEqTest(DeviceUtilsTest):
def testEq_equal_deviceUtils(self):
other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdef'))
self.assertTrue(self.device == other)
self.assertTrue(other == self.device)
def testEq_equal_adbWrapper(self):
other = adb_wrapper.AdbWrapper('0123456789abcdef')
self.assertTrue(self.device == other)
self.assertTrue(other == self.device)
def testEq_equal_string(self):
other = '0123456789abcdef'
self.assertTrue(self.device == other)
self.assertTrue(other == self.device)
def testEq_devicesNotEqual(self):
other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdee'))
self.assertFalse(self.device == other)
self.assertFalse(other == self.device)
def testEq_identity(self):
self.assertTrue(self.device == self.device)
def testEq_serialInList(self):
devices = [self.device]
self.assertTrue('0123456789abcdef' in devices)
class DeviceUtilsLtTest(DeviceUtilsTest):
def testLt_lessThan(self):
other = device_utils.DeviceUtils(_AdbWrapperMock('ffffffffffffffff'))
self.assertTrue(self.device < other)
self.assertTrue(other > self.device)
def testLt_greaterThan_lhs(self):
other = device_utils.DeviceUtils(_AdbWrapperMock('0000000000000000'))
self.assertFalse(self.device < other)
self.assertFalse(other > self.device)
def testLt_equal(self):
other = device_utils.DeviceUtils(_AdbWrapperMock('0123456789abcdef'))
self.assertFalse(self.device < other)
self.assertFalse(other > self.device)
def testLt_sorted(self):
devices = [
device_utils.DeviceUtils(_AdbWrapperMock('ffffffffffffffff')),
device_utils.DeviceUtils(_AdbWrapperMock('0000000000000000')),
]
sorted_devices = sorted(devices)
self.assertEquals('0000000000000000',
sorted_devices[0].adb.GetDeviceSerial())
self.assertEquals('ffffffffffffffff',
sorted_devices[1].adb.GetDeviceSerial())
class DeviceUtilsStrTest(DeviceUtilsTest):
def testStr_returnsSerial(self):
with self.assertCalls(
(self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
self.assertEqual('0123456789abcdef', str(self.device))
class DeviceUtilsIsOnlineTest(DeviceUtilsTest): class DeviceUtilsIsOnlineTest(DeviceUtilsTest):
def testIsOnline_true(self): def testIsOnline_true(self):
...@@ -1539,14 +1606,6 @@ class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsTest): ...@@ -1539,14 +1606,6 @@ class DeviceUtilsGetMemoryUsageForPidTest(DeviceUtilsTest):
self.device.GetMemoryUsageForPid(4321)) self.device.GetMemoryUsageForPid(4321))
class DeviceUtilsStrTest(DeviceUtilsTest):
def testStr_returnsSerial(self):
with self.assertCalls(
(self.call.adb.GetDeviceSerial(), '0123456789abcdef')):
self.assertEqual('0123456789abcdef', str(self.device))
class DeviceUtilsClientCache(DeviceUtilsTest): class DeviceUtilsClientCache(DeviceUtilsTest):
def testClientCache_twoCaches(self): def testClientCache_twoCaches(self):
......
...@@ -68,9 +68,9 @@ class HostDrivenTestCase(object): ...@@ -68,9 +68,9 @@ class HostDrivenTestCase(object):
def SetUp(self, device, shard_index, ports_to_forward=None): def SetUp(self, device, shard_index, ports_to_forward=None):
if not ports_to_forward: if not ports_to_forward:
ports_to_forward = [] ports_to_forward = []
self.device_id = device self.device = device
self.shard_index = shard_index self.shard_index = shard_index
self.device = device_utils.DeviceUtils(self.device_id) self.device_id = str(self.device)
if ports_to_forward: if ports_to_forward:
self.ports_to_forward = ports_to_forward self.ports_to_forward = ports_to_forward
...@@ -117,10 +117,9 @@ class HostDrivenTestCase(object): ...@@ -117,10 +117,9 @@ class HostDrivenTestCase(object):
# TODO(bulach): move this to SetUp() stage. # TODO(bulach): move this to SetUp() stage.
self.__StartForwarder() self.__StartForwarder()
java_test_runner = test_runner.TestRunner(self.instrumentation_options, java_test_runner = test_runner.TestRunner(
self.device_id, self.instrumentation_options, self.device, self.shard_index,
self.shard_index, test_pkg, test_pkg, additional_flags=additional_flags)
additional_flags=additional_flags)
try: try:
java_test_runner.SetUp() java_test_runner.SetUp()
return java_test_runner.RunTest(test)[0] return java_test_runner.RunTest(test)[0]
......
...@@ -86,7 +86,7 @@ class HostDrivenTestRunner(base_test_runner.BaseTestRunner): ...@@ -86,7 +86,7 @@ class HostDrivenTestRunner(base_test_runner.BaseTestRunner):
exception_raised = False exception_raised = False
try: try:
test.SetUp(str(self.device), self.shard_index) test.SetUp(self.device, self.shard_index)
except Exception: except Exception:
logging.exception( logging.exception(
'Caught exception while trying to run SetUp() for test: ' + 'Caught exception while trying to run SetUp() for test: ' +
......
...@@ -9,7 +9,6 @@ import unittest ...@@ -9,7 +9,6 @@ import unittest
sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
from pylib import android_commands
from pylib.device import device_utils from pylib.device import device_utils
from pylib.perf import perf_control from pylib.perf import perf_control
...@@ -18,10 +17,9 @@ class TestPerfControl(unittest.TestCase): ...@@ -18,10 +17,9 @@ class TestPerfControl(unittest.TestCase):
if not os.getenv('BUILDTYPE'): if not os.getenv('BUILDTYPE'):
os.environ['BUILDTYPE'] = 'Debug' os.environ['BUILDTYPE'] = 'Debug'
devices = android_commands.GetAttachedDevices() devices = device_utils.DeviceUtils.HealthyDevices()
self.assertGreater(len(devices), 0, 'No device attached!') self.assertGreater(len(devices), 0, 'No device attached!')
self._device = device_utils.DeviceUtils( self._device = devices[0]
android_commands.AndroidCommands(device=devices[0]))
def testHighPerfMode(self): def testHighPerfMode(self):
perf = perf_control.PerfControl(self._device) perf = perf_control.PerfControl(self._device)
......
...@@ -10,10 +10,10 @@ import logging ...@@ -10,10 +10,10 @@ import logging
import os import os
import shutil import shutil
from pylib import android_commands
from pylib import constants from pylib import constants
from pylib import forwarder from pylib import forwarder
from pylib.device import device_list from pylib.device import device_list
from pylib.device import device_utils
from pylib.perf import test_runner from pylib.perf import test_runner
from pylib.utils import test_environment from pylib.utils import test_environment
...@@ -22,10 +22,11 @@ def _GetAllDevices(): ...@@ -22,10 +22,11 @@ def _GetAllDevices():
devices_path = os.path.join(os.environ.get('CHROMIUM_OUT_DIR', 'out'), devices_path = os.path.join(os.environ.get('CHROMIUM_OUT_DIR', 'out'),
device_list.LAST_DEVICES_FILENAME) device_list.LAST_DEVICES_FILENAME)
try: try:
devices = device_list.GetPersistentDeviceList(devices_path) devices = [device_utils.DeviceUtils(s)
for s in device_list.GetPersistentDeviceList(devices_path)]
except IOError as e: except IOError as e:
logging.error('Unable to find %s [%s]', devices_path, e) logging.error('Unable to find %s [%s]', devices_path, e)
devices = android_commands.GetAttachedDevices() devices = device_utils.DeviceUtils.HealthyDevices()
return sorted(devices) return sorted(devices)
......
...@@ -15,7 +15,6 @@ import subprocess ...@@ -15,7 +15,6 @@ import subprocess
import time import time
# TODO(craigdh): Move these pylib dependencies to pylib/utils/. # TODO(craigdh): Move these pylib dependencies to pylib/utils/.
from pylib import android_commands
from pylib import cmd_helper from pylib import cmd_helper
from pylib import constants from pylib import constants
from pylib import pexpect from pylib import pexpect
...@@ -90,14 +89,14 @@ def _KillAllEmulators(): ...@@ -90,14 +89,14 @@ def _KillAllEmulators():
running but a device slot is taken. A little bot trouble and and running but a device slot is taken. A little bot trouble and and
we're out of room forever. we're out of room forever.
""" """
emulators = android_commands.GetAttachedDevices(hardware=False) emulators = [d for d in device_utils.HealthyDevices() if d.adb.is_emulator]
if not emulators: if not emulators:
return return
for emu_name in emulators: for e in emulators:
cmd_helper.RunCmd(['adb', '-s', emu_name, 'emu', 'kill']) e.adb.Emu(['kill'])
logging.info('Emulator killing is async; give a few seconds for all to die.') logging.info('Emulator killing is async; give a few seconds for all to die.')
for _ in range(5): for _ in range(5):
if not android_commands.GetAttachedDevices(hardware=False): if not any(d.adb.is_emulator for d in device_utils.HealthyDevices()):
return return
time.sleep(1) time.sleep(1)
...@@ -141,9 +140,9 @@ class PortPool(object): ...@@ -141,9 +140,9 @@ class PortPool(object):
def _GetAvailablePort(): def _GetAvailablePort():
"""Returns an available TCP port for the console.""" """Returns an available TCP port for the console."""
used_ports = [] used_ports = []
emulators = android_commands.GetAttachedDevices(hardware=False) emulators = [d for d in device_utils.HealthyDevices() if d.adb.is_emulator]
for emulator in emulators: for emulator in emulators:
used_ports.append(emulator.split('-')[1]) used_ports.append(emulator.adb.GetDeviceSerial().split('-')[1])
for port in PortPool.port_range(): for port in PortPool.port_range():
if str(port) not in used_ports: if str(port) not in used_ports:
return port return port
......
...@@ -16,7 +16,6 @@ import sys ...@@ -16,7 +16,6 @@ import sys
import threading import threading
import unittest import unittest
from pylib import android_commands
from pylib import constants from pylib import constants
from pylib import forwarder from pylib import forwarder
from pylib import ports from pylib import ports
...@@ -25,6 +24,8 @@ from pylib.base import environment_factory ...@@ -25,6 +24,8 @@ from pylib.base import environment_factory
from pylib.base import test_dispatcher from pylib.base import test_dispatcher
from pylib.base import test_instance_factory from pylib.base import test_instance_factory
from pylib.base import test_run_factory from pylib.base import test_run_factory
from pylib.device import device_errors
from pylib.device import device_utils
from pylib.gtest import gtest_config from pylib.gtest import gtest_config
from pylib.gtest import setup as gtest_setup from pylib.gtest import setup as gtest_setup
from pylib.gtest import test_options as gtest_test_options from pylib.gtest import test_options as gtest_test_options
...@@ -867,18 +868,19 @@ def _GetAttachedDevices(test_device=None): ...@@ -867,18 +868,19 @@ def _GetAttachedDevices(test_device=None):
Returns: Returns:
A list of attached devices. A list of attached devices.
""" """
attached_devices = [] attached_devices = device_utils.DeviceUtils.HealthyDevices()
attached_devices = android_commands.GetAttachedDevices()
if test_device: if test_device:
assert test_device in attached_devices, ( test_device = [d for d in attached_devices if d == test_device]
'Did not find device %s among attached device. Attached devices: %s' if not test_device:
% (test_device, ', '.join(attached_devices))) raise device_errors.DeviceUnreachableError(
attached_devices = [test_device] 'Did not find device %s among attached device. Attached devices: %s'
% (test_device, ', '.join(attached_devices)))
assert attached_devices, 'No devices attached.' return test_device
return sorted(attached_devices) else:
if not attached_devices:
raise device_errors.NoDevicesError()
return sorted(attached_devices)
def RunTestsCommand(args, parser): def RunTestsCommand(args, parser):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment