(site, domain, args, timeout=None)
| 160 | ] |
| 161 | |
| 162 | def run_site(site, domain, args, timeout=None): |
| 163 | print("="*80) |
| 164 | print("RUNNING DOMAIN %s" % domain) |
| 165 | print("="*80) |
| 166 | result_template = "{domain}#{count}.txt" if args.repeat else "{domain}.txt" |
| 167 | count = 0 |
| 168 | if timeout is None: timeout = args.timeout |
| 169 | if args.replay_wpr: |
| 170 | timeout *= 1 + args.refresh |
| 171 | timeout += 1 |
| 172 | retries_since_good_run = 0 |
| 173 | while count == 0 or args.repeat is not None and count < args.repeat: |
| 174 | count += 1 |
| 175 | result = result_template.format(domain=domain, count=count) |
| 176 | retries = 0 |
| 177 | while args.retries is None or retries < args.retries: |
| 178 | retries += 1 |
| 179 | try: |
| 180 | if args.user_data_dir: |
| 181 | user_data_dir = args.user_data_dir |
| 182 | else: |
| 183 | user_data_dir = tempfile.mkdtemp(prefix="chr_") |
| 184 | js_flags = "--runtime-call-stats" |
| 185 | if args.replay_wpr: js_flags += " --allow-natives-syntax" |
| 186 | if args.js_flags: js_flags += " " + args.js_flags |
| 187 | chrome_flags = get_chrome_flags(js_flags, user_data_dir) |
| 188 | if args.replay_wpr: |
| 189 | chrome_flags += get_chrome_replay_flags(args) |
| 190 | else: |
| 191 | chrome_flags += [ "--single-process", ] |
| 192 | if args.chrome_flags: |
| 193 | chrome_flags += args.chrome_flags.split() |
| 194 | cmd_args = [ |
| 195 | "timeout", str(timeout), |
| 196 | args.with_chrome |
| 197 | ] + chrome_flags + [ site ] |
| 198 | print("- " * 40) |
| 199 | print_command(cmd_args) |
| 200 | print("- " * 40) |
| 201 | with open(result, "wt") as f: |
| 202 | with open(args.log_stderr or os.devnull, 'at') as err: |
| 203 | status = subprocess.call(cmd_args, stdout=f, stderr=err) |
| 204 | # 124 means timeout killed chrome, 0 means the user was bored first! |
| 205 | # If none of these two happened, then chrome apparently crashed, so |
| 206 | # it must be called again. |
| 207 | if status != 124 and status != 0: |
| 208 | print("CHROME CRASHED, REPEATING RUN"); |
| 209 | continue |
| 210 | # If the stats file is empty, chrome must be called again. |
| 211 | if os.path.isfile(result) and os.path.getsize(result) > 0: |
| 212 | if args.print_url: |
| 213 | with open(result, "at") as f: |
| 214 | print(file=f) |
| 215 | print("URL: {}".format(site), file=f) |
| 216 | retries_since_good_run = 0 |
| 217 | break |
| 218 | if retries_since_good_run > MAX_NOF_RETRIES: |
| 219 | # Abort after too many retries, no point in ever increasing the |
no test coverage detected
searching dependent graphs…