[test] Add batch mode to hb-subset and use it

time meson test --suite=subset down from:
real	0m22.822s
user	0m44.561s
sys	0m9.255s

to:
real	0m19.418s
user	0m38.171s
sys	0m3.587s

Does not seem to help much, but it is something.

Part of https://github.com/harfbuzz/harfbuzz/issues/3089
This commit is contained in:
Khaled Hosny 2021-08-01 11:11:12 +02:00 committed by Behdad Esfahbod
parent 75f314c471
commit 10e73d188a
3 changed files with 62 additions and 6 deletions

View File

@ -22,6 +22,12 @@ except ImportError:
ots_sanitize = shutil.which ("ots-sanitize")
def subset_cmd (command):
global process
process.stdin.write ((';'.join (command) + '\n').encode ("utf-8"))
process.stdin.flush ()
return process.stdout.readline().decode ("utf-8").strip ()
def cmd (command):
p = subprocess.Popen (
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
@ -45,10 +51,10 @@ def run_test (test, should_check_ots):
"--unicodes=%s" % test.codepoints_string (),
"--drop-tables-=GPOS,GSUB,GDEF",]
print (' '.join (cli_args))
_, return_code = cmd (cli_args)
ret = subset_cmd (cli_args)
if return_code:
return fail_test (test, cli_args, "%s returned %d" % (' '.join (cli_args), return_code))
if ret != "success":
return fail_test (test, cli_args, "%s failed" % ' '.join (cli_args))
try:
with TTFont (out_file) as font:
@ -87,6 +93,11 @@ if len (args) != 1:
has_ots = has_ots()
process = subprocess.Popen ([hb_subset, '--batch'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=sys.stdout)
fails = 0
path = args[0]

View File

@ -22,6 +22,12 @@ except ImportError:
ots_sanitize = shutil.which ("ots-sanitize")
def subset_cmd (command):
global process
process.stdin.write ((';'.join (command) + '\n').encode ("utf-8"))
process.stdin.flush ()
return process.stdout.readline().decode ("utf-8").strip ()
def cmd (command):
p = subprocess.Popen (
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
@ -51,10 +57,10 @@ def run_test (test, should_check_ots):
"--drop-tables-=sbix"]
cli_args.extend (test.get_profile_flags ())
print (' '.join (cli_args))
_, return_code = cmd (cli_args)
ret = subset_cmd (cli_args)
if return_code:
return fail_test (test, cli_args, "%s returned %d" % (' '.join (cli_args), return_code))
if ret != "success":
return fail_test (test, cli_args, "%s failed" % ' '.join (cli_args))
expected_file = os.path.join (test_suite.get_output_directory (), test.get_font_ttx_name ())
with open(expected_file, encoding="utf-8") as expected_ttx:
@ -115,6 +121,11 @@ if not len (args):
has_ots = has_ots()
process = subprocess.Popen ([hb_subset, '--batch'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=sys.stdout)
fails = 0
for path in args:
with open (path, mode="r", encoding="utf-8") as f:

View File

@ -130,6 +130,40 @@ struct subset_consumer_t
int
main (int argc, char **argv)
{
if (argc == 2 && !strcmp (argv[1], "--batch"))
{
unsigned int ret = 0;
char buf[4092];
while (fgets (buf, sizeof (buf), stdin))
{
size_t l = strlen (buf);
if (l && buf[l - 1] == '\n') buf[l - 1] = '\0';
main_font_text_t<subset_consumer_t, 10, 0, EOF> driver;
char *args[32];
argc = 0;
char *p = buf, *e;
args[argc++] = p;
unsigned start_offset = 0;
while ((e = strchr (p + start_offset, ';')) && argc < (int) ARRAY_LENGTH (args))
{
*e++ = '\0';
while (*e == ':')
e++;
args[argc++] = p = e;
}
int result = driver.main (argc, args);
if (result == 0)
fprintf (stdout, "success\n");
else
fprintf (stdout, "failure\n");
ret |= result;
fflush (stdout);
if (ret)
break;
}
return ret;
}
main_font_text_t<subset_consumer_t, 10, 0> driver;
return driver.main (argc, argv);
}