chiark / gitweb /
test-hashmap: use $SYSTEMD_SLOW_TESTS variable
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 12 Jul 2017 20:55:00 +0000 (20:55 +0000)
committerSven Eden <yamakuzure@gmx.net>
Thu, 10 Aug 2017 08:07:19 +0000 (10:07 +0200)
test-hashmap is a very good test, but it gets in the way when one wants to
compile and quickly test changes.

src/test/test-hashmap-plain.c

index 1bd5c02f8789a9547d16727d7e7996728e6c7ad4..0471cd2f2f42c498227b62f55511e694c0143aa9 100644 (file)
 ***/
 
 #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();