From 422debb830fe150c26e1628f77531f41f0871325 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 30 Oct 2018 00:51:43 -0700 Subject: [PATCH] [test/shaping] Spawn one hb-shape per test file Speeds up runnings in-house tests from over 20s to 2s. --- test/shaping/run-tests.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/test/shaping/run-tests.py b/test/shaping/run-tests.py index f77a17c3d..99c0a59f0 100755 --- a/test/shaping/run-tests.py +++ b/test/shaping/run-tests.py @@ -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