[test/shaping] Spawn one hb-shape per test file

Speeds up runnings in-house tests from over 20s to 2s.
This commit is contained in:
Behdad Esfahbod 2018-10-30 00:51:43 -07:00
parent 58e20f53bf
commit 422debb830

View File

@ -2,16 +2,13 @@
from __future__ import print_function, division, absolute_import
import sys, os, subprocess, tempfile
import sys, os, subprocess
def cmd(command):
# https://stackoverflow.com/a/4408409
with tempfile.TemporaryFile() as tempf:
p = subprocess.Popen (command, stdout=tempf, stderr=sys.stdout)
p.wait ()
tempf.seek(0)
return tempf.read().decode ("utf-8").strip (), p.returncode
global process
process.stdin.write (' '.join (command) + '\n')
process.stdin.flush ()
return process.stdout.readline().decode ("utf-8").strip ()
args = sys.argv[1:]
if not args or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.argv[1]):
@ -19,6 +16,11 @@ if not args or sys.argv[1].find('hb-shape') == -1 or not os.path.exists (sys.arg
sys.exit (1)
hb_shape, args = args[0], args[1:]
process = subprocess.Popen ([hb_shape, '--batch'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=sys.stdout)
fails = 0
reference = False
@ -60,24 +62,14 @@ for filename in args:
print ("%s %s %s %s --unicodes %s" %
(hb_shape, fontfile, ' '.join(extra_options), options, unicodes))
glyphs1, returncode = cmd ([hb_shape, "--font-funcs=ft",
glyphs1 = cmd ([hb_shape, "--font-funcs=ft",
fontfile] + extra_options + ["--unicodes",
unicodes] + (options.split (' ') if options else []))
if returncode:
print ("ERROR: hb-shape --font-funcs=ft failed.") # file=sys.stderr
fails = fails + 1
#continue
glyphs2, returncode = cmd ([hb_shape, "--font-funcs=ot",
glyphs2 = cmd ([hb_shape, "--font-funcs=ot",
fontfile] + extra_options + ["--unicodes",
unicodes] + (options.split (' ') if options else []))
if returncode:
print ("ERROR: hb-shape --font-funcs=ot failed.") # file=sys.stderr
fails = fails + 1
#continue
if glyphs1 != glyphs2 and glyphs_expected != '*':
print ("FT funcs: " + glyphs1) # file=sys.stderr
print ("OT funcs: " + glyphs2) # file=sys.stderr