Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(16)

Side by Side Diff: testing/scripts/common.py

Issue 2889153007: Update run_gtest_perf_test.py to streaming command output to stdout & log file at the same time (Closed)
Patch Set: Address Daniel's comments Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | testing/scripts/run_gtest_perf_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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, ):
dnj 2017/05/19 21:27:16 Nit, trailing comma.
nednguyen 2017/05/19 21:31:15 Done.
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, 'wb') as writer:
dnj 2017/05/19 21:27:16 Nit, you can combine this into a single block: wi
nednguyen 2017/05/19 21:31:14 Done.
77 output = subprocess.check_output(argv, env=env, cwd=cwd, 82 with io.open(stdoutfile, 'rb', 1) as reader:
dnj 2017/05/19 21:27:16 Note: the original used "w" (text-mode); "wb" and
nednguyen 2017/05/19 21:31:15 Oh, I just use "w" & "r" here to be sure.
78 stderr=subprocess.STDOUT) 83 process = subprocess.Popen(argv, env=env, cwd=cwd, stdout=writer,
79 if stdoutfile: 84 stderr=subprocess.STDOUT)
80 with open(stdoutfile, 'w') as fp: 85 while process.poll() is None:
81 fp.write(output) 86 sys.stdout.write(reader.read())
82 rc = 0 87 time.sleep(1)
dnj 2017/05/19 21:27:16 Note: if the subprocess is fast and repeated (e.g.
nednguyen 2017/05/19 21:31:15 Done.
83 except Exception: 88 # Read the remaining
84 # Exit code remains 1 and we don't write output 89 sys.stdout.write(reader.read())
85 pass 90 print 'Command %r returned exit code %d' % (argv, process.returncode)
86 print 'Command %r returned exit code %d' % (argv, rc) 91 return process.returncode
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
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
OLDNEW
« no previous file with comments | « no previous file | testing/scripts/run_gtest_perf_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698