forked from Minki/linux
rhashtable: make test actually random
The "random rhlist add/delete operations" actually wasn't very random, as all cases tested the same bit. Since the later parts of this loop depend on the first case execute this unconditionally, and then test on different bits for the remaining tests. While at it only request as much random bits as are actually used. Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de> Acked-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
95a0396a06
commit
c5f0a17288
@ -369,18 +369,10 @@ static int __init test_rhltable(unsigned int entries)
|
||||
pr_info("test %d random rhlist add/delete operations\n", entries);
|
||||
for (j = 0; j < entries; j++) {
|
||||
u32 i = prandom_u32_max(entries);
|
||||
u32 prand = get_random_u32();
|
||||
u32 prand = prandom_u32_max(4);
|
||||
|
||||
cond_resched();
|
||||
|
||||
if (prand == 0)
|
||||
prand = get_random_u32();
|
||||
|
||||
if (prand & 1) {
|
||||
prand >>= 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params);
|
||||
if (test_bit(i, obj_in_table)) {
|
||||
clear_bit(i, obj_in_table);
|
||||
@ -393,35 +385,29 @@ static int __init test_rhltable(unsigned int entries)
|
||||
}
|
||||
|
||||
if (prand & 1) {
|
||||
prand >>= 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params);
|
||||
if (err == 0) {
|
||||
if (WARN(test_and_set_bit(i, obj_in_table), "succeeded to insert same object %d", i))
|
||||
continue;
|
||||
} else {
|
||||
if (WARN(!test_bit(i, obj_in_table), "failed to insert object %d", i))
|
||||
continue;
|
||||
}
|
||||
|
||||
if (prand & 1) {
|
||||
prand >>= 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
i = prandom_u32_max(entries);
|
||||
if (test_bit(i, obj_in_table)) {
|
||||
err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params);
|
||||
WARN(err, "cannot remove element at slot %d", i);
|
||||
if (err == 0)
|
||||
clear_bit(i, obj_in_table);
|
||||
} else {
|
||||
err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params);
|
||||
WARN(err, "failed to insert object %d", i);
|
||||
if (err == 0)
|
||||
set_bit(i, obj_in_table);
|
||||
if (err == 0) {
|
||||
if (WARN(test_and_set_bit(i, obj_in_table), "succeeded to insert same object %d", i))
|
||||
continue;
|
||||
} else {
|
||||
if (WARN(!test_bit(i, obj_in_table), "failed to insert object %d", i))
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (prand & 2) {
|
||||
i = prandom_u32_max(entries);
|
||||
if (test_bit(i, obj_in_table)) {
|
||||
err = rhltable_remove(&rhlt, &rhl_test_objects[i].list_node, test_rht_params);
|
||||
WARN(err, "cannot remove element at slot %d", i);
|
||||
if (err == 0)
|
||||
clear_bit(i, obj_in_table);
|
||||
} else {
|
||||
err = rhltable_insert(&rhlt, &rhl_test_objects[i].list_node, test_rht_params);
|
||||
WARN(err, "failed to insert object %d", i);
|
||||
if (err == 0)
|
||||
set_bit(i, obj_in_table);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user