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
|
2018-10-19 05:54:21 +00:00
|
|
|
|
|
|
|
|
2019-07-19 06:03:00 +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
|
2019-07-19 06:03:00 +00:00
|
|
|
with tempfile.TemporaryFile () as tempf:
|
2018-10-18 04:12:20 +00:00
|
|
|
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")))
|
2018-10-18 04:12:20 +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
|
2018-10-18 04:12:20 +00:00
|
|
|
|
2017-12-29 19:43:29 +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-15 20:04:31 +00:00
|
|
|
hb_shape_fuzzer = os.path.join (top_builddir, "hb-shape-fuzzer" + EXEEXT)
|
2018-01-01 07:47:51 +00:00
|
|
|
|
2018-03-15 20:04:31 +00:00
|
|
|
if not os.path.exists (hb_shape_fuzzer):
|
2018-01-02 20:22:12 +00:00
|
|
|
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-shape-fuzzer binary automatically,
|
2018-01-02 20:22:12 +00:00
|
|
|
please provide it as the first argument to the tool""")
|
|
|
|
|
2018-03-15 20:04:31 +00:00
|
|
|
hb_shape_fuzzer = sys.argv[1]
|
2018-01-01 07:47:51 +00:00
|
|
|
|
2018-03-15 20:04:31 +00:00
|
|
|
print ('hb_shape_fuzzer:', hb_shape_fuzzer)
|
2017-12-29 19:43:29 +00:00
|
|
|
fails = 0
|
|
|
|
|
2018-10-20 04:09:18 +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-15 20:52:21 +00:00
|
|
|
if valgrind is None:
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("""Valgrind requested but not found.""")
|
2018-10-19 05:54:21 +00:00
|
|
|
|
2018-10-16 23:39:29 +00:00
|
|
|
parent_path = os.path.join (srcdir, "fonts")
|
|
|
|
for file in os.listdir (parent_path):
|
2019-07-19 06:03:00 +00:00
|
|
|
path = os.path.join (parent_path, file)
|
2018-10-16 22:12:04 +00:00
|
|
|
|
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_shape_fuzzer, path])
|
2019-04-28 18:54:07 +00:00
|
|
|
else:
|
|
|
|
text, returncode = cmd ([hb_shape_fuzzer, path])
|
|
|
|
if 'error' in text:
|
|
|
|
returncode = 1
|
|
|
|
|
2019-07-19 06:03:00 +00:00
|
|
|
if (not valgrind or returncode) and text.strip ():
|
2018-10-30 05:53:16 +00:00
|
|
|
print (text)
|
2017-12-29 19:43:29 +00:00
|
|
|
|
2019-04-28 18:54:07 +00:00
|
|
|
if returncode != 0:
|
2018-10-18 04:12:20 +00:00
|
|
|
print ('failure on %s' % file)
|
2017-12-29 19:43:29 +00:00
|
|
|
fails = fails + 1
|
|
|
|
|
2019-04-28 18:54:07 +00:00
|
|
|
|
2017-12-29 19:43:29 +00:00
|
|
|
if fails:
|
2020-05-28 18:21:29 +00:00
|
|
|
sys.exit ("%d shape fuzzer related tests failed." % fails)
|