Skip to content

Commit 4130f0e

Browse files
Davidlohr Buesotorvalds
authored andcommitted
rbtree_test: add extra rbtree integrity check
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>
1 parent 31c3a3f commit 4130f0e

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

‎lib/rbtree_test.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ static int black_path_count(struct rb_node *rb)
117117
static void check(int nr_nodes)
118118
{
119119
struct rb_node *rb;
120-
int count = 0;
121-
int blacks = 0;
120+
int count = 0, blacks = 0;
122121
u32 prev_key = 0;
123122

124123
for (rb = rb_first(&root); rb; rb = rb_next(rb)) {
@@ -134,7 +133,9 @@ static void check(int nr_nodes)
134133
prev_key = node->key;
135134
count++;
136135
}
136+
137137
WARN_ON_ONCE(count != nr_nodes);
138+
WARN_ON_ONCE(count < (1 << black_path_count(rb_last(&root))) - 1);
138139
}
139140

140141
static void check_augmented(int nr_nodes)

0 commit comments

Comments
 (0)