From: Keith Packard Date: Sun, 5 Jan 2025 09:18:22 -0800 Subject: Provide a way to extend test timeouts Some hardware is really slow; let users set CMARK_TIMING_SCALE to multiply the timeouts by an arbitrary amount Signed-off-by: Keith Packard --- api_test/main.c | 17 +++++++++++++++-- test/pathological_tests.py | 4 +++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api_test/main.c b/api_test/main.c index 1a41e69..790327c 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -942,6 +942,13 @@ static void test_feed_across_line_ending(test_batch_runner *runner) { # include static struct timeval _before, _after; static int _timing; +static int _timing_scale = 1; +# define SETUP_TIMING() \ + do { \ + char *scale = getenv("CMARK_TIMING_SCALE"); \ + if (scale) \ + _timing_scale = atoi(scale); \ + } while (0) # define START_TIMING() \ gettimeofday(&_before, NULL) @@ -952,10 +959,13 @@ static int _timing; } while (0) # define TIMING _timing +# define TIMING_SCALE _timing_scale #else +# define SETUP_TIMING() # define START_TIMING() # define END_TIMING() # define TIMING 0 +# define TIMING_SCALE 1 #endif static void test_pathological_regressions(test_batch_runner *runner) { @@ -973,7 +983,8 @@ static void test_pathological_regressions(test_batch_runner *runner) { free(html); free(input); - OK(runner, TIMING < 1000, "takes less than 1000ms to run"); + OK(runner, TIMING < 1000 * TIMING_SCALE, + "takes less than CMARK_TIMING_SCALE * 1000ms to run"); } { @@ -989,7 +1000,8 @@ static void test_pathological_regressions(test_batch_runner *runner) { free(html); free(input); - OK(runner, TIMING < 1000, "takes less than 1000ms to run"); + OK(runner, TIMING < 1000 * TIMING_SCALE, + "takes less than CMARK_TIMING_SCALE * 1000ms to run"); } } @@ -1133,6 +1145,7 @@ int main() { int retval; test_batch_runner *runner = test_batch_runner_new(); + SETUP_TIMING(); cmark_enable_safety_checks(true); version(runner); constructor(runner); diff --git a/test/pathological_tests.py b/test/pathological_tests.py index d0e910c..f556a1d 100644 --- a/test/pathological_tests.py +++ b/test/pathological_tests.py @@ -7,6 +7,7 @@ import sys import platform import itertools import multiprocessing +import os from cmark import CMark def hash_collisions(): @@ -106,7 +107,8 @@ whitespace_re = re.compile('/s+/') passed = 0 errored = 0 ignored = 0 -TIMEOUT = 5 +timing_scale = float(os.getenv("CMARK_TIMING_SCALE", "1")) +TIMEOUT = 5 * timing_scale def run_test(inp, regex): parser = argparse.ArgumentParser(description='Run cmark tests.')