Python fixes for reduce.py (#3795)

This commit is contained in:
Paul Fultz II 2022-02-05 01:32:01 -06:00 committed by GitHub
parent c2b5cdcca5
commit 508fa6284c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 6 deletions

View File

@ -3,6 +3,18 @@ import subprocess
import sys import sys
import time import time
if sys.version_info[0] < 3:
class TimeoutExpired(Exception):
pass
else:
TimeoutExpired = subprocess.TimeoutExpired
def communicate(p, timeout=None, **kwargs):
if sys.version_info[0] < 3:
return p.communicate(**kwargs)
else:
return p.communicate(timeout=timeout)
# TODO: add --hang option to detect code which impacts the analysis time # TODO: add --hang option to detect code which impacts the analysis time
def show_syntax(): def show_syntax():
print('Syntax:') print('Syntax:')
@ -59,15 +71,14 @@ else:
print('EXPECTED=' + EXPECTED) print('EXPECTED=' + EXPECTED)
print('FILE=' + FILE) print('FILE=' + FILE)
def runtool(filedata=None): def runtool(filedata=None):
timeout = None timeout = None
if elapsed_time: if elapsed_time:
timeout = elapsed_time * 2 timeout = elapsed_time * 2
p = subprocess.Popen(CMD.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE) p = subprocess.Popen(CMD.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
try: try:
comm = p.communicate(timeout=timeout) comm = communicate(p, timeout=timeout)
except subprocess.TimeoutExpired: except TimeoutExpired:
print('timeout') print('timeout')
p.kill() p.kill()
p.communicate() p.communicate()
@ -278,11 +289,11 @@ def removeline(filedata):
# reduce.. # reduce..
print('Make sure error can be reproduced...') print('Make sure error can be reproduced...')
elapsed_time = None elapsed_time = None
t = time.perf_counter() t = time.time()
if not runtool(): if not runtool():
print("Cannot reproduce") print("Cannot reproduce")
sys.exit(1) sys.exit(1)
elapsed_time = time.perf_counter() - t elapsed_time = time.time() - t
print('elapsed_time: {}'.format(elapsed_time)) print('elapsed_time: {}'.format(elapsed_time))
f = open(FILE, 'rt') f = open(FILE, 'rt')