summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2017-07-12 20:55:00 +0000
committerSven Eden <yamakuzure@gmx.net>2017-08-10 10:07:19 +0200
commitdc430fe0f27b980fe47e393c9a66fde2145d4a7a (patch)
tree48d7696778d18908204432af04ab95e9ceed4575
parent852a2106dbb79c3a04281b6e8b78b76bc8b17b10 (diff)
test-hashmap: use $SYSTEMD_SLOW_TESTS variable
test-hashmap is a very good test, but it gets in the way when one wants to compile and quickly test changes.
-rw-r--r--src/test/test-hashmap-plain.c73
1 files changed, 70 insertions, 3 deletions
diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c
index 1bd5c02f8..0471cd2f2 100644
--- a/src/test/test-hashmap-plain.c
+++ b/src/test/test-hashmap-plain.c
@@ -18,17 +18,23 @@
***/
#include "alloc-util.h"
+#include "env-util.h"
#include "hashmap.h"
+#include "log.h"
#include "string-util.h"
#include "strv.h"
#include "util.h"
+static bool arg_slow = false;
+
void test_hashmap_funcs(void);
static void test_hashmap_replace(void) {
Hashmap *m;
char *val1, *val2, *val3, *val4, *val5, *r;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
val1 = strdup("val1");
@@ -67,6 +73,8 @@ static void test_hashmap_copy(void) {
Hashmap *m, *copy;
char *val1, *val2, *val3, *val4, *r;
+ log_info("%s", __func__);
+
val1 = strdup("val1");
assert_se(val1);
val2 = strdup("val2");
@@ -103,6 +111,8 @@ static void test_hashmap_get_strv(void) {
char **strv;
char *val1, *val2, *val3, *val4;
+ log_info("%s", __func__);
+
val1 = strdup("val1");
assert_se(val1);
val2 = strdup("val2");
@@ -139,6 +149,8 @@ static void test_hashmap_move_one(void) {
Hashmap *m, *n;
char *val1, *val2, *val3, *val4, *r;
+ log_info("%s", __func__);
+
val1 = strdup("val1");
assert_se(val1);
val2 = strdup("val2");
@@ -178,6 +190,8 @@ static void test_hashmap_move(void) {
Hashmap *m, *n;
char *val1, *val2, *val3, *val4, *r;
+ log_info("%s", __func__);
+
val1 = strdup("val1");
assert_se(val1);
val2 = strdup("val2");
@@ -220,6 +234,8 @@ static void test_hashmap_update(void) {
Hashmap *m;
char *val1, *val2, *r;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
val1 = strdup("old_value");
assert_se(val1);
@@ -250,6 +266,8 @@ static void test_hashmap_put(void) {
void *val2 = (void*) "val 2";
_cleanup_free_ char* key1 = NULL;
+ log_info("%s", __func__);
+
assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0);
assert_se(m);
@@ -268,6 +286,8 @@ static void test_hashmap_remove(void) {
_cleanup_hashmap_free_ Hashmap *m = NULL;
char *r;
+ log_info("%s", __func__);
+
r = hashmap_remove(NULL, "key 1");
assert_se(r == NULL);
@@ -296,6 +316,8 @@ static void test_hashmap_remove2(void) {
char val2[] = "val 2";
void *r, *r2;
+ log_info("%s", __func__);
+
r = hashmap_remove2(NULL, "key 1", &r2);
assert_se(r == NULL);
@@ -326,6 +348,8 @@ static void test_hashmap_remove_value(void) {
char val1[] = "val 1";
char val2[] = "val 2";
+ log_info("%s", __func__);
+
r = hashmap_remove_value(NULL, "key 1", val1);
assert_se(r == NULL);
@@ -358,6 +382,8 @@ static void test_hashmap_remove_and_put(void) {
int valid;
char *r;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
assert_se(m);
@@ -392,6 +418,8 @@ static void test_hashmap_remove_and_replace(void) {
void *r;
int i, j;
+ log_info("%s", __func__);
+
m = hashmap_new(&trivial_hash_ops);
assert_se(m);
@@ -443,6 +471,8 @@ static void test_hashmap_ensure_allocated(void) {
Hashmap *m;
int valid_hashmap;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
valid_hashmap = hashmap_ensure_allocated(&m, &string_hash_ops);
@@ -464,6 +494,8 @@ static void test_hashmap_foreach_key(void) {
"key 3\0"
"key 4\0";
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
NULSTR_FOREACH(key, key_table)
@@ -494,6 +526,8 @@ static void test_hashmap_foreach(void) {
char *val1, *val2, *val3, *val4, *s;
unsigned count;
+ log_info("%s", __func__);
+
val1 = strdup("my val1");
assert_se(val1);
val2 = strdup("my val2");
@@ -544,6 +578,8 @@ static void test_hashmap_merge(void) {
Hashmap *n;
char *val1, *val2, *val3, *val4, *r;
+ log_info("%s", __func__);
+
val1 = strdup("my val1");
assert_se(val1);
val2 = strdup("my val2");
@@ -577,6 +613,8 @@ static void test_hashmap_contains(void) {
Hashmap *m;
char *val1;
+ log_info("%s", __func__);
+
val1 = strdup("my val");
assert_se(val1);
@@ -597,6 +635,8 @@ static void test_hashmap_isempty(void) {
Hashmap *m;
char *val1;
+ log_info("%s", __func__);
+
val1 = strdup("my val");
assert_se(val1);
@@ -614,6 +654,8 @@ static void test_hashmap_size(void) {
Hashmap *m;
char *val1, *val2, *val3, *val4;
+ log_info("%s", __func__);
+
val1 = strdup("my val");
assert_se(val1);
val2 = strdup("my val");
@@ -644,6 +686,8 @@ static void test_hashmap_get(void) {
char *r;
char *val;
+ log_info("%s", __func__);
+
val = strdup("my val");
assert_se(val);
@@ -671,6 +715,8 @@ static void test_hashmap_get2(void) {
char key_orig[] = "Key 1";
void *key_copy;
+ log_info("%s", __func__);
+
val = strdup("my val");
assert_se(val);
@@ -710,14 +756,15 @@ static void test_hashmap_many(void) {
Hashmap *h;
unsigned i, j;
void *v, *k;
- static const struct {
+ const struct {
const struct hash_ops *ops;
unsigned n_entries;
} tests[] = {
- { .ops = NULL, .n_entries = 1 << 20 },
- { .ops = &crippled_hashmap_ops, .n_entries = 1 << 14 },
+ { .ops = NULL, .n_entries = arg_slow ? 1 << 20 : 240 },
+ { .ops = &crippled_hashmap_ops, .n_entries = arg_slow ? 1 << 14 : 140 },
};
+ log_info("%s (%s)", __func__, arg_slow ? "slow" : "fast");
for (j = 0; j < ELEMENTSOF(tests); j++) {
assert_se(h = hashmap_new(tests[j].ops));
@@ -748,6 +795,8 @@ static void test_hashmap_many(void) {
static void test_hashmap_first(void) {
_cleanup_hashmap_free_ Hashmap *m = NULL;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
assert_se(m);
@@ -765,6 +814,8 @@ static void test_hashmap_first(void) {
static void test_hashmap_first_key(void) {
_cleanup_hashmap_free_ Hashmap *m = NULL;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
assert_se(m);
@@ -782,6 +833,8 @@ static void test_hashmap_first_key(void) {
static void test_hashmap_steal_first_key(void) {
_cleanup_hashmap_free_ Hashmap *m = NULL;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
assert_se(m);
@@ -797,6 +850,8 @@ static void test_hashmap_steal_first(void) {
int seen[3] = {};
char *val;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
assert_se(m);
@@ -815,6 +870,8 @@ static void test_hashmap_steal_first(void) {
static void test_hashmap_clear_free_free(void) {
_cleanup_hashmap_free_ Hashmap *m = NULL;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
assert_se(m);
@@ -829,6 +886,8 @@ static void test_hashmap_clear_free_free(void) {
static void test_hashmap_reserve(void) {
_cleanup_hashmap_free_ Hashmap *m = NULL;
+ log_info("%s", __func__);
+
m = hashmap_new(&string_hash_ops);
assert_se(hashmap_reserve(m, 1) == 0);
@@ -844,6 +903,14 @@ 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();