Skip to content

Commit

Permalink
radix tree test suite: Add test for idr_get_next()
Browse files Browse the repository at this point in the history
Assert that idr_get_next() returns the next populated entry in the tree with
an ID greater than or equal to the value pointed to by @nextid argument.

Signed-off-by: Rehas Sachdeva <[email protected]>
Signed-off-by: Matthew Wilcox <[email protected]>
  • Loading branch information
rehassachdeva authored and Matthew Wilcox committed Mar 7, 2017
1 parent 2d6be4a commit 2eacc79
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tools/testing/radix-tree/idr-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,30 @@ void idr_nowait_test(void)
idr_destroy(&idr);
}

void idr_get_next_test(void)
{
unsigned long i;
int nextid;
DEFINE_IDR(idr);

int indices[] = {4, 7, 9, 15, 65, 128, 1000, 99999, 0};

for(i = 0; indices[i]; i++) {
struct item *item = item_create(indices[i], 0);
assert(idr_alloc(&idr, item, indices[i], indices[i+1],
GFP_KERNEL) == indices[i]);
}

for(i = 0, nextid = 0; indices[i]; i++) {
idr_get_next(&idr, &nextid);
assert(nextid == indices[i]);
nextid++;
}

idr_for_each(&idr, item_idr_free, &idr);
idr_destroy(&idr);
}

void idr_checks(void)
{
unsigned long i;
Expand Down Expand Up @@ -202,6 +226,7 @@ void idr_checks(void)
idr_alloc_test();
idr_null_test();
idr_nowait_test();
idr_get_next_test();
}

/*
Expand Down

0 comments on commit 2eacc79

Please sign in to comment.