maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
maruel | ea586f3 | 2016-04-05 11:11:33 -0700 | [diff] [blame] | 2 | # Copyright 2012 The LUCI Authors. All rights reserved. |
| 3 | # Use of this source code is governed by the Apache v2.0 license that can be |
| 4 | # found in the LICENSE file. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 5 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 6 | """Runs a command with optional isolated input/output. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 7 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 8 | Despite name "run_isolated", can run a generic non-isolated command specified as |
| 9 | args. |
| 10 | |
| 11 | If input isolated hash is provided, fetches it, creates a tree of hard links, |
| 12 | appends args to the command in the fetched isolated and runs it. |
| 13 | To improve performance, keeps a local cache. |
| 14 | The local cache can safely be deleted. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 15 | |
| 16 | Any ${ISOLATED_OUTDIR} on the command line will be replaced by the location of a |
| 17 | temporary directory upon execution of the command specified in the .isolated |
| 18 | file. All content written to this directory will be uploaded upon termination |
| 19 | and the .isolated file describing this directory will be printed to stdout. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 20 | """ |
| 21 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 22 | __version__ = '0.7.0' |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 23 | |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 24 | import base64 |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 25 | import logging |
| 26 | import optparse |
| 27 | import os |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 28 | import sys |
| 29 | import tempfile |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 30 | import time |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 31 | |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 32 | from third_party.depot_tools import fix_encoding |
| 33 | |
Vadim Shtayura | 6b555c1 | 2014-07-23 16:22:18 -0700 | [diff] [blame] | 34 | from utils import file_path |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 35 | from utils import fs |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 36 | from utils import large |
Marc-Antoine Ruel | f74cffe | 2015-07-15 15:21:34 -0400 | [diff] [blame] | 37 | from utils import logging_utils |
Marc-Antoine Ruel | cfb6085 | 2014-07-02 15:22:00 -0400 | [diff] [blame] | 38 | from utils import on_error |
Marc-Antoine Ruel | c44f572 | 2015-01-08 16:10:01 -0500 | [diff] [blame] | 39 | from utils import subprocess42 |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 40 | from utils import tools |
vadimsh@chromium.org | 3e97deb | 2013-08-24 00:56:44 +0000 | [diff] [blame] | 41 | from utils import zip_package |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 42 | |
Vadim Shtayura | e34e13a | 2014-02-02 11:23:26 -0800 | [diff] [blame] | 43 | import auth |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 44 | import isolateserver |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 45 | |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 46 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 47 | ISOLATED_OUTDIR_PARAMETER = '${ISOLATED_OUTDIR}' |
| 48 | |
vadimsh@chromium.org | 8507106 | 2013-08-21 23:37:45 +0000 | [diff] [blame] | 49 | # Absolute path to this file (can be None if running from zip on Mac). |
| 50 | THIS_FILE_PATH = os.path.abspath(__file__) if __file__ else None |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 51 | |
| 52 | # Directory that contains this file (might be inside zip package). |
vadimsh@chromium.org | 8507106 | 2013-08-21 23:37:45 +0000 | [diff] [blame] | 53 | BASE_DIR = os.path.dirname(THIS_FILE_PATH) if __file__ else None |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 54 | |
| 55 | # Directory that contains currently running script file. |
maruel@chromium.org | 814d23f | 2013-10-01 19:08:00 +0000 | [diff] [blame] | 56 | if zip_package.get_main_script_path(): |
| 57 | MAIN_DIR = os.path.dirname( |
| 58 | os.path.abspath(zip_package.get_main_script_path())) |
| 59 | else: |
| 60 | # This happens when 'import run_isolated' is executed at the python |
| 61 | # interactive prompt, in that case __file__ is undefined. |
| 62 | MAIN_DIR = None |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 63 | |
csharp@chromium.org | ff2a466 | 2012-11-21 20:49:32 +0000 | [diff] [blame] | 64 | # The name of the log file to use. |
| 65 | RUN_ISOLATED_LOG_FILE = 'run_isolated.log' |
| 66 | |
csharp@chromium.org | e217f30 | 2012-11-22 16:51:53 +0000 | [diff] [blame] | 67 | # The name of the log to use for the run_test_cases.py command |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 68 | RUN_TEST_CASES_LOG = 'run_test_cases.log' |
csharp@chromium.org | e217f30 | 2012-11-22 16:51:53 +0000 | [diff] [blame] | 69 | |
vadimsh@chromium.org | 87d6326 | 2013-04-04 19:34:21 +0000 | [diff] [blame] | 70 | |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 71 | def get_as_zip_package(executable=True): |
| 72 | """Returns ZipPackage with this module and all its dependencies. |
| 73 | |
| 74 | If |executable| is True will store run_isolated.py as __main__.py so that |
| 75 | zip package is directly executable be python. |
| 76 | """ |
| 77 | # Building a zip package when running from another zip package is |
| 78 | # unsupported and probably unneeded. |
| 79 | assert not zip_package.is_zipped_module(sys.modules[__name__]) |
vadimsh@chromium.org | 8507106 | 2013-08-21 23:37:45 +0000 | [diff] [blame] | 80 | assert THIS_FILE_PATH |
| 81 | assert BASE_DIR |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 82 | package = zip_package.ZipPackage(root=BASE_DIR) |
| 83 | package.add_python_file(THIS_FILE_PATH, '__main__.py' if executable else None) |
Marc-Antoine Ruel | 8bee66d | 2014-08-28 19:02:07 -0400 | [diff] [blame] | 84 | package.add_python_file(os.path.join(BASE_DIR, 'isolated_format.py')) |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 85 | package.add_python_file(os.path.join(BASE_DIR, 'isolateserver.py')) |
Vadim Shtayura | e34e13a | 2014-02-02 11:23:26 -0800 | [diff] [blame] | 86 | package.add_python_file(os.path.join(BASE_DIR, 'auth.py')) |
vadimsh@chromium.org | 8b9d56b | 2013-08-21 22:24:35 +0000 | [diff] [blame] | 87 | package.add_directory(os.path.join(BASE_DIR, 'third_party')) |
| 88 | package.add_directory(os.path.join(BASE_DIR, 'utils')) |
| 89 | return package |
| 90 | |
| 91 | |
Vadim Shtayura | cb0b743 | 2015-07-31 13:26:50 -0700 | [diff] [blame] | 92 | def make_temp_dir(prefix, root_dir=None): |
| 93 | """Returns a temporary directory. |
| 94 | |
| 95 | If root_dir is given and /tmp is on same file system as root_dir, uses /tmp. |
| 96 | Otherwise makes a new temp directory under root_dir. |
maruel | 79d5e06 | 2016-04-08 13:39:57 -0700 | [diff] [blame] | 97 | |
| 98 | Except on OSX, because it's dangerous to create hardlinks in $TMPDIR on OSX! |
| 99 | /System/Library/LaunchDaemons/com.apple.bsd.dirhelper.plist runs every day at |
| 100 | 3:35am and deletes all files older than 3 days in $TMPDIR, but hardlinks do |
| 101 | not have the inode modification time updated, so they tend to be old, thus |
| 102 | they get deleted. |
Vadim Shtayura | cb0b743 | 2015-07-31 13:26:50 -0700 | [diff] [blame] | 103 | """ |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 104 | base_temp_dir = None |
maruel | 79d5e06 | 2016-04-08 13:39:57 -0700 | [diff] [blame] | 105 | real_temp_dir = unicode(tempfile.gettempdir()) |
| 106 | if sys.platform == 'darwin': |
| 107 | # Nope! Nope! Nope! |
| 108 | assert root_dir, 'It is unsafe to create hardlinks in $TMPDIR' |
| 109 | base_temp_dir = root_dir |
| 110 | elif root_dir and not file_path.is_same_filesystem(root_dir, real_temp_dir): |
Paweł Hajdan, Jr | f7d5872 | 2015-04-27 14:54:42 +0200 | [diff] [blame] | 111 | base_temp_dir = root_dir |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 112 | return unicode(tempfile.mkdtemp(prefix=prefix, dir=base_temp_dir)) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 113 | |
| 114 | |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 115 | def change_tree_read_only(rootdir, read_only): |
| 116 | """Changes the tree read-only bits according to the read_only specification. |
| 117 | |
| 118 | The flag can be 0, 1 or 2, which will affect the possibility to modify files |
| 119 | and create or delete files. |
| 120 | """ |
| 121 | if read_only == 2: |
| 122 | # Files and directories (except on Windows) are marked read only. This |
| 123 | # inhibits modifying, creating or deleting files in the test directory, |
| 124 | # except on Windows where creating and deleting files is still possible. |
Marc-Antoine Ruel | e4ad07e | 2014-10-15 20:22:29 -0400 | [diff] [blame] | 125 | file_path.make_tree_read_only(rootdir) |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 126 | elif read_only == 1: |
| 127 | # Files are marked read only but not the directories. This inhibits |
| 128 | # modifying files but creating or deleting files is still possible. |
Marc-Antoine Ruel | e4ad07e | 2014-10-15 20:22:29 -0400 | [diff] [blame] | 129 | file_path.make_tree_files_read_only(rootdir) |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 130 | elif read_only in (0, None): |
Marc-Antoine Ruel | f1d827c | 2014-11-24 15:22:25 -0500 | [diff] [blame] | 131 | # Anything can be modified. |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 132 | # TODO(maruel): This is currently dangerous as long as DiskCache.touch() |
| 133 | # is not yet changed to verify the hash of the content of the files it is |
| 134 | # looking at, so that if a test modifies an input file, the file must be |
| 135 | # deleted. |
Marc-Antoine Ruel | e4ad07e | 2014-10-15 20:22:29 -0400 | [diff] [blame] | 136 | file_path.make_tree_writeable(rootdir) |
Marc-Antoine Ruel | 7124e39 | 2014-01-09 11:49:21 -0500 | [diff] [blame] | 137 | else: |
| 138 | raise ValueError( |
| 139 | 'change_tree_read_only(%s, %s): Unknown flag %s' % |
| 140 | (rootdir, read_only, read_only)) |
| 141 | |
| 142 | |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 143 | def process_command(command, out_dir): |
| 144 | """Replaces isolated specific variables in a command line.""" |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 145 | def fix(arg): |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 146 | if ISOLATED_OUTDIR_PARAMETER in arg: |
| 147 | arg = arg.replace(ISOLATED_OUTDIR_PARAMETER, out_dir) |
| 148 | # Replace slashes only if ISOLATED_OUTDIR_PARAMETER is present |
| 149 | # because of arguments like '${ISOLATED_OUTDIR}/foo/bar' |
| 150 | arg = arg.replace('/', os.sep) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 151 | return arg |
| 152 | |
| 153 | return [fix(arg) for arg in command] |
| 154 | |
| 155 | |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 156 | def run_command(command, cwd, tmp_dir, hard_timeout, grace_period): |
| 157 | """Runs the command. |
| 158 | |
| 159 | Returns: |
| 160 | tuple(process exit code, bool if had a hard timeout) |
| 161 | """ |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 162 | logging.info('run_command(%s, %s)' % (command, cwd)) |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 163 | |
| 164 | env = os.environ.copy() |
| 165 | if sys.platform == 'darwin': |
| 166 | env['TMPDIR'] = tmp_dir.encode('ascii') |
| 167 | elif sys.platform == 'win32': |
maruel | df2329b | 2016-01-19 15:33:23 -0800 | [diff] [blame] | 168 | env['TEMP'] = tmp_dir.encode('ascii') |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 169 | else: |
| 170 | env['TMP'] = tmp_dir.encode('ascii') |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 171 | exit_code = None |
| 172 | had_hard_timeout = False |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 173 | with tools.Profiler('RunTest'): |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 174 | proc = None |
| 175 | had_signal = [] |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 176 | try: |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 177 | # TODO(maruel): This code is imperfect. It doesn't handle well signals |
| 178 | # during the download phase and there's short windows were things can go |
| 179 | # wrong. |
| 180 | def handler(signum, _frame): |
| 181 | if proc and not had_signal: |
| 182 | logging.info('Received signal %d', signum) |
| 183 | had_signal.append(True) |
maruel | 556d905 | 2015-10-05 11:12:44 -0700 | [diff] [blame] | 184 | raise subprocess42.TimeoutExpired(command, None) |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 185 | |
| 186 | proc = subprocess42.Popen(command, cwd=cwd, env=env, detached=True) |
| 187 | with subprocess42.set_signal_handler(subprocess42.STOP_SIGNALS, handler): |
| 188 | try: |
| 189 | exit_code = proc.wait(hard_timeout or None) |
| 190 | except subprocess42.TimeoutExpired: |
| 191 | if not had_signal: |
| 192 | logging.warning('Hard timeout') |
| 193 | had_hard_timeout = True |
| 194 | logging.warning('Sending SIGTERM') |
| 195 | proc.terminate() |
| 196 | |
| 197 | # Ignore signals in grace period. Forcibly give the grace period to the |
| 198 | # child process. |
| 199 | if exit_code is None: |
| 200 | ignore = lambda *_: None |
| 201 | with subprocess42.set_signal_handler(subprocess42.STOP_SIGNALS, ignore): |
| 202 | try: |
| 203 | exit_code = proc.wait(grace_period or None) |
| 204 | except subprocess42.TimeoutExpired: |
| 205 | # Now kill for real. The user can distinguish between the |
| 206 | # following states: |
| 207 | # - signal but process exited within grace period, |
| 208 | # hard_timed_out will be set but the process exit code will be |
| 209 | # script provided. |
| 210 | # - processed exited late, exit code will be -9 on posix. |
| 211 | logging.warning('Grace exhausted; sending SIGKILL') |
| 212 | proc.kill() |
| 213 | logging.info('Waiting for proces exit') |
| 214 | exit_code = proc.wait() |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 215 | except OSError: |
| 216 | # This is not considered to be an internal error. The executable simply |
| 217 | # does not exit. |
maruel | a72f46e | 2016-02-24 11:05:45 -0800 | [diff] [blame] | 218 | sys.stderr.write( |
| 219 | '<The executable does not exist or a dependent library is missing>\n' |
| 220 | '<Check for missing .so/.dll in the .isolate or GN file>\n' |
| 221 | '<Command: %s>\n' % command) |
| 222 | if os.environ.get('SWARMING_TASK_ID'): |
| 223 | # Give an additional hint when running as a swarming task. |
| 224 | sys.stderr.write( |
| 225 | '<See the task\'s page for commands to help diagnose this issue ' |
| 226 | 'by reproducing the task locally>\n') |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 227 | exit_code = 1 |
| 228 | logging.info( |
| 229 | 'Command finished with exit code %d (%s)', |
| 230 | exit_code, hex(0xffffffff & exit_code)) |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 231 | return exit_code, had_hard_timeout |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 232 | |
| 233 | |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 234 | def fetch_and_measure(isolated_hash, storage, cache, outdir): |
| 235 | """Fetches an isolated and returns (bundle, stats).""" |
| 236 | start = time.time() |
| 237 | bundle = isolateserver.fetch_isolated( |
| 238 | isolated_hash=isolated_hash, |
| 239 | storage=storage, |
| 240 | cache=cache, |
| 241 | outdir=outdir) |
| 242 | return bundle, { |
| 243 | 'duration': time.time() - start, |
| 244 | 'initial_number_items': cache.initial_number_items, |
| 245 | 'initial_size': cache.initial_size, |
| 246 | 'items_cold': base64.b64encode(large.pack(sorted(cache.added))), |
| 247 | 'items_hot': base64.b64encode( |
| 248 | large.pack(sorted(set(cache.linked) - set(cache.added)))), |
| 249 | } |
| 250 | |
| 251 | |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 252 | def delete_and_upload(storage, out_dir, leak_temp_dir): |
| 253 | """Deletes the temporary run directory and uploads results back. |
| 254 | |
| 255 | Returns: |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 256 | tuple(outputs_ref, success, stats) |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 257 | - outputs_ref: a dict referring to the results archived back to the isolated |
| 258 | server, if applicable. |
| 259 | - success: False if something occurred that means that the task must |
| 260 | forcibly be considered a failure, e.g. zombie processes were left |
| 261 | behind. |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 262 | - stats: uploading stats. |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 263 | """ |
| 264 | |
| 265 | # Upload out_dir and generate a .isolated file out of this directory. It is |
| 266 | # only done if files were written in the directory. |
| 267 | outputs_ref = None |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 268 | cold = [] |
| 269 | hot = [] |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 270 | start = time.time() |
| 271 | |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 272 | if fs.isdir(out_dir) and fs.listdir(out_dir): |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 273 | with tools.Profiler('ArchiveOutput'): |
| 274 | try: |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 275 | results, f_cold, f_hot = isolateserver.archive_files_to_storage( |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 276 | storage, [out_dir], None) |
| 277 | outputs_ref = { |
| 278 | 'isolated': results[0][0], |
| 279 | 'isolatedserver': storage.location, |
| 280 | 'namespace': storage.namespace, |
| 281 | } |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 282 | cold = sorted(i.size for i in f_cold) |
| 283 | hot = sorted(i.size for i in f_hot) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 284 | except isolateserver.Aborted: |
| 285 | # This happens when a signal SIGTERM was received while uploading data. |
| 286 | # There is 2 causes: |
| 287 | # - The task was too slow and was about to be killed anyway due to |
| 288 | # exceeding the hard timeout. |
| 289 | # - The amount of data uploaded back is very large and took too much |
| 290 | # time to archive. |
| 291 | sys.stderr.write('Received SIGTERM while uploading') |
| 292 | # Re-raise, so it will be treated as an internal failure. |
| 293 | raise |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 294 | |
| 295 | success = False |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 296 | try: |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 297 | if (not leak_temp_dir and fs.isdir(out_dir) and |
maruel | 6eeea7d | 2015-09-16 12:17:42 -0700 | [diff] [blame] | 298 | not file_path.rmtree(out_dir)): |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 299 | logging.error('Had difficulties removing out_dir %s', out_dir) |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 300 | else: |
| 301 | success = True |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 302 | except OSError as e: |
| 303 | # When this happens, it means there's a process error. |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 304 | logging.exception('Had difficulties removing out_dir %s: %s', out_dir, e) |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 305 | stats = { |
| 306 | 'duration': time.time() - start, |
| 307 | 'items_cold': base64.b64encode(large.pack(cold)), |
| 308 | 'items_hot': base64.b64encode(large.pack(hot)), |
| 309 | } |
| 310 | return outputs_ref, success, stats |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 311 | |
| 312 | |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 313 | def map_and_run( |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 314 | command, isolated_hash, storage, cache, leak_temp_dir, root_dir, |
| 315 | hard_timeout, grace_period, extra_args): |
| 316 | """Runs a command with optional isolated input/output. |
| 317 | |
| 318 | See run_tha_test for argument documentation. |
| 319 | |
| 320 | Returns metadata about the result. |
| 321 | """ |
| 322 | assert bool(command) ^ bool(isolated_hash) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 323 | result = { |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 324 | 'duration': None, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 325 | 'exit_code': None, |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 326 | 'had_hard_timeout': False, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 327 | 'internal_failure': None, |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 328 | 'stats': { |
| 329 | # 'download': { |
| 330 | # 'duration': 0., |
| 331 | # 'initial_number_items': 0, |
| 332 | # 'initial_size': 0, |
| 333 | # 'items_cold': '<large.pack()>', |
| 334 | # 'items_hot': '<large.pack()>', |
| 335 | # }, |
| 336 | # 'upload': { |
| 337 | # 'duration': 0., |
| 338 | # 'items_cold': '<large.pack()>', |
| 339 | # 'items_hot': '<large.pack()>', |
| 340 | # }, |
| 341 | }, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 342 | 'outputs_ref': None, |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 343 | 'version': 3, |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 344 | } |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 345 | if root_dir: |
nodir | e5028a9 | 2016-04-29 14:38:21 -0700 | [diff] [blame] | 346 | file_path.ensure_tree(root_dir, 0700) |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 347 | prefix = u'' |
| 348 | else: |
| 349 | root_dir = os.path.dirname(cache.cache_dir) if cache.cache_dir else None |
| 350 | prefix = u'isolated_' |
| 351 | run_dir = make_temp_dir(prefix + u'run', root_dir) |
| 352 | out_dir = make_temp_dir(prefix + u'out', root_dir) |
| 353 | tmp_dir = make_temp_dir(prefix + u'tmp', root_dir) |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 354 | cwd = run_dir |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 355 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 356 | try: |
| 357 | if isolated_hash: |
| 358 | bundle, result['stats']['download'] = fetch_and_measure( |
| 359 | isolated_hash=isolated_hash, |
| 360 | storage=storage, |
| 361 | cache=cache, |
| 362 | outdir=run_dir) |
| 363 | if not bundle.command: |
| 364 | # Handle this as a task failure, not an internal failure. |
| 365 | sys.stderr.write( |
| 366 | '<The .isolated doesn\'t declare any command to run!>\n' |
| 367 | '<Check your .isolate for missing \'command\' variable>\n') |
| 368 | if os.environ.get('SWARMING_TASK_ID'): |
| 369 | # Give an additional hint when running as a swarming task. |
| 370 | sys.stderr.write('<This occurs at the \'isolate\' step>\n') |
| 371 | result['exit_code'] = 1 |
| 372 | return result |
| 373 | |
| 374 | change_tree_read_only(run_dir, bundle.read_only) |
| 375 | cwd = os.path.normpath(os.path.join(cwd, bundle.relative_cwd)) |
| 376 | command = bundle.command + extra_args |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 377 | file_path.ensure_command_has_abs_path(command, cwd) |
maruel | 064c0a3 | 2016-04-05 11:47:15 -0700 | [diff] [blame] | 378 | sys.stdout.flush() |
| 379 | start = time.time() |
| 380 | try: |
| 381 | result['exit_code'], result['had_hard_timeout'] = run_command( |
| 382 | process_command(command, out_dir), cwd, tmp_dir, hard_timeout, |
| 383 | grace_period) |
| 384 | finally: |
| 385 | result['duration'] = max(time.time() - start, 0) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 386 | except Exception as e: |
| 387 | # An internal error occured. Report accordingly so the swarming task will be |
| 388 | # retried automatically. |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 389 | logging.exception('internal failure: %s', e) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 390 | result['internal_failure'] = str(e) |
| 391 | on_error.report(None) |
| 392 | finally: |
| 393 | try: |
| 394 | if leak_temp_dir: |
| 395 | logging.warning( |
| 396 | 'Deliberately leaking %s for later examination', run_dir) |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 397 | else: |
maruel | 84537cb | 2015-10-16 14:21:28 -0700 | [diff] [blame] | 398 | # On Windows rmtree(run_dir) call above has a synchronization effect: it |
| 399 | # finishes only when all task child processes terminate (since a running |
| 400 | # process locks *.exe file). Examine out_dir only after that call |
| 401 | # completes (since child processes may write to out_dir too and we need |
| 402 | # to wait for them to finish). |
| 403 | if fs.isdir(run_dir): |
| 404 | try: |
| 405 | success = file_path.rmtree(run_dir) |
| 406 | except OSError as e: |
| 407 | logging.error('Failure with %s', e) |
| 408 | success = False |
| 409 | if not success: |
| 410 | print >> sys.stderr, ( |
| 411 | 'Failed to delete the run directory, forcibly failing\n' |
| 412 | 'the task because of it. No zombie process can outlive a\n' |
| 413 | 'successful task run and still be marked as successful.\n' |
| 414 | 'Fix your stuff.') |
| 415 | if result['exit_code'] == 0: |
| 416 | result['exit_code'] = 1 |
| 417 | if fs.isdir(tmp_dir): |
| 418 | try: |
| 419 | success = file_path.rmtree(tmp_dir) |
| 420 | except OSError as e: |
| 421 | logging.error('Failure with %s', e) |
| 422 | success = False |
| 423 | if not success: |
| 424 | print >> sys.stderr, ( |
| 425 | 'Failed to delete the temporary directory, forcibly failing\n' |
| 426 | 'the task because of it. No zombie process can outlive a\n' |
| 427 | 'successful task run and still be marked as successful.\n' |
| 428 | 'Fix your stuff.') |
| 429 | if result['exit_code'] == 0: |
| 430 | result['exit_code'] = 1 |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 431 | |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 432 | # This deletes out_dir if leak_temp_dir is not set. |
nodir | 6f80188 | 2016-04-29 14:41:50 -0700 | [diff] [blame] | 433 | result['outputs_ref'], success, result['stats']['upload'] = ( |
| 434 | delete_and_upload(storage, out_dir, leak_temp_dir)) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 435 | if not success and result['exit_code'] == 0: |
| 436 | result['exit_code'] = 1 |
| 437 | except Exception as e: |
| 438 | # Swallow any exception in the main finally clause. |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 439 | logging.exception('Leaking out_dir %s: %s', out_dir, e) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 440 | result['internal_failure'] = str(e) |
| 441 | return result |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 442 | |
| 443 | |
Marc-Antoine Ruel | 0ec868b | 2015-08-12 14:12:46 -0400 | [diff] [blame] | 444 | def run_tha_test( |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 445 | command, isolated_hash, storage, cache, leak_temp_dir, result_json, |
| 446 | root_dir, hard_timeout, grace_period, extra_args): |
| 447 | """Runs an executable and records execution metadata. |
| 448 | |
| 449 | Either command or isolated_hash must be specified. |
| 450 | |
| 451 | If isolated_hash is specified, downloads the dependencies in the cache, |
| 452 | hardlinks them into a temporary directory and runs the command specified in |
| 453 | the .isolated. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 454 | |
| 455 | A temporary directory is created to hold the output files. The content inside |
| 456 | this directory will be uploaded back to |storage| packaged as a .isolated |
| 457 | file. |
| 458 | |
| 459 | Arguments: |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 460 | command: the command to run, a list of strings. Mutually exclusive with |
| 461 | isolated_hash. |
Marc-Antoine Ruel | 35b5843 | 2014-12-08 17:40:40 -0500 | [diff] [blame] | 462 | isolated_hash: the SHA-1 of the .isolated file that must be retrieved to |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 463 | recreate the tree of files to run the target executable. |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 464 | The command specified in the .isolated is executed. |
| 465 | Mutually exclusive with command argument. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 466 | storage: an isolateserver.Storage object to retrieve remote objects. This |
| 467 | object has a reference to an isolateserver.StorageApi, which does |
| 468 | the actual I/O. |
| 469 | cache: an isolateserver.LocalCache to keep from retrieving the same objects |
| 470 | constantly by caching the objects retrieved. Can be on-disk or |
| 471 | in-memory. |
Kenneth Russell | 61d4235 | 2014-09-15 11:41:16 -0700 | [diff] [blame] | 472 | leak_temp_dir: if true, the temporary directory will be deliberately leaked |
| 473 | for later examination. |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 474 | result_json: file path to dump result metadata into. If set, the process |
| 475 | exit code is always 0 unless an internal error occured. |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 476 | root_dir: directory to the path to use to create the temporary directory. If |
| 477 | not specified, a random temporary directory is created. |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 478 | hard_timeout: kills the process if it lasts more than this amount of |
| 479 | seconds. |
| 480 | grace_period: number of seconds to wait between SIGTERM and SIGKILL. |
Marc-Antoine Ruel | 2283ad1 | 2014-02-09 11:14:57 -0500 | [diff] [blame] | 481 | extra_args: optional arguments to add to the command stated in the .isolate |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 482 | file. Ignored if isolate_hash is empty. |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 483 | |
| 484 | Returns: |
| 485 | Process exit code that should be used. |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 486 | """ |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 487 | assert bool(command) ^ bool(isolated_hash) |
| 488 | extra_args = extra_args or [] |
| 489 | if any(ISOLATED_OUTDIR_PARAMETER in a for a in (command or extra_args)): |
| 490 | assert storage is not None, 'storage is None although outdir is specified' |
| 491 | |
maruel | a76b9ee | 2015-12-15 06:18:08 -0800 | [diff] [blame] | 492 | if result_json: |
| 493 | # Write a json output file right away in case we get killed. |
| 494 | result = { |
| 495 | 'exit_code': None, |
| 496 | 'had_hard_timeout': False, |
| 497 | 'internal_failure': 'Was terminated before completion', |
| 498 | 'outputs_ref': None, |
| 499 | 'version': 2, |
| 500 | } |
| 501 | tools.write_json(result_json, result, dense=True) |
| 502 | |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 503 | # run_isolated exit code. Depends on if result_json is used or not. |
| 504 | result = map_and_run( |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 505 | command, isolated_hash, storage, cache, leak_temp_dir, root_dir, |
| 506 | hard_timeout, grace_period, extra_args) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 507 | logging.info('Result:\n%s', tools.format_json(result, dense=True)) |
| 508 | if result_json: |
maruel | 05d5a88 | 2015-09-21 13:59:02 -0700 | [diff] [blame] | 509 | # We've found tests to delete 'work' when quitting, causing an exception |
| 510 | # here. Try to recreate the directory if necessary. |
nodir | e5028a9 | 2016-04-29 14:38:21 -0700 | [diff] [blame] | 511 | file_path.ensure_tree(os.path.dirname(result_json)) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 512 | tools.write_json(result_json, result, dense=True) |
| 513 | # Only return 1 if there was an internal error. |
| 514 | return int(bool(result['internal_failure'])) |
maruel@chromium.org | 781ccf6 | 2013-09-17 19:39:47 +0000 | [diff] [blame] | 515 | |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 516 | # Marshall into old-style inline output. |
| 517 | if result['outputs_ref']: |
| 518 | data = { |
| 519 | 'hash': result['outputs_ref']['isolated'], |
| 520 | 'namespace': result['outputs_ref']['namespace'], |
| 521 | 'storage': result['outputs_ref']['isolatedserver'], |
| 522 | } |
Marc-Antoine Ruel | c44f572 | 2015-01-08 16:10:01 -0500 | [diff] [blame] | 523 | sys.stdout.flush() |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 524 | print( |
| 525 | '[run_isolated_out_hack]%s[/run_isolated_out_hack]' % |
| 526 | tools.format_json(data, dense=True)) |
maruel | b76604c | 2015-11-11 11:53:44 -0800 | [diff] [blame] | 527 | sys.stdout.flush() |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 528 | return result['exit_code'] or int(bool(result['internal_failure'])) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 529 | |
| 530 | |
Marc-Antoine Ruel | 90c9816 | 2013-12-18 15:11:57 -0500 | [diff] [blame] | 531 | def main(args): |
Marc-Antoine Ruel | f74cffe | 2015-07-15 15:21:34 -0400 | [diff] [blame] | 532 | parser = logging_utils.OptionParserWithLogging( |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 533 | usage='%prog <options> [command to run or extra args]', |
maruel@chromium.org | dedbf49 | 2013-09-12 20:42:11 +0000 | [diff] [blame] | 534 | version=__version__, |
| 535 | log_file=RUN_ISOLATED_LOG_FILE) |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 536 | parser.add_option( |
maruel | 36a963d | 2016-04-08 17:15:49 -0700 | [diff] [blame] | 537 | '--clean', action='store_true', |
| 538 | help='Cleans the cache, trimming it necessary and remove corrupted items ' |
| 539 | 'and returns without executing anything; use with -v to know what ' |
| 540 | 'was done') |
| 541 | parser.add_option( |
maruel | a9cfd6f | 2015-09-15 11:03:15 -0700 | [diff] [blame] | 542 | '--json', |
| 543 | help='dump output metadata to json file. When used, run_isolated returns ' |
| 544 | 'non-zero only on internal failure') |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 545 | parser.add_option( |
maruel | 5c9e47b | 2015-12-18 13:02:30 -0800 | [diff] [blame] | 546 | '--hard-timeout', type='float', help='Enforce hard timeout in execution') |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 547 | parser.add_option( |
maruel | 5c9e47b | 2015-12-18 13:02:30 -0800 | [diff] [blame] | 548 | '--grace-period', type='float', |
maruel | 6be7f9e | 2015-10-01 12:25:30 -0700 | [diff] [blame] | 549 | help='Grace period between SIGTERM and SIGKILL') |
Marc-Antoine Ruel | 1687b5e | 2014-02-06 17:47:53 -0500 | [diff] [blame] | 550 | data_group = optparse.OptionGroup(parser, 'Data source') |
| 551 | data_group.add_option( |
Marc-Antoine Ruel | 185ded4 | 2015-01-28 20:49:18 -0500 | [diff] [blame] | 552 | '-s', '--isolated', |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 553 | help='Hash of the .isolated to grab from the isolate server.') |
Marc-Antoine Ruel | f7d737d | 2014-12-10 15:36:29 -0500 | [diff] [blame] | 554 | isolateserver.add_isolate_server_options(data_group) |
Marc-Antoine Ruel | 1687b5e | 2014-02-06 17:47:53 -0500 | [diff] [blame] | 555 | parser.add_option_group(data_group) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 556 | |
Marc-Antoine Ruel | a57d7db | 2014-10-15 20:31:19 -0400 | [diff] [blame] | 557 | isolateserver.add_cache_options(parser) |
| 558 | parser.set_defaults(cache='cache') |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 559 | |
Kenneth Russell | 61d4235 | 2014-09-15 11:41:16 -0700 | [diff] [blame] | 560 | debug_group = optparse.OptionGroup(parser, 'Debugging') |
| 561 | debug_group.add_option( |
| 562 | '--leak-temp-dir', |
| 563 | action='store_true', |
| 564 | help='Deliberately leak isolate\'s temp dir for later examination ' |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 565 | '[default: %default]') |
maruel | eb5fbee | 2015-09-17 13:01:36 -0700 | [diff] [blame] | 566 | debug_group.add_option( |
| 567 | '--root-dir', help='Use a directory instead of a random one') |
Kenneth Russell | 61d4235 | 2014-09-15 11:41:16 -0700 | [diff] [blame] | 568 | parser.add_option_group(debug_group) |
| 569 | |
Vadim Shtayura | e34e13a | 2014-02-02 11:23:26 -0800 | [diff] [blame] | 570 | auth.add_auth_options(parser) |
Marc-Antoine Ruel | 90c9816 | 2013-12-18 15:11:57 -0500 | [diff] [blame] | 571 | options, args = parser.parse_args(args) |
maruel | 36a963d | 2016-04-08 17:15:49 -0700 | [diff] [blame] | 572 | |
| 573 | cache = isolateserver.process_cache_options(options) |
| 574 | if options.clean: |
| 575 | if options.isolated: |
| 576 | parser.error('Can\'t use --isolated with --clean.') |
| 577 | if options.isolate_server: |
| 578 | parser.error('Can\'t use --isolate-server with --clean.') |
| 579 | if options.json: |
| 580 | parser.error('Can\'t use --json with --clean.') |
| 581 | cache.cleanup() |
| 582 | return 0 |
| 583 | |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 584 | if not options.isolated and not args: |
| 585 | parser.error('--isolated or command to run is required.') |
| 586 | |
Vadim Shtayura | 5d1efce | 2014-02-04 10:55:43 -0800 | [diff] [blame] | 587 | auth.process_auth_options(parser, options) |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 588 | |
| 589 | isolateserver.process_isolate_server_options( |
| 590 | parser, options, True, False) |
| 591 | if not options.isolate_server: |
| 592 | if options.isolated: |
| 593 | parser.error('--isolated requires --isolate-server') |
| 594 | if ISOLATED_OUTDIR_PARAMETER in args: |
| 595 | parser.error( |
| 596 | '%s in args requires --isolate-server' % ISOLATED_OUTDIR_PARAMETER) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 597 | |
maruel | 12e3001 | 2015-10-09 11:55:35 -0700 | [diff] [blame] | 598 | if options.root_dir: |
| 599 | options.root_dir = unicode(os.path.abspath(options.root_dir)) |
| 600 | if options.json: |
| 601 | options.json = unicode(os.path.abspath(options.json)) |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 602 | |
| 603 | command = [] if options.isolated else args |
| 604 | if options.isolate_server: |
| 605 | storage = isolateserver.get_storage( |
| 606 | options.isolate_server, options.namespace) |
Marc-Antoine Ruel | cfb6085 | 2014-07-02 15:22:00 -0400 | [diff] [blame] | 607 | # Hashing schemes used by |storage| and |cache| MUST match. |
| 608 | assert storage.hash_algo == cache.hash_algo |
| 609 | return run_tha_test( |
nodir | 55be77b | 2016-05-03 09:39:57 -0700 | [diff] [blame^] | 610 | command, options.isolated, storage, cache, options.leak_temp_dir, |
| 611 | options.json, options.root_dir, options.hard_timeout, |
| 612 | options.grace_period, args) |
| 613 | else: |
| 614 | return run_tha_test( |
| 615 | command, options.isolated, None, cache, options.leak_temp_dir, |
| 616 | options.json, options.root_dir, options.hard_timeout, |
| 617 | options.grace_period, args) |
maruel@chromium.org | 9c72d4e | 2012-09-28 19:20:25 +0000 | [diff] [blame] | 618 | |
| 619 | |
| 620 | if __name__ == '__main__': |
csharp@chromium.org | bfb9874 | 2013-03-26 20:28:36 +0000 | [diff] [blame] | 621 | # Ensure that we are always running with the correct encoding. |
vadimsh@chromium.org | a432647 | 2013-08-24 02:05:41 +0000 | [diff] [blame] | 622 | fix_encoding.fix_encoding() |
Marc-Antoine Ruel | 90c9816 | 2013-12-18 15:11:57 -0500 | [diff] [blame] | 623 | sys.exit(main(sys.argv[1:])) |