From: Zbigniew Jędrzejewski-Szmek Date: Wed, 12 Sep 2018 07:45:17 +0000 (+0200) Subject: tests: centralize check for slow tests X-Git-Tag: v240~722^2~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0cf29baac098787daa39efe621bcf987e1e0570d;p=thirdparty%2Fsystemd.git tests: centralize check for slow tests --- diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c index 411df3fa7ab..e3034dae696 100644 --- a/src/journal/test-compress-benchmark.c +++ b/src/journal/test-compress-benchmark.c @@ -8,6 +8,7 @@ #include "process-util.h" #include "random-util.h" #include "string-util.h" +#include "tests.h" #include "util.h" typedef int (compress_t)(const void *src, uint64_t src_size, void *dst, @@ -143,23 +144,19 @@ static void test_compress_decompress(const char* label, const char* type, int main(int argc, char *argv[]) { #if HAVE_XZ || HAVE_LZ4 const char *i; - int r; log_set_max_level(LOG_INFO); + log_parse_environment(); + log_open(); if (argc >= 2) { unsigned x; assert_se(safe_atou(argv[1], &x) >= 0); arg_duration = x * USEC_PER_SEC; - } else { - bool slow; - - r = getenv_bool("SYSTEMD_SLOW_TESTS"); - slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT; - - arg_duration = slow ? 2 * USEC_PER_SEC : USEC_PER_SEC / 50; - } + } else + arg_duration = slow_tests_enabled() ? + 2 * USEC_PER_SEC : USEC_PER_SEC / 50; if (argc == 3) (void) safe_atozu(argv[2], &arg_start); diff --git a/src/shared/tests.c b/src/shared/tests.c index 94f4629b1b8..cb5b7b6deae 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -7,6 +7,7 @@ #include #include "alloc-util.h" +#include "env-util.h" #include "fileio.h" #include "path-util.h" #include "strv.h" @@ -76,3 +77,15 @@ const char* get_catalog_dir(void) { } return env; } + +bool slow_tests_enabled(void) { + int r; + + r = getenv_bool("SYSTEMD_SLOW_TESTS"); + if (r >= 0) + return r; + + if (r != -ENXIO) + log_warning_errno(r, "Cannot parse $SYSTEMD_SLOW_TESTS, ignoring."); + return SYSTEMD_SLOW_TESTS_DEFAULT; +} diff --git a/src/shared/tests.h b/src/shared/tests.h index 0d5e6a8386a..44b52f5589d 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -4,3 +4,4 @@ char* setup_fake_runtime_dir(void); const char* get_testdata_dir(void); const char* get_catalog_dir(void); +bool slow_tests_enabled(void); diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index f80febce76b..82837da4f62 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -1,15 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ #include "alloc-util.h" -#include "env-util.h" #include "hashmap.h" #include "log.h" #include "string-util.h" #include "strv.h" +#include "tests.h" #include "util.h" -static bool arg_slow = false; - void test_hashmap_funcs(void); static void test_hashmap_replace(void) { @@ -739,15 +737,16 @@ static void test_hashmap_many(void) { Hashmap *h; unsigned i, j; void *v, *k; + bool slow = slow_tests_enabled(); const struct { const struct hash_ops *ops; unsigned n_entries; } tests[] = { - { .ops = NULL, .n_entries = arg_slow ? 1 << 20 : 240 }, - { .ops = &crippled_hashmap_ops, .n_entries = arg_slow ? 1 << 14 : 140 }, + { .ops = NULL, .n_entries = slow ? 1 << 20 : 240 }, + { .ops = &crippled_hashmap_ops, .n_entries = slow ? 1 << 14 : 140 }, }; - log_info("%s (%s)", __func__, arg_slow ? "slow" : "fast"); + log_info("%s (%s)", __func__, slow ? "slow" : "fast"); for (j = 0; j < ELEMENTSOF(tests); j++) { assert_se(h = hashmap_new(tests[j].ops)); @@ -886,14 +885,9 @@ static void test_hashmap_reserve(void) { } void test_hashmap_funcs(void) { - int r; - log_parse_environment(); log_open(); - r = getenv_bool("SYSTEMD_SLOW_TESTS"); - arg_slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT; - test_hashmap_copy(); test_hashmap_get_strv(); test_hashmap_move_one(); diff --git a/src/test/test-watchdog.c b/src/test/test-watchdog.c index 2aba3b5a26c..d595ae27d52 100644 --- a/src/test/test-watchdog.c +++ b/src/test/test-watchdog.c @@ -3,8 +3,8 @@ #include #include -#include "env-util.h" #include "log.h" +#include "tests.h" #include "watchdog.h" int main(int argc, char *argv[]) { @@ -15,9 +15,9 @@ int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); log_parse_environment(); + log_open(); - r = getenv_bool("SYSTEMD_SLOW_TESTS"); - slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT; + slow = slow_tests_enabled(); t = slow ? 10 * USEC_PER_SEC : 1 * USEC_PER_SEC; count = slow ? 5 : 3;