From 10e73d188a28e777b7950e37a9eed908f3a19615 Mon Sep 17 00:00:00 2001 From: Khaled Hosny Date: Sun, 1 Aug 2021 11:11:12 +0200 Subject: [PATCH] [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 --- test/subset/run-repack-tests.py | 17 ++++++++++++++--- test/subset/run-tests.py | 17 ++++++++++++++--- util/hb-subset.cc | 34 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 6 deletions(-) diff --git a/test/subset/run-repack-tests.py b/test/subset/run-repack-tests.py index 22154ba9f..2334edfee 100755 --- a/test/subset/run-repack-tests.py +++ b/test/subset/run-repack-tests.py @@ -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] diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py index c86c6bc41..c9bd58db7 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py @@ -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: diff --git a/util/hb-subset.cc b/util/hb-subset.cc index 3a69f66b9..4ad3f54b9 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -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 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 driver; return driver.main (argc, argv); }