[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260208113235.6897e631@pumpkin>
Date: Sun, 8 Feb 2026 11:32:35 +0000
From: David Laight <david.laight.linux@...il.com>
To: Yury Norov <ynorov@...dia.com>
Cc: Nathan Chancellor <nathan@...nel.org>, Greg Kroah-Hartman
<gregkh@...uxfoundation.org>, Thomas Gleixner <tglx@...utronix.de>, Peter
Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...nel.org>, Mathieu
Desnoyers <mathieu.desnoyers@...icios.com>, Arnd Bergmann <arnd@...db.de>,
linux-arch@...r.kernel.org, linux-kernel@...r.kernel.org, Yury Norov
<yury.norov@...il.com>, Lucas De Marchi <lucas.demarchi@...el.com>, Jani
Nikula <jani.nikula@...el.com>, Vincent Mailhol
<mailhol.vincent@...adoo.fr>, Andy Shevchenko
<andriy.shevchenko@...ux.intel.com>, Kees Cook <keescook@...omium.org>,
Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH next 13/14] test_bits: Change all the tests to be
compile-time tests
On Sat, 7 Feb 2026 23:37:49 -0500
Yury Norov <ynorov@...dia.com> wrote:
> On Wed, Jan 21, 2026 at 02:57:30PM +0000, david.laight.linux@...il.com wrote:
> > From: David Laight <david.laight.linux@...il.com>
> >
> > Since all the GENMASK() values are compile-time constants they can
> > be tested with BUILD_BUG_ON() rather than KUNIT_EXPECT_EQ().
> >
> > Signed-off-by: David Laight <david.laight.linux@...il.com>
>
> I thought, KUNIT invented this EXPECT_EQ macro for a nice printing
> and some accounting. If you want to make sure that __GENMASK() is a
> compile-time expression, it's OK. But I'd rather keep the existing
> KUNIT_EXPECT_EQ() and add
>
> BUILD_BUG_ON(!__builtin_constant_p(GENMASK()))
>
> next to that. This is actually how test_bitmap_const_eval() works.
That just tests that the value is a compile time constant.
You want an error if the compile time constant is the wrong value.
The point is there is no reason to do a run-time check if the compile
test fails.
Making them compile-time means they get tested by the compiler,
so you don't need to run the tests at all.
The original tests in one of these files were all _Static_assert()
at file scope, but that requires 'integer constant expressions'.
They need moving into a function to use BUILD_BUG_ON().
Perhaps the test framework(s) should have a standard scheme for
compile-time tests.
David
>
> Thanks,
> Yury
>
> > ---
> > lib/tests/test_bits.c | 90 +++++++++++++++++++++----------------------
> > 1 file changed, 45 insertions(+), 45 deletions(-)
> >
> > diff --git a/lib/tests/test_bits.c b/lib/tests/test_bits.c
> > index 36eb4661e78b..4d3a895f490c 100644
> > --- a/lib/tests/test_bits.c
> > +++ b/lib/tests/test_bits.c
> > @@ -32,30 +32,30 @@ static_assert(assert_type(u64, GENMASK_U64(63, 0)) == U64_MAX);
> >
> > static void __genmask_test(struct kunit *test)
> > {
> > - KUNIT_EXPECT_EQ(test, 1ul, __GENMASK(0, 0));
> > - KUNIT_EXPECT_EQ(test, 3ul, __GENMASK(1, 0));
> > - KUNIT_EXPECT_EQ(test, 6ul, __GENMASK(2, 1));
> > - KUNIT_EXPECT_EQ(test, 0xFFFFFFFFul, __GENMASK(31, 0));
> > + BUILD_BUG_ON(__GENMASK(0, 0) != 1ul);
> > + BUILD_BUG_ON(__GENMASK(1, 0) != 3ul);
> > + BUILD_BUG_ON(__GENMASK(2, 1) != 6ul);
> > + BUILD_BUG_ON(__GENMASK(31, 0) != 0xFFFFFFFFul);
> > }
...
Powered by blists - more mailing lists