Skip to content

Commit a6359bd

Browse files
Florian Westphaldavem330
authored andcommitted
test_rhashtable: add a check for max_size
add a test that tries to insert more than max_size elements. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f651616 commit a6359bd

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

lib/test_rhashtable.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,43 @@ static s64 __init test_rhashtable(struct rhashtable *ht, struct test_obj *array,
246246

247247
static struct rhashtable ht;
248248

249+
static int __init test_rhashtable_max(struct test_obj *array,
250+
unsigned int entries)
251+
{
252+
unsigned int i, insert_retries = 0;
253+
int err;
254+
255+
test_rht_params.max_size = roundup_pow_of_two(entries / 8);
256+
err = rhashtable_init(&ht, &test_rht_params);
257+
if (err)
258+
return err;
259+
260+
for (i = 0; i < ht.max_elems; i++) {
261+
struct test_obj *obj = &array[i];
262+
263+
obj->value.id = i * 2;
264+
err = insert_retry(&ht, obj, test_rht_params);
265+
if (err > 0)
266+
insert_retries += err;
267+
else if (err)
268+
return err;
269+
}
270+
271+
err = insert_retry(&ht, &array[ht.max_elems], test_rht_params);
272+
if (err == -E2BIG) {
273+
err = 0;
274+
} else {
275+
pr_info("insert element %u should have failed with %d, got %d\n",
276+
ht.max_elems, -E2BIG, err);
277+
if (err == 0)
278+
err = -1;
279+
}
280+
281+
rhashtable_destroy(&ht);
282+
283+
return err;
284+
}
285+
249286
static int thread_lookup_test(struct thread_data *tdata)
250287
{
251288
unsigned int entries = tdata->entries;
@@ -386,7 +423,11 @@ static int __init test_rht_init(void)
386423
total_time += time;
387424
}
388425

426+
pr_info("test if its possible to exceed max_size %d: %s\n",
427+
test_rht_params.max_size, test_rhashtable_max(objs, entries) == 0 ?
428+
"no, ok" : "YES, failed");
389429
vfree(objs);
430+
390431
do_div(total_time, runs);
391432
pr_info("Average test time: %llu\n", total_time);
392433

0 commit comments

Comments
 (0)