Commit f71dd204 authored by Sergiy Belozorov's avatar Sergiy Belozorov Committed by Commit Bot

[tools] Add -d/--device options to all test launchers

This allows to select device when multiple devices are connected.

R=machenbach@chromium.org, tmrts@chromium.org

Bug: chromium:893593
Change-Id: I3dfd8b98251f613f5c93d29acd5035b236731ea6
Reviewed-on: https://chromium-review.googlesource.com/c/1452441Reviewed-by: 's avatarMichael Achenbach <machenbach@chromium.org>
Commit-Queue: Sergiy Belozorov <sergiyb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59388}
parent df630e67
......@@ -23,7 +23,7 @@ MAX_TRIES = 3
TIMEOUT = 120
# Predictable mode works only when run on the host os.
command.setup(utils.GuessOS())
command.setup(utils.GuessOS(), None)
def main(args):
def allocation_str(stdout):
......
......@@ -662,7 +662,7 @@ class DesktopPlatform(Platform):
self.command_prefix = []
# Setup command class to OS specific version.
command.setup(utils.GuessOS())
command.setup(utils.GuessOS(), options.device)
if options.prioritize or options.affinitize != None:
self.command_prefix = ["schedtool"]
......@@ -916,7 +916,7 @@ def Main(args):
help="Adapt to path structure used on buildbots and adds "
"timestamps/level to all logged status messages",
default=False, action="store_true")
parser.add_option("--device",
parser.add_option("-d", "--device",
help="The device ID to run Android tests on. If not given "
"it will be autodetected.")
parser.add_option("--extra-flags",
......
......@@ -251,7 +251,7 @@ class BaseTestRunner(object):
print ' '.join(sys.argv)
self._load_build_config(options)
command.setup(self.target_os)
command.setup(self.target_os, options.device)
try:
self._process_default_options(options)
......@@ -309,6 +309,9 @@ class BaseTestRunner(object):
parser.add_option("-j", help="The number of parallel tasks to run",
default=0, type=int)
parser.add_option("-d", "--device",
help="The device ID to run Android tests on. If not "
"given it will be autodetected.")
# Shard
parser.add_option("--shard-count", default=1, type=int,
......
......@@ -204,6 +204,9 @@ class WindowsCommand(BaseCommand):
class AndroidCommand(BaseCommand):
# This must be initialized before creating any instances of this class.
driver = None
def __init__(self, shell, args=None, cmd_prefix=None, timeout=60, env=None,
verbose=False, resources_func=None):
"""Initialize the command and all files that need to be pushed to the
......@@ -236,19 +239,19 @@ class AndroidCommand(BaseCommand):
if self.verbose:
print '# %s' % self
android_driver().push_executable(self.shell_dir, 'bin', self.shell_name)
self.driver.push_executable(self.shell_dir, 'bin', self.shell_name)
for abs_file in self.files_to_push:
abs_dir = os.path.dirname(abs_file)
file_name = os.path.basename(abs_file)
rel_dir = os.path.relpath(abs_dir, BASE_DIR)
android_driver().push_file(abs_dir, file_name, rel_dir)
self.driver.push_file(abs_dir, file_name, rel_dir)
start_time = time.time()
return_code = 0
timed_out = False
try:
stdout = android_driver().run(
stdout = self.driver.run(
'bin', self.shell_name, self.args, '.', self.timeout, self.env)
except CommandFailedException as e:
return_code = e.status
......@@ -271,10 +274,11 @@ class AndroidCommand(BaseCommand):
Command = None
def setup(target_os):
def setup(target_os, device):
"""Set the Command class to the OS-specific version."""
global Command
if target_os == 'android':
AndroidCommand.driver = android_driver(device)
Command = AndroidCommand
elif target_os == 'windows':
Command = WindowsCommand
......@@ -284,4 +288,4 @@ def setup(target_os):
def tear_down():
"""Clean up after using commands."""
if Command == AndroidCommand:
android_driver().tear_down()
AndroidCommand.driver.tear_down()
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