tests: centralize check for slow tests

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2018-09-13 12:07:27 +02:00
parent c633b0a642
commit 0cf29baac0
5 changed files with 28 additions and 23 deletions
+6 -9
View File
@@ -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);
+13
View File
@@ -7,6 +7,7 @@
#include <util.h>
#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;
}
+1
View File
@@ -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);
+5 -11
View File
@@ -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();
+3 -3
View File
@@ -3,8 +3,8 @@
#include <string.h>
#include <unistd.h>
#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;