[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
1 changed files with 12 additions and 20 deletions

View File

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