Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 the V8 project authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 # Fork from commands.py and output.py in v8 test driver. | |
| 6 | |
| 7 import signal | |
| 8 import subprocess | |
| 9 import sys | |
| 10 from threading import Timer | |
| 11 | |
| 12 | |
| 13 class Output(object): | |
| 14 def __init__(self, exit_code, timed_out, stdout, pid): | |
| 15 self.exit_code = exit_code | |
| 16 self.timed_out = timed_out | |
| 17 self.stdout = stdout | |
| 18 self.pid = pid | |
| 19 | |
| 20 def HasCrashed(self): | |
| 21 # Timed out tests will have exit_code -signal.SIGTERM. | |
| 22 if self.timed_out: | |
| 23 return False | |
| 24 return (self.exit_code < 0 and | |
| 25 self.exit_code != -signal.SIGABRT) | |
| 26 | |
| 27 def HasTimedOut(self): | |
| 28 return self.timed_out | |
| 29 | |
| 30 | |
| 31 def Execute(args, cwd, timeout=None): | |
| 32 popen_args = [ c for c in args if c != "" ] | |
|
tandrii(chromium)
2016/12/16 16:46:26
nit-nit: space after [ and before ]
Michael Achenbach
2016/12/19 08:42:45
Done.
| |
| 33 try: | |
| 34 process = subprocess.Popen( | |
| 35 args=popen_args, | |
| 36 stdout=subprocess.PIPE, | |
| 37 stderr=subprocess.STDOUT, | |
| 38 cwd=cwd | |
| 39 ) | |
| 40 except Exception as e: | |
| 41 sys.stderr.write("Error executing: %s\n" % popen_args) | |
| 42 raise e | |
| 43 | |
| 44 def kill_process(process, timeout_result): | |
|
tandrii(chromium)
2016/12/16 16:46:26
why args if this func is already inside Execute cl
Michael Achenbach
2016/12/19 08:42:45
Done.
| |
| 45 timeout_result[0] = True | |
|
tandrii(chromium)
2016/12/16 16:46:26
this code relies on this line being atomic, as wel
Michael Achenbach
2016/12/19 08:42:45
Done.
| |
| 46 try: | |
| 47 process.kill() | |
| 48 except OSError: | |
| 49 sys.stderr.write('Error: Process %s already ended.\n' % process.pid) | |
| 50 | |
| 51 # Pseudo object to communicate with timer thread. | |
| 52 timeout_result = [False] | |
| 53 | |
| 54 timer = Timer(timeout, kill_process, [process, timeout_result]) | |
| 55 timer.start() | |
| 56 stdout, _ = process.communicate() | |
| 57 timer.cancel() | |
| 58 | |
| 59 return Output( | |
| 60 process.returncode, | |
| 61 timeout_result[0], | |
| 62 stdout.decode('utf-8', 'replace').encode('utf-8'), | |
| 63 process.pid, | |
| 64 ) | |
| 65 | |
| OLD | NEW |