mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
mm/damon/tests/core-kunit: test damon_rand()
Commit 9012c4e647 ("mm/damon: replace damon_rand() with a per-ctx
lockless PRNG") optimized DAMON for better performance. Add a kunit test
for ensuring the bounds of the output.
Link: https://lore.kernel.org/20260630141726.92246-4-sj@kernel.org
Signed-off-by: SJ Park <sj@kernel.org>
Cc: Brendan Higgins <brendan.higgins@linux.dev>
Cc: David Hildenbrand <david@kernel.org>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Liam R. Howlett <liam@infradead.org>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
fb6e06631d
commit
5b3c43405a
|
|
@ -1546,6 +1546,20 @@ static void damon_test_walk_control_obsolete(struct kunit *test)
|
|||
damon_destroy_ctx(ctx);
|
||||
}
|
||||
|
||||
static void damon_test_rand(struct kunit *test)
|
||||
{
|
||||
struct damon_ctx ctx;
|
||||
int i;
|
||||
|
||||
prandom_seed_state(&ctx.rnd_state, get_random_u64());
|
||||
for (i = 0; i < 10000; i++) {
|
||||
unsigned long rnd = damon_rand(&ctx, 0, 10);
|
||||
|
||||
KUNIT_EXPECT_GE(test, rnd, 0);
|
||||
KUNIT_EXPECT_LE(test, rnd, 9);
|
||||
}
|
||||
}
|
||||
|
||||
static struct kunit_case damon_test_cases[] = {
|
||||
KUNIT_CASE(damon_test_target),
|
||||
KUNIT_CASE(damon_test_regions),
|
||||
|
|
@ -1577,6 +1591,7 @@ static struct kunit_case damon_test_cases[] = {
|
|||
KUNIT_CASE(damon_test_apply_min_nr_regions),
|
||||
KUNIT_CASE(damon_test_is_last_region),
|
||||
KUNIT_CASE(damon_test_walk_control_obsolete),
|
||||
KUNIT_CASE(damon_test_rand),
|
||||
{},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user