blob: 2664338314ccb7729bd476db287bdaaf7708434f [file] [log] [blame]
Simran Basi14622bb2015-11-25 13:23:40 -08001#!/usr/bin/python
2# Copyright 2015 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import argparse
7import os
8import sys
9
10import logging
11# Turn the logging level to INFO before importing other autotest
12# code, to avoid having failed import logging messages confuse the
13# test_droid user.
14logging.basicConfig(level=logging.INFO)
15
Christopher Wiley19125112015-12-16 10:04:48 -080016
Simran Basi14622bb2015-11-25 13:23:40 -080017import common
Christopher Wiley19125112015-12-16 10:04:48 -080018# Unfortunately, autotest depends on external packages for assorted
19# functionality regardless of whether or not it is needed in a particular
20# context.
21# Since we can't depend on people to import these utilities in any principled
22# way, we dynamically download code before any autotest imports.
23try:
24 import chromite.lib.terminal # pylint: disable=unused-import
25 import django.http # pylint: disable=unused-import
26except ImportError:
27 # Ensure the chromite site-package is installed.
28 import subprocess
29 build_externals_path = os.path.join(
30 os.path.dirname(os.path.dirname(os.path.realpath(__file__))),
31 'utils', 'build_externals.py')
32 subprocess.check_call([build_externals_path, 'chromiterepo', 'django'])
33 # Restart the script so python now finds the autotest site-packages.
34 sys.exit(os.execv(__file__, sys.argv))
35
Mike Frysinger5d7a7092016-02-23 15:14:42 -050036from autotest_lib.client.common_lib import utils
37from autotest_lib.server.hosts import adb_host
Simran Basi14622bb2015-11-25 13:23:40 -080038from autotest_lib.site_utils import test_runner_utils
Gilad Arnolda97d1802016-01-27 18:20:14 -080039from autotest_lib.site_utils import tester_feedback
Simran Basi14622bb2015-11-25 13:23:40 -080040
41
Simran Basi14622bb2015-11-25 13:23:40 -080042def parse_arguments(argv):
43 """
44 Parse command line arguments
45
46 @param argv: argument list to parse
47
48 @returns: parsed arguments
49
50 @raises SystemExit if arguments are malformed, or required arguments
51 are not present.
52 """
53 return _parse_arguments_internal(argv)[0]
54
55
56def _parse_arguments_internal(argv):
57 """
58 Parse command line arguments
59
60 @param argv: argument list to parse
61
62 @returns: tuple of parsed arguments and argv suitable for remote runs
63
64 @raises SystemExit if arguments are malformed, or required arguments
65 are not present.
66 """
67
68 parser = argparse.ArgumentParser(description='Run remote tests.')
69
Mike Frysinger5d7a7092016-02-23 15:14:42 -050070 parser.add_argument('-s', '--serials', metavar='SERIALS',
Simran Basi14622bb2015-11-25 13:23:40 -080071 help='Comma separate list of device serials under '
72 'test.')
Simran Basi973bf712016-05-26 13:41:34 -070073 parser.add_argument('-f', '--fastboot_serial', metavar='FB_SERIALS',
74 help='Comma separate list of fastboot serials under '
75 'test.', default=None)
Simran Basif067d9c2015-12-22 14:31:55 -080076 parser.add_argument('-r', '--remote', metavar='REMOTE',
77 default='localhost',
78 help='hostname[:port] if the ADB device is connected '
79 'to a remote machine. Ensure this workstation '
80 'is configured for passwordless ssh access as '
81 'users "root" or "adb"')
Gilad Arnolda97d1802016-01-27 18:20:14 -080082 parser.add_argument('-i', '--interactive', action='store_true',
83 help='Enable interactive feedback requests from tests.')
Simran Basi14622bb2015-11-25 13:23:40 -080084 test_runner_utils.add_common_args(parser)
85 return parser.parse_args(argv)
86
87
88def main(argv):
89 """
90 Entry point for test_droid script.
91
92 @param argv: arguments list
93 """
94 arguments = _parse_arguments_internal(argv)
95
Mike Frysinger5d7a7092016-02-23 15:14:42 -050096 serials = arguments.serials
97 if serials is None:
98 result = utils.run(['adb', 'devices'])
99 devices = adb_host.ADBHost.parse_device_serials(result.stdout)
100 if len(devices) != 1:
101 logging.error('could not detect exactly one device; please select '
102 'one with -s: %s', devices)
103 return 1
104 serials = devices[0]
105
Simran Basi14622bb2015-11-25 13:23:40 -0800106 results_directory = test_runner_utils.create_results_directory(
107 arguments.results_dir)
108 arguments.results_dir = results_directory
109
110 autotest_path = os.path.dirname(os.path.dirname(
111 os.path.realpath(__file__)))
112 site_utils_path = os.path.join(autotest_path, 'site_utils')
113 realpath = os.path.realpath(__file__)
114 site_utils_path = os.path.realpath(site_utils_path)
Mike Frysinger5d7a7092016-02-23 15:14:42 -0500115 host_attributes = {'serials' : serials,
Simran Basi14622bb2015-11-25 13:23:40 -0800116 'os_type' : 'android'}
Simran Basi973bf712016-05-26 13:41:34 -0700117 if arguments.fastboot_serial:
118 host_attributes['fastboot_serial'] = arguments.fastboot_serial
Simran Basi14622bb2015-11-25 13:23:40 -0800119
Gilad Arnolda97d1802016-01-27 18:20:14 -0800120 fb_service = None
121 try:
122 # Start the feedback service if needed.
123 if arguments.interactive:
124 fb_service = tester_feedback.FeedbackService()
125 fb_service.start()
126
127 if arguments.args:
128 arguments.args += ' '
129 else:
130 arguments.args = ''
131 arguments.args += (
132 'feedback=interactive feedback_args=localhost:%d' %
133 fb_service.server_port)
134
135 return test_runner_utils.perform_run_from_autotest_root(
136 autotest_path, argv, arguments.tests, arguments.remote,
137 args=arguments.args, ignore_deps=not arguments.enforce_deps,
138 results_directory=results_directory,
139 iterations=arguments.iterations,
140 fast_mode=arguments.fast_mode, debug=arguments.debug,
Simran Basi57740ca2016-02-19 11:20:22 -0800141 host_attributes=host_attributes, pretend=arguments.pretend)
Gilad Arnolda97d1802016-01-27 18:20:14 -0800142 finally:
143 if fb_service is not None:
144 fb_service.stop()
Simran Basi14622bb2015-11-25 13:23:40 -0800145
146
147if __name__ == '__main__':
148 sys.exit(main(sys.argv[1:]))