2020-02-19 11:26:55 +00:00
|
|
|
#!/usr/bin/env python3
|
2018-03-29 08:18:47 +00:00
|
|
|
|
2020-03-19 08:13:37 +00:00
|
|
|
import sys, os, subprocess, tempfile, shutil
|
2019-04-28 18:54:07 +00:00
|
|
|
|
|
|
|
|
2020-03-19 08:13:37 +00:00
|
|
|
def cmd (command):
|
|
|
|
# https://stackoverflow.com/a/4408409 as we might have huge output sometimes
|
|
|
|
with tempfile.TemporaryFile () as tempf:
|
2019-04-28 18:54:07 +00:00
|
|
|
p = subprocess.Popen (command, stderr=tempf)
|
|
|
|
|
|
|
|
try:
|
2020-10-13 18:21:28 +00:00
|
|
|
p.wait ()
|
2019-04-28 18:54:07 +00:00
|
|
|
tempf.seek (0)
|
2019-09-21 12:52:02 +00:00
|
|
|
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
|
2019-04-28 18:54:07 +00:00
|
|
|
|
2018-03-15 02:15:33 +00:00
|
|
|
|
2020-07-04 09:42:55 +00:00
|
|
|
srcdir = os.getenv ("srcdir", ".")
|
|
|
|
EXEEXT = os.getenv ("EXEEXT", "")
|
|
|
|
top_builddir = os.getenv ("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]):
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("""Failed to find hb-subset-fuzzer binary automatically,
|
2018-03-15 02:15:33 +00:00
|
|
|
please provide it as the first argument to the tool""")
|
|
|
|
|
|
|
|
hb_subset_fuzzer = sys.argv[1]
|
|
|
|
|
|
|
|
print ('hb_subset_fuzzer:', hb_subset_fuzzer)
|
|
|
|
fails = 0
|
|
|
|
|
2019-04-28 18:54:07 +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')
|
2019-04-28 18:54:07 +00:00
|
|
|
if valgrind is None:
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("""Valgrind requested but not found.""")
|
2019-04-28 18:54:07 +00:00
|
|
|
|
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)
|
2019-07-11 10:01:55 +00:00
|
|
|
# TODO: Run on all the fonts not just subset related ones
|
|
|
|
if "subset" not in path: continue
|
2018-10-16 23:39:29 +00:00
|
|
|
|
|
|
|
print ("running subset fuzzer against %s" % path)
|
2019-04-28 18:54:07 +00:00
|
|
|
if valgrind:
|
2020-07-08 10:40:25 +00:00
|
|
|
text, returncode = cmd ([valgrind, '--leak-check=full', '--error-exitcode=1', hb_subset_fuzzer, path])
|
2019-04-28 18:54:07 +00:00
|
|
|
else:
|
|
|
|
text, returncode = cmd ([hb_subset_fuzzer, path])
|
|
|
|
if 'error' in text:
|
|
|
|
returncode = 1
|
2018-10-16 23:39:29 +00:00
|
|
|
|
2019-07-11 10:01:55 +00:00
|
|
|
if (not valgrind or returncode) and text.strip ():
|
2019-04-28 18:54:07 +00:00
|
|
|
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"))
|
2019-07-11 10:01:55 +00:00
|
|
|
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:
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("%d subset fuzzer related tests failed." % fails)
|