OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import argparse | 5 import argparse |
6 import contextlib | 6 import contextlib |
| 7 import io |
7 import json | 8 import json |
8 import os | 9 import os |
| 10 import logging |
9 import subprocess | 11 import subprocess |
10 import sys | 12 import sys |
11 import tempfile | 13 import tempfile |
| 14 import time |
12 | 15 |
13 | 16 |
14 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | 17 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
15 SRC_DIR = os.path.abspath( | 18 SRC_DIR = os.path.abspath( |
16 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir)) | 19 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir)) |
17 | 20 |
18 | 21 |
19 # run-webkit-tests returns the number of failures as the return | 22 # run-webkit-tests returns the number of failures as the return |
20 # code, but caps the return code at 101 to avoid overflow or colliding | 23 # code, but caps the return code at 101 to avoid overflow or colliding |
21 # with reserved values from the shell. | 24 # with reserved values from the shell. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return args.func(args) | 66 return args.func(args) |
64 | 67 |
65 | 68 |
66 def run_command(argv, env=None, cwd=None): | 69 def run_command(argv, env=None, cwd=None): |
67 print 'Running %r in %r (env: %r)' % (argv, cwd, env) | 70 print 'Running %r in %r (env: %r)' % (argv, cwd, env) |
68 rc = subprocess.call(argv, env=env, cwd=cwd) | 71 rc = subprocess.call(argv, env=env, cwd=cwd) |
69 print 'Command %r returned exit code %d' % (argv, rc) | 72 print 'Command %r returned exit code %d' % (argv, rc) |
70 return rc | 73 return rc |
71 | 74 |
72 | 75 |
73 def run_command_with_output(argv, env=None, cwd=None, stdoutfile=None): | 76 def run_command_with_output(argv, stdoutfile, env=None, cwd=None): |
| 77 """ Run command and stream its stdout/stderr to the console & |stdoutfile|. |
| 78 """ |
74 print 'Running %r in %r (env: %r)' % (argv, cwd, env) | 79 print 'Running %r in %r (env: %r)' % (argv, cwd, env) |
75 rc = 1 | 80 assert stdoutfile |
76 try: | 81 with io.open(stdoutfile, 'w') as writer, io.open(stdoutfile, 'r', 1) as \ |
77 output = subprocess.check_output(argv, env=env, cwd=cwd, | 82 reader: |
| 83 process = subprocess.Popen(argv, env=env, cwd=cwd, stdout=writer, |
78 stderr=subprocess.STDOUT) | 84 stderr=subprocess.STDOUT) |
79 if stdoutfile: | 85 while process.poll() is None: |
80 with open(stdoutfile, 'w') as fp: | 86 sys.stdout.write(reader.read()) |
81 fp.write(output) | 87 time.sleep(0.1) |
82 rc = 0 | 88 # Read the remaining |
83 except Exception: | 89 sys.stdout.write(reader.read()) |
84 # Exit code remains 1 and we don't write output | 90 print 'Command %r returned exit code %d' % (argv, process.returncode) |
85 pass | 91 return process.returncode |
86 print 'Command %r returned exit code %d' % (argv, rc) | |
87 return rc | |
88 | 92 |
89 | 93 |
90 def run_runtest(cmd_args, runtest_args): | 94 def run_runtest(cmd_args, runtest_args): |
91 if cmd_args.use_src_side_runtest_py: | 95 if cmd_args.use_src_side_runtest_py: |
92 cmd = [ | 96 cmd = [ |
93 sys.executable, | 97 sys.executable, |
94 os.path.join( | 98 os.path.join( |
95 cmd_args.paths['checkout'], 'infra', 'scripts', 'runtest_wrapper.py'), | 99 cmd_args.paths['checkout'], 'infra', 'scripts', 'runtest_wrapper.py'), |
96 '--', | 100 '--', |
97 ] | 101 ] |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 [sys.executable, script_to_run] + extra_args) | 184 [sys.executable, script_to_run] + extra_args) |
181 | 185 |
182 with open(log_file) as f: | 186 with open(log_file) as f: |
183 failures = json.load(f) | 187 failures = json.load(f) |
184 json.dump({ | 188 json.dump({ |
185 'valid': integration_test_res == 0, | 189 'valid': integration_test_res == 0, |
186 'failures': failures, | 190 'failures': failures, |
187 }, output) | 191 }, output) |
188 | 192 |
189 return integration_test_res | 193 return integration_test_res |
OLD | NEW |