[ci][fuzzer] print valgrind failure if an error happened

This commit is contained in:
Ebrahim Byagowi 2019-07-19 10:33:00 +04:30 committed by GitHub
parent 2bd953ff4f
commit bdfdac0f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 17 deletions

View File

@ -5,41 +5,41 @@ from __future__ import print_function, division, absolute_import
import sys, os, subprocess, tempfile, threading import sys, os, subprocess, tempfile, threading
def which(program): def which (program):
# https://stackoverflow.com/a/377028 # https://stackoverflow.com/a/377028
def is_exe(fpath): def is_exe (fpath):
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) return os.path.isfile (fpath) and os.access (fpath, os.X_OK)
fpath, _ = os.path.split(program) fpath, _ = os.path.split (program)
if fpath: if fpath:
if is_exe(program): if is_exe (program):
return program return program
else: else:
for path in os.environ["PATH"].split(os.pathsep): for path in os.environ["PATH"].split (os.pathsep):
exe_file = os.path.join(path, program) exe_file = os.path.join (path, program)
if is_exe(exe_file): if is_exe (exe_file):
return exe_file return exe_file
return None return None
def cmd(command): def cmd (command):
# https://stackoverflow.com/a/4408409 # https://stackoverflow.com/a/4408409
# https://stackoverflow.com/a/10012262 # https://stackoverflow.com/a/10012262
with tempfile.TemporaryFile() as tempf: with tempfile.TemporaryFile () as tempf:
p = subprocess.Popen (command, stderr=tempf) p = subprocess.Popen (command, stderr=tempf)
is_killed = {'value': False} is_killed = {'value': False}
def timeout(p, is_killed): def timeout (p, is_killed):
is_killed['value'] = True is_killed['value'] = True
p.kill() p.kill ()
timer = threading.Timer (2, timeout, [p, is_killed]) timer = threading.Timer (2, timeout, [p, is_killed])
try: try:
timer.start() timer.start()
p.wait () p.wait ()
tempf.seek (0) tempf.seek (0)
text = tempf.read().decode ("utf-8").strip () text = tempf.read ().decode ("utf-8").strip ()
returncode = p.returncode returncode = p.returncode
finally: finally:
timer.cancel() timer.cancel()
@ -67,9 +67,9 @@ please provide it as the first argument to the tool""")
print ('hb_shape_fuzzer:', hb_shape_fuzzer) print ('hb_shape_fuzzer:', hb_shape_fuzzer)
fails = 0 fails = 0
libtool = os.environ.get('LIBTOOL') libtool = os.environ.get ('LIBTOOL')
valgrind = None valgrind = None
if os.environ.get('RUN_VALGRIND', ''): if os.environ.get ('RUN_VALGRIND', ''):
valgrind = which ('valgrind') valgrind = which ('valgrind')
if valgrind is None: if valgrind is None:
print ("""Valgrind requested but not found.""") print ("""Valgrind requested but not found.""")
@ -80,7 +80,7 @@ if os.environ.get('RUN_VALGRIND', ''):
parent_path = os.path.join (srcdir, "fonts") parent_path = os.path.join (srcdir, "fonts")
for file in os.listdir (parent_path): for file in os.listdir (parent_path):
path = os.path.join(parent_path, file) path = os.path.join (parent_path, file)
if valgrind: if valgrind:
text, returncode = cmd (libtool.split(' ') + ['--mode=execute', valgrind + ' --leak-check=full --error-exitcode=1', '--', hb_shape_fuzzer, path]) text, returncode = cmd (libtool.split(' ') + ['--mode=execute', valgrind + ' --leak-check=full --error-exitcode=1', '--', hb_shape_fuzzer, path])
@ -89,7 +89,7 @@ for file in os.listdir (parent_path):
if 'error' in text: if 'error' in text:
returncode = 1 returncode = 1
if not valgrind and text.strip (): if (not valgrind or returncode) and text.strip ():
print (text) print (text)
if returncode != 0: if returncode != 0: