DAMON development mailing list
 help / color / mirror / Atom feed
From: SeongJae Park <sj@kernel.org>
To: sashiko-bot@kernel.org
Cc: SeongJae Park <sj@kernel.org>, damon@lists.linux.dev
Subject: Re: [RFC PATCH v1.1 03/11] mm/damon/tests/core-kunit: test damon_rand()
Date: Wed, 24 Jun 2026 22:37:50 -0700	[thread overview]
Message-ID: <20260625053751.92864-1-sj@kernel.org> (raw)
In-Reply-To: <20260625051352.040991F00A3A@smtp.kernel.org>

On Thu, 25 Jun 2026 05:13:51 +0000 sashiko-bot@kernel.org wrote:

> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Medium] The KUnit test uses a non-deterministic seed with tight probability bounds, which will cause sporadic test failures.
> --
> 
> commit bc9f1073820b74c3fbb6ac52d5ca363629f99f3d
> Author: SeongJae Park <sj@kernel.org>
> 
> mm/damon/tests/core-kunit: test damon_rand()
> 
> Commit 9012c4e647df ("mm/damon: replace damon_rand() with a per-ctx
> lockless PRNG") optimized DAMON for better performance.  Add a kunit
> test for ensuring the pseudo randomness quality.
> 
> > diff --git a/mm/damon/tests/core-kunit.h b/mm/damon/tests/core-kunit.h
> > index 1cfb8c176b873..756f3b9e2ed3b 100644
> > --- a/mm/damon/tests/core-kunit.h
> > +++ b/mm/damon/tests/core-kunit.h
> 
> [ ... ]
> 
> > @@ -1460,6 +1460,26 @@ static void damon_test_is_last_region(struct kunit *test)
> >  	damon_free_target(t);
> >  }
> >  
> > +static void damon_test_rand(struct kunit *test)
> > +{
> > +	struct damon_ctx ctx;
> > +	int counts[10] = {};
> > +	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);
> > +		counts[rnd]++;
> > +	}
> > +	for (i = 0; i < 10; i++) {
> > +		KUNIT_EXPECT_GE(test, counts[i], 900);
> > +		KUNIT_EXPECT_LE(test, counts[i], 1100);
> 
> [Severity: Medium]
> The test uses a true random seed to initialize the PRNG state, making the
> test output non-deterministic. Is it possible that these tight expectation
> bounds will cause sporadic test failures in automated CI environments?
> 
> Statistically, a binomial distribution with n=10,000 and p=0.1 has a
> standard deviation of 30. The allowed variation of +/- 100 is roughly
> +/- 3.33 standard deviations. The probability of any single bin falling
> outside this range is around 0.086%.
> 
> Over 10 bins, does this mean the test could spuriously fail about 0.86%
> of the time (roughly 1 in 117 runs)?

Good catch.  I will modify the test to widen the bound to [800, 1200].


Thanks,
SJ

[...]

  reply	other threads:[~2026-06-25  5:38 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25  5:07 [RFC PATCH v1.1 00/11] mm/damon: update, optimize, and clean up doc, tests, and code SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 01/11] Docs/mm/damon/design: update for DAMOS_QUOTA_NODE_ELIGIBLE_MEM_BP SeongJae Park
2026-06-25  5:13   ` sashiko-bot
2026-06-25  5:20     ` SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 02/11] Docs/ABI/damon: document probe files SeongJae Park
2026-06-25  5:14   ` sashiko-bot
2026-06-25  5:25     ` SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 03/11] mm/damon/tests/core-kunit: test damon_rand() SeongJae Park
2026-06-25  5:13   ` sashiko-bot
2026-06-25  5:37     ` SeongJae Park [this message]
2026-06-25 14:08       ` SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 04/11] selftests/damon/sysfs.sh: test multiple probe dirs creation SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 05/11] selftests/damon/sysfs.sh: test {core,ops}_filters/ directories SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 06/11] selftests/damon/sysfs.sh: test dests dir SeongJae Park
2026-06-25  5:14   ` sashiko-bot
2026-06-25  5:42     ` SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 07/11] selftests/damon/sysfs.sh: test all files in quota goal dir SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 08/11] mm/damon/core: reduce range setup in damon_commit_target_regions() SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 09/11] mm/damon/sysfs: split probe setup function out SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 10/11] mm/damon/sysfs: split out filters setup function SeongJae Park
2026-06-25  5:07 ` [RFC PATCH v1.1 11/11] mm/damon/sysfs: fix typos in probe_{add,rm}_dirs: s/attr/probe/ SeongJae Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260625053751.92864-1-sj@kernel.org \
    --to=sj@kernel.org \
    --cc=damon@lists.linux.dev \
    --cc=sashiko-bot@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox