RCU RB tree test : add prev/next/max/min test
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 May 2011 02:18:24 +0000 (22:18 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 30 May 2011 02:18:24 +0000 (22:18 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/test_urcu_rbtree.c

index 757b9409f09b66ffd5798f456dec955b71ca79c3..e0beb6ffcdfa59ecb85728336f7e84d635dd6336 100644 (file)
@@ -209,11 +209,24 @@ void rcu_copy_mutex_unlock(void)
        }
 }
 
+static
+int lookup_index(struct rcu_rbtree_node *node)
+{
+       int i;
+
+       for (i = 0; i < global_items; i++) {
+               if (node->key == global_key[i])
+                       return i;
+       }
+       return -1;
+}
+
 void *thr_reader(void *_count)
 {
        unsigned long long *count = _count;
        struct rcu_rbtree_node *node;
-       int i;
+       int i, index;
+       char *lookup_hit;
 
        printf_verbose("thread_begin %s, thread id : %lx, tid %lu\n",
                        "reader", pthread_self(), (unsigned long)gettid());
@@ -222,6 +235,8 @@ void *thr_reader(void *_count)
 
        rcu_register_thread();
 
+       lookup_hit = malloc(sizeof(*lookup_hit) * global_items);
+
        while (!test_go)
        {
        }
@@ -229,6 +244,7 @@ void *thr_reader(void *_count)
 
        for (;;) {
 
+               /* search */
                for (i = 0; i < global_items; i++) {
                        rcu_read_lock();
                        node = rcu_rbtree_search(&rbtree,
@@ -237,6 +253,40 @@ void *thr_reader(void *_count)
                        assert(!rcu_rbtree_is_nil(node));
                        rcu_read_unlock();
                }
+               /* min + next */
+               memset(lookup_hit, 0, sizeof(*lookup_hit) * global_items);
+
+               rcu_read_lock();
+               node = rcu_rbtree_min(&rbtree,
+                                     rcu_dereference(rbtree.root));
+               while (!rcu_rbtree_is_nil(node)) {
+                       index = lookup_index(node);
+                       if (index >= 0)
+                               lookup_hit[index] = 1;
+                       node = rcu_rbtree_next(&rbtree, node);
+               }
+               rcu_read_unlock();
+
+               for (i = 0; i < global_items; i++)
+                       assert(lookup_hit[i]);
+
+               /* max + prev */
+               memset(lookup_hit, 0, sizeof(*lookup_hit) * global_items);
+
+               rcu_read_lock();
+               node = rcu_rbtree_max(&rbtree,
+                                     rcu_dereference(rbtree.root));
+               while (!rcu_rbtree_is_nil(node)) {
+                       index = lookup_index(node);
+                       if (index >= 0)
+                               lookup_hit[index] = 1;
+                       node = rcu_rbtree_prev(&rbtree, node);
+               }
+               rcu_read_unlock();
+
+               for (i = 0; i < global_items; i++)
+                       assert(lookup_hit[i]);
+
                debug_yield_read();
                if (unlikely(rduration))
                        loop_sleep(rduration);
@@ -251,6 +301,8 @@ void *thr_reader(void *_count)
        rcu_register_thread();
        rcu_unregister_thread();
 
+       free(lookup_hit);
+
        *count = nr_reads;
        printf_verbose("thread_end %s, thread id : %lx, tid %lu\n",
                        "reader", pthread_self(), (unsigned long)gettid());
This page took 0.027208 seconds and 4 git commands to generate.