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 json | 7 import json |
8 import os | 8 import os |
9 import logging | |
9 import subprocess | 10 import subprocess |
10 import sys | 11 import sys |
11 import tempfile | 12 import tempfile |
12 | 13 |
13 | 14 |
14 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) | 15 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
15 SRC_DIR = os.path.abspath( | 16 SRC_DIR = os.path.abspath( |
16 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir)) | 17 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir)) |
17 | 18 |
18 | 19 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 | 65 |
65 | 66 |
66 def run_command(argv, env=None, cwd=None): | 67 def run_command(argv, env=None, cwd=None): |
67 print 'Running %r in %r (env: %r)' % (argv, cwd, env) | 68 print 'Running %r in %r (env: %r)' % (argv, cwd, env) |
68 rc = subprocess.call(argv, env=env, cwd=cwd) | 69 rc = subprocess.call(argv, env=env, cwd=cwd) |
69 print 'Command %r returned exit code %d' % (argv, rc) | 70 print 'Command %r returned exit code %d' % (argv, rc) |
70 return rc | 71 return rc |
71 | 72 |
72 | 73 |
73 def run_command_with_output(argv, env=None, cwd=None, stdoutfile=None): | 74 def run_command_with_output(argv, env=None, cwd=None, stdoutfile=None): |
75 """ Run command and stream its stdout/stderr to the console & |stdoutfile|. | |
76 """ | |
74 print 'Running %r in %r (env: %r)' % (argv, cwd, env) | 77 print 'Running %r in %r (env: %r)' % (argv, cwd, env) |
75 rc = 1 | 78 rc = 1 |
dnj
2017/05/19 20:56:18
No point setting this here.
nednguyen
2017/05/19 21:21:23
Done.
| |
76 try: | 79 stdoutfile_header = None |
77 output = subprocess.check_output(argv, env=env, cwd=cwd, | 80 if stdoutfile: |
78 stderr=subprocess.STDOUT) | 81 stdoutfile_header = open(stdoutfile, 'w') |
dnj
2017/05/19 20:56:18
nit: do this in try/finally clause, closing on fin
nednguyen
2017/05/19 21:21:23
We no longer need this as I just assert stdoutfile
| |
79 if stdoutfile: | 82 process = subprocess.Popen(argv, env=env, cwd=cwd, stdout=subprocess.PIPE, |
dnj
2017/05/19 20:56:18
Note that before, if the argv[0] did not exist or
nednguyen
2017/05/19 21:21:23
That's ok as long as we have error message can poi
| |
80 with open(stdoutfile, 'w') as fp: | 83 stderr=subprocess.STDOUT) |
81 fp.write(output) | 84 for c in iter(lambda: process.stdout.read(1), ''): |
dnj
2017/05/19 20:56:18
How much data are we expecting here? Reading byte-
nednguyen
2017/05/19 21:21:23
This can depend. I think it's safer to not assumin
| |
82 rc = 0 | 85 sys.stdout.write(c) |
83 except Exception: | 86 if stdoutfile_header: |
84 # Exit code remains 1 and we don't write output | 87 stdoutfile_header.write(c) |
dnj
2017/05/19 20:56:18
You need to close this file descriptor when you're
nednguyen
2017/05/19 21:21:23
Done.
| |
85 pass | 88 process.wait() |
89 rc = process.returncode | |
dnj
2017/05/19 20:56:18
Just use "process.returncode" in the 'print' and '
nednguyen
2017/05/19 21:21:23
Done.
| |
86 print 'Command %r returned exit code %d' % (argv, rc) | 90 print 'Command %r returned exit code %d' % (argv, rc) |
87 return rc | 91 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'), |
(...skipping 84 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 |