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 | |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 36 | from autotest_lib.site_utils import test_runner_utils |
Gilad Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 37 | from autotest_lib.site_utils import tester_feedback |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 38 | |
| 39 | |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 40 | def parse_arguments(argv): |
| 41 | """ |
| 42 | Parse command line arguments |
| 43 | |
| 44 | @param argv: argument list to parse |
| 45 | |
| 46 | @returns: parsed arguments |
| 47 | |
| 48 | @raises SystemExit if arguments are malformed, or required arguments |
| 49 | are not present. |
| 50 | """ |
| 51 | return _parse_arguments_internal(argv)[0] |
| 52 | |
| 53 | |
| 54 | def _parse_arguments_internal(argv): |
| 55 | """ |
| 56 | Parse command line arguments |
| 57 | |
| 58 | @param argv: argument list to parse |
| 59 | |
| 60 | @returns: tuple of parsed arguments and argv suitable for remote runs |
| 61 | |
| 62 | @raises SystemExit if arguments are malformed, or required arguments |
| 63 | are not present. |
| 64 | """ |
| 65 | |
| 66 | parser = argparse.ArgumentParser(description='Run remote tests.') |
| 67 | |
| 68 | parser.add_argument('serials', metavar='SERIALS', |
| 69 | help='Comma separate list of device serials under ' |
| 70 | 'test.') |
Simran Basi | f067d9c | 2015-12-22 14:31:55 -0800 | [diff] [blame] | 71 | parser.add_argument('-r', '--remote', metavar='REMOTE', |
| 72 | default='localhost', |
| 73 | help='hostname[:port] if the ADB device is connected ' |
| 74 | 'to a remote machine. Ensure this workstation ' |
| 75 | 'is configured for passwordless ssh access as ' |
| 76 | 'users "root" or "adb"') |
Gilad Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 77 | parser.add_argument('-i', '--interactive', action='store_true', |
| 78 | help='Enable interactive feedback requests from tests.') |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 79 | test_runner_utils.add_common_args(parser) |
| 80 | return parser.parse_args(argv) |
| 81 | |
| 82 | |
| 83 | def main(argv): |
| 84 | """ |
| 85 | Entry point for test_droid script. |
| 86 | |
| 87 | @param argv: arguments list |
| 88 | """ |
| 89 | arguments = _parse_arguments_internal(argv) |
| 90 | |
| 91 | results_directory = test_runner_utils.create_results_directory( |
| 92 | arguments.results_dir) |
| 93 | arguments.results_dir = results_directory |
| 94 | |
| 95 | autotest_path = os.path.dirname(os.path.dirname( |
| 96 | os.path.realpath(__file__))) |
| 97 | site_utils_path = os.path.join(autotest_path, 'site_utils') |
| 98 | realpath = os.path.realpath(__file__) |
| 99 | site_utils_path = os.path.realpath(site_utils_path) |
| 100 | host_attributes = {'serials' : arguments.serials, |
| 101 | 'os_type' : 'android'} |
| 102 | |
Gilad Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 103 | fb_service = None |
| 104 | try: |
| 105 | # Start the feedback service if needed. |
| 106 | if arguments.interactive: |
| 107 | fb_service = tester_feedback.FeedbackService() |
| 108 | fb_service.start() |
| 109 | |
| 110 | if arguments.args: |
| 111 | arguments.args += ' ' |
| 112 | else: |
| 113 | arguments.args = '' |
| 114 | arguments.args += ( |
| 115 | 'feedback=interactive feedback_args=localhost:%d' % |
| 116 | fb_service.server_port) |
| 117 | |
| 118 | return test_runner_utils.perform_run_from_autotest_root( |
| 119 | autotest_path, argv, arguments.tests, arguments.remote, |
| 120 | args=arguments.args, ignore_deps=not arguments.enforce_deps, |
| 121 | results_directory=results_directory, |
| 122 | iterations=arguments.iterations, |
| 123 | fast_mode=arguments.fast_mode, debug=arguments.debug, |
Simran Basi | 57740ca | 2016-02-19 11:20:22 -0800 | [diff] [blame^] | 124 | host_attributes=host_attributes, pretend=arguments.pretend) |
Gilad Arnold | a97d180 | 2016-01-27 18:20:14 -0800 | [diff] [blame] | 125 | finally: |
| 126 | if fb_service is not None: |
| 127 | fb_service.stop() |
Simran Basi | 14622bb | 2015-11-25 13:23:40 -0800 | [diff] [blame] | 128 | |
| 129 | |
| 130 | if __name__ == '__main__': |
| 131 | sys.exit(main(sys.argv[1:])) |