Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 1 | #!/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 | |
| 6 | import argparse |
| 7 | import os |
| 8 | import sys |
| 9 | |
| 10 | import 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. |
| 14 | logging.basicConfig(level=logging.INFO) |
| 15 | |
Christopher Wiley | 1912511 | 2015-12-16 10:04:48 -0800 | [diff] [blame] | 16 | |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 17 | import common |
Christopher Wiley | 1912511 | 2015-12-16 10:04:48 -0800 | [diff] [blame] | 18 | # 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. |
| 23 | try: |
| 24 | import chromite.lib.terminal # pylint: disable=unused-import |
| 25 | import django.http # pylint: disable=unused-import |
| 26 | except 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 Frysinger | 5d7a709 | 2016-02-23 15:14:42 -0500 | [diff] [blame] | 36 | from autotest_lib.client.common_lib import utils |
| 37 | from autotest_lib.server.hosts import adb_host |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 38 | from autotest_lib.site_utils import test_runner_utils |
Gilad Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 39 | from autotest_lib.site_utils import tester_feedback |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 40 | |
| 41 | |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 42 | def 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 | |
| 56 | def _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 Frysinger | 5d7a709 | 2016-02-23 15:14:42 -0500 | [diff] [blame] | 70 | parser.add_argument('-s', '--serials', metavar='SERIALS', |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 71 | help='Comma separate list of device serials under ' |
| 72 | 'test.') |
Simran Basi | 973bf71 | 2016-05-26 13:41:34 -0700 | [diff] [blame] | 73 | parser.add_argument('-f', '--fastboot_serial', metavar='FB_SERIALS', |
| 74 | help='Comma separate list of fastboot serials under ' |
| 75 | 'test.', default=None) |
Simran Basi | f067d9c | 2015-12-22 14:31:55 -0800 | [diff] [blame] | 76 | 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 Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 82 | parser.add_argument('-i', '--interactive', action='store_true', |
| 83 | help='Enable interactive feedback requests from tests.') |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 84 | test_runner_utils.add_common_args(parser) |
| 85 | return parser.parse_args(argv) |
| 86 | |
| 87 | |
| 88 | def 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 Frysinger | 5d7a709 | 2016-02-23 15:14:42 -0500 | [diff] [blame] | 96 | 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 Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 106 | 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 Frysinger | 5d7a709 | 2016-02-23 15:14:42 -0500 | [diff] [blame] | 115 | host_attributes = {'serials' : serials, |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 116 | 'os_type' : 'android'} |
Simran Basi | 973bf71 | 2016-05-26 13:41:34 -0700 | [diff] [blame] | 117 | if arguments.fastboot_serial: |
| 118 | host_attributes['fastboot_serial'] = arguments.fastboot_serial |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 119 | |
Gilad Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 120 | 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 Basi | 57740ca | 2016-02-19 11:20:22 -0800 | [diff] [blame] | 141 | host_attributes=host_attributes, pretend=arguments.pretend) |
Gilad Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 142 | finally: |
| 143 | if fb_service is not None: |
| 144 | fb_service.stop() |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 145 | |
| 146 | |
| 147 | if __name__ == '__main__': |
| 148 | sys.exit(main(sys.argv[1:])) |