hash table tests: Add initial hash population to glib hash table test
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 4 Sep 2011 16:39:23 +0000 (12:39 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sun, 4 Sep 2011 16:39:23 +0000 (12:39 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_glib_hash.c

index 7fed39b9c1659538959aa12eabc3578e5fdd331c..3043557aba96fe8644f567091fece942ac15bc20 100644 (file)
@@ -175,6 +175,7 @@ pthread_mutex_t rcu_copy_mutex = PTHREAD_MUTEX_INITIALIZER;
 void rcu_copy_mutex_lock(void)
 {
        int ret;
+
        ret = pthread_mutex_lock(&rcu_copy_mutex);
        if (ret) {
                perror("Error in pthread mutex lock");
@@ -483,13 +484,20 @@ void *thr_writer(void *_count)
        return ((void*)2);
 }
 
-static void populate_hash(void)
+static int populate_hash(void)
 {
        struct cds_lfht_node *node, *lookup_node;
        void *key;
 
        if (!init_populate)
-               return;
+               return 0;
+
+       if (add_unique && init_populate * 10 > rand_pool) {
+               printf("WARNING: required to populate %lu nodes (-k), but random"
+"pool is quite small (%lu values) and we are in add_unique (-u) mode. Try with a "
+"larger random pool (-p option).\n", init_populate, rand_pool);
+               return -1;
+       }
 
        while (nr_add < init_populate) {
                node = malloc(1);
@@ -514,6 +522,7 @@ static void populate_hash(void)
                }
                nr_writes++;
        }
+       return 0;
 }
 
 static
@@ -666,7 +675,8 @@ int main(int argc, char **argv)
        count_writer = malloc(sizeof(*count_writer) * nr_writers);
        test_ht = g_hash_table_new_full(test_hash_fct, test_compare_fct,
                        NULL, free);
-       populate_hash();
+       ret = populate_hash();
+       assert(!ret);
         err = create_all_cpu_call_rcu_data(0);
         assert(!err);
 
This page took 0.026538 seconds and 4 git commands to generate.