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