From 29a3eee5cafb3b2be002090ddcc1da3199f6abf5 Mon Sep 17 00:00:00 2001 From: Azat Khuzhin Date: Mon, 28 Oct 2024 22:06:29 +0100 Subject: [PATCH] test: add --repeat option into tinytest --- test/tinytest.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/test/tinytest.c b/test/tinytest.c index 8f3b53dc..8d088edd 100644 --- a/test/tinytest.c +++ b/test/tinytest.c @@ -74,6 +74,7 @@ static int opt_verbosity = 1; /**< -==quiet,0==terse,1==normal,2==verbose */ static unsigned int opt_timeout = DEFAULT_TESTCASE_TIMEOUT; /**< Timeout for every test (using alarm()) */ static unsigned int opt_retries = 3; /**< How much test with TT_RETRIABLE should be retried */ static unsigned int opt_retries_delay = 1; /**< How much seconds to delay before retrying */ +static unsigned int opt_repeat = 0; /**< How much times to repeat the test */ const char *verbosity_flag = ""; const struct testlist_alias_t *cfg_aliases=NULL; @@ -409,6 +410,7 @@ usage(struct testgroup_t *groups, int list_groups) puts(" --timeout "); puts(" --retries "); puts(" --retries-delay "); + puts(" --repeat "); puts(""); puts(" Specify tests by name, or using a prefix ending with '..'"); puts(" To skip a test, prefix its name with a colon."); @@ -527,6 +529,13 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups) return -1; } opt_retries_delay = (unsigned)atoi(v[i]); + } else if (!strcmp(v[i], "--repeat")) { + ++i; + if (i >= c) { + fprintf(stderr, "--repeat requires argument\n"); + return -1; + } + opt_repeat = (unsigned)atoi(v[i]); } else { fprintf(stderr, "Unknown option %s. Try --help\n", v[i]); return -1; @@ -552,24 +561,26 @@ tinytest_main(int c, const char **v, struct testgroup_t *groups) struct testcase_t *testcase = &group->cases[j]; int retriable = testcase->flags & TT_RETRIABLE; int attempts = retriable ? opt_retries : 0; - int test_ret_err; + int test_ret_err = FAIL; if (!(testcase->flags & TT_ENABLED_)) continue; - for (;;) { - test_ret_err = testcase_run_one(group, testcase, attempts); + for (unsigned k = 0; k < opt_repeat + 1; ++k) { + for (;;) { + test_ret_err = testcase_run_one(group, testcase, attempts); - if (test_ret_err == OK) - break; - if (!attempts--) - break; - printf("\n [RETRYING %s%s (attempts left %i, delay %i sec)]\n", group->prefix, testcase->name, attempts, opt_retries_delay); + if (test_ret_err == OK) + break; + if (!attempts--) + break; + printf("\n [RETRYING %s%s (attempts left %i, delay %i sec)]\n", group->prefix, testcase->name, attempts, opt_retries_delay); #ifdef _WIN32 - Sleep(opt_retries_delay * 1000); + Sleep(opt_retries_delay * 1000); #else - sleep(opt_retries_delay); + sleep(opt_retries_delay); #endif + } } switch (test_ret_err) {