Re: [PATCH v5 2/2] lib/prime_numbers: convert self-test to KUnit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kees, it looks like the private header didn't make it to your tree.
This bit is missing:

diff --git a/lib/math/prime_numbers.c b/lib/math/prime_numbers.c
index f88d6e64dbdc..de59f001c8c7 100644
--- a/lib/math/prime_numbers.c
+++ b/lib/math/prime_numbers.c
@@ -58,6 +58,7 @@ static DEFINE_MUTEX(lock);
 static const struct primes __rcu *primes = RCU_INITIALIZER(&small_primes);

 #if IS_ENABLED(CONFIG_PRIME_NUMBERS_KUNIT_TEST)
+// Calls the callback under RCU lock. The callback must not retain
the primes pointer.
 void with_primes(void *ctx, primes_fn fn)
 {
        rcu_read_lock();
diff --git a/lib/math/prime_numbers_private.h b/lib/math/prime_numbers_private.h
new file mode 100644
index 000000000000..f3ebf5386e6b
--- /dev/null
+++ b/lib/math/prime_numbers_private.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#include <linux/types.h>
+
+struct primes {
+       struct rcu_head rcu;
+       unsigned long last, sz;
+       unsigned long primes[];
+};
+
+#if IS_ENABLED(CONFIG_PRIME_NUMBERS_KUNIT_TEST)
+typedef void (*primes_fn)(void *, const struct primes *);
+
+void with_primes(void *ctx, primes_fn fn);
+bool slow_is_prime_number(unsigned long x);
+#endif

Tamir

On Mon, Feb 10, 2025 at 9:52 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
>
> Ah, I see https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=for-next/move-kunit-tests&id=3e50ba8fc834cadead733e4feeb969fce2f3b6e1
> now.
>
> On Mon, Feb 10, 2025 at 9:47 PM Tamir Duberstein <tamird@xxxxxxxxx> wrote:
> >
> > On Mon, Feb 10, 2025 at 9:37 PM Kees Cook <kees@xxxxxxxxxx> wrote:
> > >
> > > On Sat, Feb 08, 2025 at 09:44:39PM -0500, Tamir Duberstein wrote:
> > > > Extract a private header and convert the prime_numbers self-test to a
> > > > KUnit test. I considered parameterizing the test using
> > > > `KUNIT_CASE_PARAM` but didn't see how it was possible since the test
> > > > logic is entangled with the test parameter generation logic.
> > > >
> > > > Signed-off-by: Tamir Duberstein <tamird@xxxxxxxxx>
> > > > ---
> > > >  lib/Kconfig.debug                            | 14 +++++
> > > >  lib/math/prime_numbers.c                     | 87 +++++-----------------------
> > > >  lib/math/prime_numbers_private.h             | 17 ++++++
> > > >  lib/math/tests/Makefile                      |  1 +
> > > >  lib/math/tests/prime_numbers_kunit.c         | 59 +++++++++++++++++++
> > > >  tools/testing/selftests/lib/config           |  1 -
> > > >  tools/testing/selftests/lib/prime_numbers.sh |  4 --
> > > >  7 files changed, 106 insertions(+), 77 deletions(-)
> > >
> > > Thanks! I've applied this and rebased it onto:
> > > https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=for-next/move-kunit-tests
> > >
> > > --
> > > Kees Cook
> >
> > Thanks! Could you also take the first patch in the series[0]? The new
> > test won't build without it because lib/math/tests/Makefile is dead
> > code.
> >
> > [0] https://lore.kernel.org/all/20250208-prime_numbers-kunit-convert-v5-1-b0cb82ae7c7d@xxxxxxxxx/
> >
> > Cheers.
> > Tamir





[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux