mirror of
https://github.com/torvalds/linux.git
synced 2026-07-30 03:01:41 +02:00
bcachefs: Add eytzinger0_find self test
Function eytzinger0_find() isn't currently covered, so add a self test. We can rely on eytzinger0_find_le() here because it is being tested independently. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
63ce189b00
commit
956032edd2
|
|
@ -899,11 +899,40 @@ static void eytzinger0_find_test_ge(u16 *test_array, unsigned nr, u16 search)
|
|||
}
|
||||
}
|
||||
|
||||
static void eytzinger0_find_test_eq(u16 *test_array, unsigned nr, u16 search)
|
||||
{
|
||||
unsigned r;
|
||||
int s;
|
||||
bool bad;
|
||||
|
||||
r = eytzinger0_find(test_array, nr,
|
||||
sizeof(test_array[0]),
|
||||
cmp_u16, &search);
|
||||
|
||||
if (r < nr) {
|
||||
bad = test_array[r] != search;
|
||||
} else {
|
||||
s = eytzinger0_find_le(test_array, nr,
|
||||
sizeof(test_array[0]),
|
||||
cmp_u16, &search);
|
||||
bad = s >= 0 && test_array[s] == search;
|
||||
}
|
||||
|
||||
if (bad) {
|
||||
eytzinger0_for_each(j, nr)
|
||||
pr_info("[%3u] = %12u\n", j, test_array[j]);
|
||||
pr_info("find(%12u) = %3i is incorrect\n",
|
||||
search, r);
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
static void eytzinger0_find_test_val(u16 *test_array, unsigned nr, u16 search)
|
||||
{
|
||||
eytzinger0_find_test_le(test_array, nr, search);
|
||||
eytzinger0_find_test_gt(test_array, nr, search);
|
||||
eytzinger0_find_test_ge(test_array, nr, search);
|
||||
eytzinger0_find_test_eq(test_array, nr, search);
|
||||
}
|
||||
|
||||
void eytzinger0_find_test(void)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user