3 import sys, os, subprocess, tempfile, shutil
7 # https://stackoverflow.com/a/4408409 as we might have huge output sometimes
8 with tempfile.TemporaryFile () as tempf:
9 p = subprocess.Popen (command, stderr=tempf)
12 p.wait (timeout=int (os.environ.get ("HB_TEST_SHAPE_FUZZER_TIMEOUT", "2")))
16 #TODO: Detect debug mode with a better way
17 is_debug_mode = b"SANITIZE" in text
19 return ("" if is_debug_mode else text.decode ("utf-8").strip ()), p.returncode
20 except subprocess.TimeoutExpired:
21 return 'error: timeout, ' + ' '.join (command), 1
24 srcdir = os.environ.get ("srcdir", ".")
25 EXEEXT = os.environ.get ("EXEEXT", "")
26 top_builddir = os.environ.get ("top_builddir", ".")
27 hb_draw_fuzzer = os.path.join (top_builddir, "hb-draw-fuzzer" + EXEEXT)
29 if not os.path.exists (hb_draw_fuzzer):
30 if len (sys.argv) == 1 or not os.path.exists (sys.argv[1]):
31 sys.exit ("""Failed to find hb-draw-fuzzer binary automatically,
32 please provide it as the first argument to the tool""")
34 hb_draw_fuzzer = sys.argv[1]
36 print ('hb_draw_fuzzer:', hb_draw_fuzzer)
39 libtool = os.environ.get ('LIBTOOL')
41 if os.environ.get ('RUN_VALGRIND', ''):
42 valgrind = shutil.which ('valgrind')
44 sys.exit ("""Valgrind requested but not found.""")
46 print ("""Valgrind support is currently autotools only and needs libtool but not found.""")
49 parent_path = os.path.join (srcdir, "fonts")
50 for file in os.listdir (parent_path):
51 if "draw" not in file: continue
52 path = os.path.join (parent_path, file)
55 text, returncode = cmd (libtool.split(' ') + ['--mode=execute', valgrind + ' --leak-check=full --error-exitcode=1', '--', hb_draw_fuzzer, path])
57 text, returncode = cmd ([hb_draw_fuzzer, path])
61 if (not valgrind or returncode) and text.strip ():
65 print ('failure on %s' % file)
70 sys.exit ("%d draw fuzzer related tests failed." % fails)