2020-02-19 12:26:55 +01:00
|
|
|
#!/usr/bin/env python3
|
2018-03-29 10:18:47 +02:00
|
|
|
|
2020-03-19 09:13:37 +01:00
|
|
|
import sys, os, subprocess, tempfile, shutil
|
2018-10-19 07:54:21 +02:00
|
|
|
|
|
|
|
|
2019-07-19 08:03:00 +02:00
|
|
|
def cmd (command):
|
2020-03-19 09:13:37 +01:00
|
|
|
# https://stackoverflow.com/a/4408409 as we might have huge output sometimes
|
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)
|
|
|
|
|
|
|
|
try:
|
2020-07-04 11:42:55 +02:00
|
|
|
p.wait (timeout=int (os.getenv ("HB_TEST_SHAPE_FUZZER_TIMEOUT", "2")))
|
2018-10-18 06:12:20 +02:00
|
|
|
tempf.seek (0)
|
2019-09-21 14:52:02 +02:00
|
|
|
text = tempf.read ()
|
|
|
|
|
|
|
|
#TODO: Detect debug mode with a better way
|
|
|
|
is_debug_mode = b"SANITIZE" in text
|
|
|
|
|
2020-03-19 09:13:37 +01: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 06:12:20 +02:00
|
|
|
|
2017-12-29 20:43:29 +01:00
|
|
|
|
2020-07-04 11:42:55 +02:00
|
|
|
srcdir = os.getenv ("srcdir", ".")
|
|
|
|
EXEEXT = os.getenv ("EXEEXT", "")
|
|
|
|
top_builddir = os.getenv ("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]):
|
2020-05-28 20:21:29 +02:00
|
|
|
sys.exit ("""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""")
|
|
|
|
|
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
|
|
|
|
|
2018-10-20 06:09:18 +02:00
|
|
|
valgrind = None
|
2020-07-04 11:42:55 +02:00
|
|
|
if os.getenv ('RUN_VALGRIND', ''):
|
2020-03-18 21:28:20 +01:00
|
|
|
valgrind = shutil.which ('valgrind')
|
2019-04-15 22:52:21 +02:00
|
|
|
if valgrind is None:
|
2020-05-28 20:21:29 +02:00
|
|
|
sys.exit ("""Valgrind requested 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:
|
2020-07-08 12:40:25 +02:00
|
|
|
text, returncode = cmd ([valgrind, '--leak-check=full', '--error-exitcode=1', hb_shape_fuzzer, path])
|
2019-04-28 20:54:07 +02:00
|
|
|
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:
|
2020-05-28 20:21:29 +02:00
|
|
|
sys.exit ("%d shape fuzzer related tests failed." % fails)
|