From: Tobias Brunner Date: Mon, 22 Aug 2022 09:48:29 +0000 (+0200) Subject: unit-tests: Add environment variable to only run specific iterations X-Git-Tag: 5.9.8dr4~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=644f74ad8f41d5d92dd465a930b86637902b93a6;p=thirdparty%2Fstrongswan.git unit-tests: Add environment variable to only run specific iterations Helpful when running with increased verbosity and only specific iterations fail. --- diff --git a/src/libstrongswan/tests/test_runner.c b/src/libstrongswan/tests/test_runner.c index 71da513f0f..af1faf4730 100644 --- a/src/libstrongswan/tests/test_runner.c +++ b/src/libstrongswan/tests/test_runner.c @@ -568,6 +568,37 @@ static double end_timing(struct timespec *start) #endif /* CLOCK_THREAD_CPUTIME_ID */ +/** + * Determine the configured iterations to run + */ +static hashtable_t *get_iterations() +{ + enumerator_t *enumerator; + hashtable_t *config = NULL; + char *iterations, *iter; + + iterations = getenv("TESTS_ITERATIONS"); + if (!iterations) + { + return NULL; + } + + config = hashtable_create(hashtable_hash_ptr, hashtable_equals_ptr, 8); + enumerator = enumerator_create_token(iterations, ",", " "); + while (enumerator->enumerate(enumerator, &iter)) + { + /* add 1 so we can store 0 */ + config->put(config, (void*)(uintptr_t)atoi(iter)+1, config); + } + enumerator->destroy(enumerator); + if (!config->get_count(config)) + { + config->destroy(config); + config = NULL; + } + return config; +} + /** * Run a single test case with fixtures */ @@ -576,6 +607,7 @@ static bool run_case(test_case_t *tcase, test_runner_init_t init, char *cfg, { enumerator_t *enumerator; test_function_t *tfun; + hashtable_t *iterations; double *times; double total_time = 0; int tests = 0, ti = 0, passed = 0; @@ -596,13 +628,20 @@ static bool run_case(test_case_t *tcase, test_runner_init_t init, char *cfg, fprintf(stderr, " Running case '%s': ", tcase->name); fflush(stderr); + iterations = get_iterations(); + enumerator = array_create_enumerator(tcase->functions); while (enumerator->enumerate(enumerator, &tfun)) { - int i, rounds = 0; + int i, rounds = 0, skipped = 0; for (i = tfun->start; i < tfun->end; i++) { + if (iterations && !iterations->get(iterations, (void*)(uintptr_t)i+1)) + { + skipped++; + continue; + } if (pre_test(init, cfg)) { struct timespec start; @@ -671,7 +710,7 @@ static bool run_case(test_case_t *tcase, test_runner_init_t init, char *cfg, } } fflush(stderr); - if (rounds == tfun->end - tfun->start) + if (rounds == tfun->end - tfun->start - skipped) { passed++; } @@ -698,6 +737,7 @@ static bool run_case(test_case_t *tcase, test_runner_init_t init, char *cfg, print_failures(failures, FALSE); array_destroy(failures); array_destroy(warnings); + DESTROY_IF(iterations); return passed == array_count(tcase->functions); }