Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | # Copyright (c) 2013 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 |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 7 | import logging |
| 8 | import os |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 9 | import re |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 10 | import signal |
Aviv Keshet | c882440 | 2013-06-29 20:37:30 -0700 | [diff] [blame] | 11 | import stat |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 12 | import subprocess |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 13 | import sys |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 14 | import tempfile |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 15 | import threading |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 16 | |
| 17 | import common |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 18 | from autotest_lib.client.common_lib.cros import dev_server, retry |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 19 | from autotest_lib.server.cros.dynamic_suite import suite |
| 20 | from autotest_lib.server.cros.dynamic_suite import constants |
| 21 | from autotest_lib.server import autoserv_utils |
| 22 | |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 23 | try: |
| 24 | from chromite.lib import cros_build_lib |
| 25 | except ImportError: |
| 26 | print 'Unable to import chromite.' |
| 27 | print 'This script must be either:' |
| 28 | print ' - Be run in the chroot.' |
| 29 | print ' - (not yet supported) be run after running ' |
| 30 | print ' ../utils/build_externals.py' |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 31 | |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 32 | _autoserv_proc = None |
| 33 | _sigint_handler_lock = threading.Lock() |
| 34 | |
| 35 | _AUTOSERV_SIGINT_TIMEOUT_SECONDS = 5 |
Alex Miller | a091307 | 2013-06-12 10:01:51 -0700 | [diff] [blame] | 36 | _NO_BOARD = 'ad_hoc_board' |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 37 | _NO_BUILD = 'ad_hoc_build' |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 38 | |
Aviv Keshet | 2dc9893 | 2013-06-17 15:22:10 -0700 | [diff] [blame] | 39 | _QUICKMERGE_SCRIPTNAME = '/mnt/host/source/chromite/bin/autotest_quickmerge' |
| 40 | |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 41 | _TEST_REPORT_SCRIPTNAME = '/usr/bin/generate_test_report' |
| 42 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 43 | |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 44 | def schedule_local_suite(autotest_path, suite_name, afe, build=_NO_BUILD, |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 45 | board=_NO_BOARD, results_directory=None): |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 46 | """ |
| 47 | Schedule a suite against a mock afe object, for a local suite run. |
| 48 | @param autotest_path: Absolute path to autotest (in sysroot). |
| 49 | @param suite_name: Name of suite to schedule. |
| 50 | @param afe: afe object to schedule against (typically a directAFE) |
| 51 | @param build: Build to schedule suite for. |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 52 | @param board: Board to schedule suite for. |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 53 | @param results_directory: Absolute path of directory to store results in. |
| 54 | (results will be stored in subdirectory of this). |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 55 | @returns: The number of tests scheduled. |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 56 | """ |
| 57 | fs_getter = suite.Suite.create_fs_getter(autotest_path) |
| 58 | devserver = dev_server.ImageServer('') |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 59 | my_suite = suite.Suite.create_from_name(suite_name, build, board, |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 60 | devserver, fs_getter, afe=afe, ignore_deps=True, |
| 61 | results_dir=results_directory) |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 62 | if len(my_suite.tests) == 0: |
| 63 | raise ValueError('Suite named %s does not exist, or contains no ' |
| 64 | 'tests.' % suite_name) |
| 65 | my_suite.schedule(lambda x: None) # Schedule tests, discard record calls. |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 66 | return len(my_suite.tests) |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 67 | |
| 68 | |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 69 | def schedule_local_test(autotest_path, test_name, afe, build=_NO_BUILD, |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 70 | board=_NO_BOARD, results_directory=None): |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 71 | #temporarily disabling pylint |
| 72 | #pylint: disable-msg=C0111 |
| 73 | """ |
| 74 | Schedule an individual test against a mock afe object, for a local run. |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 75 | @param autotest_path: Absolute path to autotest (in sysroot). |
| 76 | @param test_name: Name of test to schedule. |
| 77 | @param afe: afe object to schedule against (typically a directAFE) |
| 78 | @param build: Build to schedule suite for. |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 79 | @param board: Board to schedule suite for. |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 80 | @param results_directory: Absolute path of directory to store results in. |
| 81 | (results will be stored in subdirectory of this). |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 82 | @returns: The number of tests scheduled (may be >1 if there are |
| 83 | multiple tests with the same name). |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 84 | """ |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 85 | fs_getter = suite.Suite.create_fs_getter(autotest_path) |
| 86 | devserver = dev_server.ImageServer('') |
| 87 | predicates = [suite.Suite.test_name_equals_predicate(test_name)] |
| 88 | suite_name = 'suite_' + test_name |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 89 | my_suite = suite.Suite.create_from_predicates(predicates, build, board, |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 90 | devserver, fs_getter, afe=afe, name=suite_name, ignore_deps=True, |
| 91 | results_dir=results_directory) |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 92 | if len(my_suite.tests) == 0: |
| 93 | raise ValueError('No tests named %s.' % test_name) |
| 94 | my_suite.schedule(lambda x: None) # Schedule tests, discard record calls. |
| 95 | return len(my_suite.tests) |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 96 | |
| 97 | |
Aviv Keshet | c882440 | 2013-06-29 20:37:30 -0700 | [diff] [blame] | 98 | def run_job(job, host, sysroot_autotest_path, results_directory): |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 99 | """ |
| 100 | Shell out to autoserv to run an individual test job. |
| 101 | |
| 102 | @param job: A Job object containing the control file contents and other |
| 103 | relevent metadata for this test. |
| 104 | @param host: Hostname of DUT to run test against. |
| 105 | @param sysroot_autotest_path: Absolute path of autotest directory. |
Aviv Keshet | c882440 | 2013-06-29 20:37:30 -0700 | [diff] [blame] | 106 | @param results_directory: Absolute path of directory to store results in. |
| 107 | (results will be stored in subdirectory of this). |
| 108 | @returns: Absolute path of directory where results were stored. |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 109 | """ |
| 110 | with tempfile.NamedTemporaryFile() as temp_file: |
| 111 | temp_file.write(job.control_file) |
| 112 | temp_file.flush() |
| 113 | |
Aviv Keshet | c882440 | 2013-06-29 20:37:30 -0700 | [diff] [blame] | 114 | results_directory = os.path.join(results_directory, |
| 115 | 'results-%s' % job.id) |
| 116 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 117 | command = autoserv_utils.autoserv_run_job_command( |
| 118 | os.path.join(sysroot_autotest_path, 'server'), |
| 119 | machines=host, job=job, verbose=False, |
Aviv Keshet | c882440 | 2013-06-29 20:37:30 -0700 | [diff] [blame] | 120 | results_directory=results_directory, |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 121 | extra_args=[temp_file.name]) |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 122 | global _autoserv_proc |
| 123 | _autoserv_proc = subprocess.Popen(command) |
| 124 | _autoserv_proc.wait() |
| 125 | _autoserv_proc = None |
Aviv Keshet | c882440 | 2013-06-29 20:37:30 -0700 | [diff] [blame] | 126 | return results_directory |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 127 | |
| 128 | |
| 129 | def setup_local_afe(): |
| 130 | """ |
| 131 | Setup a local afe database and return a direct_afe object to access it. |
| 132 | |
| 133 | @returns: A autotest_lib.frontend.afe.direct_afe instance. |
| 134 | """ |
| 135 | # This import statement is delayed until now rather than running at |
| 136 | # module load time, because it kicks off a local sqlite :memory: backed |
| 137 | # database, and we don't need that unless we are doing a local run. |
| 138 | from autotest_lib.frontend import setup_django_lite_environment |
| 139 | from autotest_lib.frontend.afe import direct_afe |
| 140 | return direct_afe.directAFE() |
| 141 | |
| 142 | |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 143 | def perform_local_run(afe, autotest_path, tests, remote, build=_NO_BUILD, |
| 144 | board=_NO_BOARD): |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 145 | """ |
| 146 | @param afe: A direct_afe object used to interact with local afe database. |
| 147 | @param autotest_path: Absolute path of sysroot installed autotest. |
| 148 | @param tests: List of strings naming tests and suites to run. Suite strings |
| 149 | should be formed like "suite:smoke". |
| 150 | @param remote: Remote hostname. |
| 151 | @param build: String specifying build for local run. |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 152 | @param board: String specifyinb board for local run. |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 153 | |
| 154 | @returns: directory in which results are stored. |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 155 | """ |
| 156 | afe.create_label(constants.VERSION_PREFIX + build) |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 157 | afe.create_label(board) |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 158 | afe.create_host(remote) |
| 159 | |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 160 | results_directory = tempfile.mkdtemp(prefix='test_that_results_') |
| 161 | os.chmod(results_directory, stat.S_IWOTH | stat.S_IROTH | stat.S_IXOTH) |
| 162 | logging.info('Running jobs. Results will be placed in %s', |
| 163 | results_directory) |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 164 | # Schedule tests / suites in local afe |
| 165 | for test in tests: |
| 166 | suitematch = re.match(r'suite:(.*)', test) |
| 167 | if suitematch: |
| 168 | suitename = suitematch.group(1) |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 169 | logging.info('Scheduling suite %s...', suitename) |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 170 | ntests = schedule_local_suite(autotest_path, suitename, afe, |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 171 | build=build, board=board, |
| 172 | results_directory=results_directory) |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 173 | else: |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 174 | logging.info('Scheduling test %s...', test) |
Aviv Keshet | 1071196 | 2013-06-24 12:20:33 -0700 | [diff] [blame] | 175 | ntests = schedule_local_test(autotest_path, test, afe, |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 176 | build=build, board=board, |
| 177 | results_directory=results_directory) |
Aviv Keshet | 69ebb6c | 2013-06-11 13:58:44 -0700 | [diff] [blame] | 178 | logging.info('... scheduled %s tests.', ntests) |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 179 | |
| 180 | for job in afe.get_jobs(): |
Aviv Keshet | c882440 | 2013-06-29 20:37:30 -0700 | [diff] [blame] | 181 | run_job(job, remote, autotest_path, results_directory) |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 182 | |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 183 | return results_directory |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 184 | |
| 185 | |
| 186 | def validate_arguments(arguments): |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 187 | """ |
| 188 | Validates parsed arguments. |
| 189 | |
| 190 | @param arguments: arguments object, as parsed by ParseArguments |
| 191 | @raises: ValueError if arguments were invalid. |
| 192 | """ |
| 193 | if arguments.args: |
| 194 | raise ValueError('--args flag not yet supported.') |
| 195 | |
| 196 | if not arguments.board: |
| 197 | raise ValueError('Board autodetection not yet supported. ' |
| 198 | '--board required.') |
| 199 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 200 | if arguments.remote == ':lab:': |
| 201 | raise ValueError('Running tests in test lab not yet supported.') |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 202 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 203 | |
| 204 | def parse_arguments(argv): |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 205 | """ |
| 206 | Parse command line arguments |
| 207 | |
| 208 | @param argv: argument list to parse |
| 209 | @returns: parsed arguments. |
| 210 | """ |
| 211 | parser = argparse.ArgumentParser(description='Run remote tests.') |
| 212 | |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 213 | parser.add_argument('remote', metavar='REMOTE', |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 214 | help='hostname[:port] for remote device. Specify ' |
| 215 | ':lab: to run in test lab, or :vm:PORT_NUMBER to ' |
| 216 | 'run in vm.') |
| 217 | parser.add_argument('tests', nargs='+', metavar='TEST', |
| 218 | help='Run given test(s). Use suite:SUITE to specify ' |
| 219 | 'test suite.') |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 220 | parser.add_argument('-b', '--board', metavar='BOARD', |
| 221 | action='store', |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 222 | help='Board for which the test will run.') |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 223 | parser.add_argument('-i', '--build', metavar='BUILD', |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 224 | help='Build to test. Device will be reimaged if ' |
| 225 | 'necessary. Omit flag to skip reimage and test ' |
| 226 | 'against already installed DUT image.') |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 227 | parser.add_argument('--args', metavar='ARGS', |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 228 | help='Argument string to pass through to test.') |
| 229 | |
| 230 | return parser.parse_args(argv) |
| 231 | |
| 232 | |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 233 | def sigint_handler(signum, stack_frame): |
| 234 | #pylint: disable-msg=C0111 |
| 235 | """Handle SIGINT or SIGTERM to a local test_that run. |
| 236 | |
| 237 | This handler sends a SIGINT to the running autoserv process, |
| 238 | if one is running, giving it up to 5 seconds to clean up and exit. After |
| 239 | the timeout elapses, autoserv is killed. In either case, after autoserv |
| 240 | exits then this process exits with status 1. |
| 241 | """ |
| 242 | # If multiple signals arrive before handler is unset, ignore duplicates |
| 243 | if not _sigint_handler_lock.acquire(False): |
| 244 | return |
| 245 | try: |
| 246 | # Ignore future signals by unsetting handler. |
| 247 | signal.signal(signal.SIGINT, signal.SIG_IGN) |
| 248 | signal.signal(signal.SIGTERM, signal.SIG_IGN) |
| 249 | |
| 250 | logging.warning('Received SIGINT or SIGTERM. Cleaning up and exiting.') |
| 251 | if _autoserv_proc: |
| 252 | logging.warning('Sending SIGINT to autoserv process. Waiting up ' |
| 253 | 'to %s seconds for cleanup.', |
| 254 | _AUTOSERV_SIGINT_TIMEOUT_SECONDS) |
| 255 | _autoserv_proc.send_signal(signal.SIGINT) |
| 256 | timed_out, _ = retry.timeout(_autoserv_proc.wait, |
| 257 | timeout_sec=_AUTOSERV_SIGINT_TIMEOUT_SECONDS) |
| 258 | if timed_out: |
| 259 | _autoserv_proc.kill() |
| 260 | logging.warning('Timed out waiting for autoserv to handle ' |
| 261 | 'SIGINT. Killed autoserv.') |
| 262 | finally: |
| 263 | _sigint_handler_lock.release() # this is not really necessary? |
| 264 | sys.exit(1) |
| 265 | |
| 266 | |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 267 | def main(argv): |
| 268 | """ |
| 269 | Entry point for test_that script. |
| 270 | @param argv: arguments list |
| 271 | """ |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 272 | if not cros_build_lib.IsInsideChroot(): |
| 273 | logging.error('Script must be invoked inside the chroot.') |
| 274 | return 1 |
| 275 | |
Aviv Keshet | 712128f | 2013-06-11 14:41:08 -0700 | [diff] [blame] | 276 | logging.getLogger('').setLevel(logging.INFO) |
| 277 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 278 | arguments = parse_arguments(argv) |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 279 | try: |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 280 | validate_arguments(arguments) |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 281 | except ValueError as err: |
| 282 | logging.error('Invalid arguments. %s', err.message) |
| 283 | return 1 |
| 284 | |
| 285 | # TODO: Determine the following string programatically. |
| 286 | # (same TODO applied to autotest_quickmerge) |
| 287 | sysroot_path = os.path.join('/build', arguments.board, '') |
| 288 | sysroot_autotest_path = os.path.join(sysroot_path, 'usr', 'local', |
| 289 | 'autotest', '') |
| 290 | sysroot_site_utils_path = os.path.join(sysroot_autotest_path, |
| 291 | 'site_utils') |
| 292 | |
| 293 | if not os.path.exists(sysroot_path): |
| 294 | logging.error('%s does not exist. Have you run setup_board?', |
| 295 | sysroot_path) |
| 296 | return 1 |
| 297 | if not os.path.exists(sysroot_autotest_path): |
| 298 | logging.error('%s does not exist. Have you run build_packages?', |
| 299 | sysroot_autotest_path) |
| 300 | return 1 |
| 301 | |
Aviv Keshet | 2dc9893 | 2013-06-17 15:22:10 -0700 | [diff] [blame] | 302 | # If we are not running the sysroot version of script, perform |
| 303 | # a quickmerge if necessary and then re-execute |
| 304 | # the sysroot version of script with the same arguments. |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 305 | realpath = os.path.realpath(__file__) |
| 306 | if os.path.dirname(realpath) != sysroot_site_utils_path: |
Aviv Keshet | 2dc9893 | 2013-06-17 15:22:10 -0700 | [diff] [blame] | 307 | subprocess.call([_QUICKMERGE_SCRIPTNAME, '--board='+arguments.board]) |
| 308 | |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 309 | script_command = os.path.join(sysroot_site_utils_path, |
| 310 | os.path.basename(realpath)) |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 311 | proc = None |
| 312 | def resend_sig(signum, stack_frame): |
| 313 | #pylint: disable-msg=C0111 |
| 314 | if proc: |
| 315 | proc.send_signal(signum) |
| 316 | signal.signal(signal.SIGINT, resend_sig) |
| 317 | signal.signal(signal.SIGTERM, resend_sig) |
| 318 | |
| 319 | proc = subprocess.Popen([script_command] + argv) |
| 320 | |
| 321 | return proc.wait() |
Aviv Keshet | 0e5d525 | 2013-04-26 16:01:36 -0700 | [diff] [blame] | 322 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 323 | # Hard coded to True temporarily. This will eventually be parsed to false |
| 324 | # if we are doing a run in the test lab. |
| 325 | local_run = True |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 326 | |
Aviv Keshet | 1d991ea | 2013-06-12 17:24:23 -0700 | [diff] [blame] | 327 | signal.signal(signal.SIGINT, sigint_handler) |
| 328 | signal.signal(signal.SIGTERM, sigint_handler) |
| 329 | |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 330 | if local_run: |
| 331 | afe = setup_local_afe() |
Aviv Keshet | ba4992a | 2013-07-02 14:09:23 -0700 | [diff] [blame^] | 332 | res_dir= perform_local_run(afe, sysroot_autotest_path, arguments.tests, |
| 333 | arguments.remote) |
| 334 | return subprocess.call([_TEST_REPORT_SCRIPTNAME, res_dir]) |
| 335 | |
Aviv Keshet | 021c19f | 2013-02-22 13:19:43 -0800 | [diff] [blame] | 336 | |
| 337 | if __name__ == '__main__': |
Aviv Keshet | d4a0430 | 2013-04-30 15:48:30 -0700 | [diff] [blame] | 338 | sys.exit(main(sys.argv[1:])) |