2018-03-15 02:15:33 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2018-03-29 08:18:47 +00:00
|
|
|
from __future__ import print_function, division, absolute_import
|
|
|
|
|
2019-04-28 18:54:07 +00:00
|
|
|
import sys, os, subprocess, tempfile, threading
|
|
|
|
|
|
|
|
|
|
|
|
def which(program):
|
|
|
|
# https://stackoverflow.com/a/377028
|
|
|
|
def is_exe(fpath):
|
|
|
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
|
|
|
|
fpath, _ = os.path.split(program)
|
|
|
|
if fpath:
|
|
|
|
if is_exe(program):
|
|
|
|
return program
|
|
|
|
else:
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
exe_file = os.path.join(path, program)
|
|
|
|
if is_exe(exe_file):
|
|
|
|
return exe_file
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
|
|
def cmd(command):
|
|
|
|
# https://stackoverflow.com/a/4408409
|
|
|
|
# https://stackoverflow.com/a/10012262
|
|
|
|
with tempfile.TemporaryFile() as tempf:
|
|
|
|
p = subprocess.Popen (command, stderr=tempf)
|
|
|
|
is_killed = {'value': False}
|
|
|
|
|
|
|
|
def timeout(p, is_killed):
|
|
|
|
is_killed['value'] = True
|
|
|
|
p.kill()
|
|
|
|
timer = threading.Timer (2, timeout, [p, is_killed])
|
|
|
|
|
|
|
|
try:
|
|
|
|
timer.start()
|
|
|
|
p.wait ()
|
|
|
|
tempf.seek (0)
|
|
|
|
text = tempf.read().decode ("utf-8").strip ()
|
|
|
|
returncode = p.returncode
|
|
|
|
finally:
|
|
|
|
timer.cancel()
|
|
|
|
|
|
|
|
if is_killed['value']:
|
|
|
|
text = 'error: timeout, ' + text
|
|
|
|
returncode = 1
|
|
|
|
|
|
|
|
return text, returncode
|
|
|
|
|
2018-03-15 02:15:33 +00:00
|
|
|
|
|
|
|
srcdir = os.environ.get ("srcdir", ".")
|
|
|
|
EXEEXT = os.environ.get ("EXEEXT", "")
|
|
|
|
top_builddir = os.environ.get ("top_builddir", ".")
|
2018-03-16 01:27:01 +00:00
|
|
|
hb_subset_fuzzer = os.path.join (top_builddir, "hb-subset-fuzzer" + EXEEXT)
|
2018-03-15 02:15:33 +00:00
|
|
|
|
|
|
|
if not os.path.exists (hb_subset_fuzzer):
|
2018-04-17 14:21:22 +00:00
|
|
|
if len (sys.argv) < 2 or not os.path.exists (sys.argv[1]):
|
2018-03-15 02:15:33 +00:00
|
|
|
print ("""Failed to find hb-subset-fuzzer binary automatically,
|
|
|
|
please provide it as the first argument to the tool""")
|
|
|
|
sys.exit (1)
|
|
|
|
|
|
|
|
hb_subset_fuzzer = sys.argv[1]
|
|
|
|
|
|
|
|
print ('hb_subset_fuzzer:', hb_subset_fuzzer)
|
|
|
|
fails = 0
|
|
|
|
|
2019-04-28 18:54:07 +00:00
|
|
|
libtool = os.environ.get('LIBTOOL')
|
|
|
|
valgrind = None
|
|
|
|
if os.environ.get('RUN_VALGRIND', ''):
|
|
|
|
valgrind = which ('valgrind')
|
|
|
|
if valgrind is None:
|
|
|
|
print ("""Valgrind requested but not found.""")
|
|
|
|
sys.exit (1)
|
|
|
|
if libtool is None:
|
|
|
|
print ("""Valgrind support is currently autotools only and needs libtool but not found.""")
|
|
|
|
|
|
|
|
|
2018-10-16 23:39:29 +00:00
|
|
|
def run_dir (parent_path):
|
|
|
|
global fails
|
|
|
|
for file in os.listdir (parent_path):
|
|
|
|
path = os.path.join(parent_path, file)
|
|
|
|
|
|
|
|
print ("running subset fuzzer against %s" % path)
|
2019-04-28 18:54:07 +00:00
|
|
|
if valgrind:
|
|
|
|
text, returncode = cmd (libtool.split(' ') + ['--mode=execute', valgrind + ' --leak-check=full --show-leak-kinds=all --error-exitcode=1', '--', hb_subset_fuzzer, path])
|
|
|
|
else:
|
|
|
|
text, returncode = cmd ([hb_subset_fuzzer, path])
|
|
|
|
if 'error' in text:
|
|
|
|
returncode = 1
|
2018-10-16 23:39:29 +00:00
|
|
|
|
2019-04-28 18:54:07 +00:00
|
|
|
if not valgrind and text.strip ():
|
|
|
|
print (text)
|
2018-10-16 23:39:29 +00:00
|
|
|
|
2019-04-28 18:54:07 +00:00
|
|
|
if returncode != 0:
|
2018-10-16 23:39:29 +00:00
|
|
|
print ("failed for %s" % path)
|
|
|
|
fails = fails + 1
|
|
|
|
|
2019-04-28 18:54:07 +00:00
|
|
|
|
2018-10-16 23:39:29 +00:00
|
|
|
run_dir (os.path.join (srcdir, "..", "subset", "data", "fonts"))
|
|
|
|
# TODO running these tests very slow tests. Fix and re-enable
|
|
|
|
#run_dir (os.path.join (srcdir, "fonts"))
|
2018-04-17 14:21:22 +00:00
|
|
|
|
2018-03-15 02:15:33 +00:00
|
|
|
if fails:
|
2018-03-15 22:41:08 +00:00
|
|
|
print ("%i subset fuzzer related tests failed." % fails)
|
2018-03-15 02:15:33 +00:00
|
|
|
sys.exit (1)
|