2020-02-28 16:20:30 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2020-03-19 08:13:37 +00:00
|
|
|
import sys, os, subprocess, tempfile, shutil
|
2020-02-28 16:20:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
def cmd (command):
|
2020-03-19 08:13:37 +00:00
|
|
|
# https://stackoverflow.com/a/4408409 as we might have huge output sometimes
|
2020-02-28 16:20:30 +00:00
|
|
|
with tempfile.TemporaryFile () as tempf:
|
|
|
|
p = subprocess.Popen (command, stderr=tempf)
|
|
|
|
|
|
|
|
try:
|
2020-07-04 09:42:55 +00:00
|
|
|
p.wait (timeout=int (os.getenv ("HB_TEST_SHAPE_FUZZER_TIMEOUT", "2")))
|
2020-02-28 16:20:30 +00:00
|
|
|
tempf.seek (0)
|
|
|
|
text = tempf.read ()
|
|
|
|
|
|
|
|
#TODO: Detect debug mode with a better way
|
|
|
|
is_debug_mode = b"SANITIZE" in text
|
|
|
|
|
2020-03-19 08:13:37 +00:00
|
|
|
return ("" if is_debug_mode else text.decode ("utf-8").strip ()), p.returncode
|
|
|
|
except subprocess.TimeoutExpired:
|
|
|
|
return 'error: timeout, ' + ' '.join (command), 1
|
2020-02-28 16:20:30 +00:00
|
|
|
|
|
|
|
|
2020-07-04 09:42:55 +00:00
|
|
|
srcdir = os.getenv ("srcdir", ".")
|
|
|
|
EXEEXT = os.getenv ("EXEEXT", "")
|
|
|
|
top_builddir = os.getenv ("top_builddir", ".")
|
2020-02-28 16:20:30 +00:00
|
|
|
hb_draw_fuzzer = os.path.join (top_builddir, "hb-draw-fuzzer" + EXEEXT)
|
|
|
|
|
|
|
|
if not os.path.exists (hb_draw_fuzzer):
|
|
|
|
if len (sys.argv) == 1 or not os.path.exists (sys.argv[1]):
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("""Failed to find hb-draw-fuzzer binary automatically,
|
2020-02-28 16:20:30 +00:00
|
|
|
please provide it as the first argument to the tool""")
|
|
|
|
|
|
|
|
hb_draw_fuzzer = sys.argv[1]
|
|
|
|
|
|
|
|
print ('hb_draw_fuzzer:', hb_draw_fuzzer)
|
|
|
|
fails = 0
|
|
|
|
|
2020-07-04 09:42:55 +00:00
|
|
|
libtool = os.getenv ('LIBTOOL')
|
2020-02-28 16:20:30 +00:00
|
|
|
valgrind = None
|
2020-07-04 09:42:55 +00:00
|
|
|
if os.getenv ('RUN_VALGRIND', ''):
|
2020-03-18 20:28:20 +00:00
|
|
|
valgrind = shutil.which ('valgrind')
|
2020-02-28 16:20:30 +00:00
|
|
|
if valgrind is None:
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("""Valgrind requested but not found.""")
|
2020-02-28 16:20:30 +00:00
|
|
|
if libtool is None:
|
|
|
|
print ("""Valgrind support is currently autotools only and needs libtool but not found.""")
|
|
|
|
|
|
|
|
|
|
|
|
parent_path = os.path.join (srcdir, "fonts")
|
|
|
|
for file in os.listdir (parent_path):
|
|
|
|
if "draw" not in file: continue
|
|
|
|
path = os.path.join (parent_path, file)
|
|
|
|
|
|
|
|
if valgrind:
|
|
|
|
text, returncode = cmd (libtool.split(' ') + ['--mode=execute', valgrind + ' --leak-check=full --error-exitcode=1', '--', hb_draw_fuzzer, path])
|
|
|
|
else:
|
|
|
|
text, returncode = cmd ([hb_draw_fuzzer, path])
|
|
|
|
if 'error' in text:
|
|
|
|
returncode = 1
|
|
|
|
|
|
|
|
if (not valgrind or returncode) and text.strip ():
|
|
|
|
print (text)
|
|
|
|
|
|
|
|
if returncode != 0:
|
|
|
|
print ('failure on %s' % file)
|
|
|
|
fails = fails + 1
|
|
|
|
|
|
|
|
|
|
|
|
if fails:
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("%d draw fuzzer related tests failed." % fails)
|