rbtree_test: add extra rbtree integrity check
authorDavidlohr Bueso <davidlohr.bueso@hp.com>
Tue, 30 Apr 2013 22:28:24 +0000 (15:28 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 1 May 2013 00:04:07 +0000 (17:04 -0700)
Account for the rbtree having  2**bh(v)-1 internal nodes.

While this can be seen as a consequence of other checks, Michel states
that it nicely sums up what the other properties are for.

Signed-off-by: Davidlohr Bueso <davidlohr.bueso@hp.com>
Reviewed-by: Michel Lespinasse <walken@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/rbtree_test.c

index af38aedbd874f0f2ad4f5411c8bfc2187aa2c738..99515038ff6dda9fb5adb3e9bc8c4be7d82a663d 100644 (file)
@@ -117,8 +117,7 @@ static int black_path_count(struct rb_node *rb)
 static void check(int nr_nodes)
 {
        struct rb_node *rb;
-       int count = 0;
-       int blacks = 0;
+       int count = 0, blacks = 0;
        u32 prev_key = 0;
 
        for (rb = rb_first(&root); rb; rb = rb_next(rb)) {
@@ -134,7 +133,9 @@ static void check(int nr_nodes)
                prev_key = node->key;
                count++;
        }
+
        WARN_ON_ONCE(count != nr_nodes);
+       WARN_ON_ONCE(count < (1 << black_path_count(rb_last(&root))) - 1);
 }
 
 static void check_augmented(int nr_nodes)