Re: [PATCH] lib/random32: convert selftest to KUnit
From: Thomas Weißschuh <hidden>
Date: 2026-01-30 08:23:48
Also in:
linux-kselftest, linux-s390, lkml
On Sat, Jan 24, 2026 at 02:41:33PM +0900, Kir Chou wrote:
This patch converts the existing prandom selftest (lib/random32.c) to use the KUnit framework (lib/tests/random32_kunit.c). Unlike typical KUnit tests, this file is directly #included into lib/random32.c. Only the file name "random32_kunit.c" keeps random32, "prandom" is used for all other places for aligning with the API semantics and avoiding confusion with the cryptographically secure random.c, The new test: - Removes the legacy CONFIG_RANDOM32_SELFTEST.
This bit seems to be missing from the patch. 'config RANDOM32_SELFTEST' still exists in lib/Kconfig.
- Adds CONFIG_PRANDOM_KUNIT_TEST (defaulting to KUNIT_ALL_TESTS). - Moves the test logic to lib/tests/random32_kunit.c. - Updates arch/s390/configs/debug_defconfig to use the new KUnit symbol. This commit is verified by `./tools/testing/kunit/kunit.py run` with the .kunit/.kunitconfig:CONFIG_KUNIT=y CONFIG_PRANDOM_KUNIT_TEST=ySigned-off-by: Kir Chou <redacted> --- arch/s390/configs/debug_defconfig | 2 +- lib/Kconfig.debug | 12 +++ lib/random32.c | 173 +---------------------------- lib/tests/random32_kunit.c | 174 ++++++++++++++++++++++++++++++ 4 files changed, 189 insertions(+), 172 deletions(-) create mode 100644 lib/tests/random32_kunit.c
(...)
quoted hunk ↗ jump to hunk
diff --git a/lib/tests/random32_kunit.c b/lib/tests/random32_kunit.c new file mode 100644 index 000000000..ee50205b8 --- /dev/null +++ b/lib/tests/random32_kunit.c@@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test cases for random32 functions. + */ + +#include <kunit/test.h> + +static struct prandom_test1 { + u32 seed; + u32 result; +} test1[] = { + { 1U, 3484351685U }, + { 2U, 2623130059U }, + { 3U, 3125133893U }, + { 4U, 984847254U }, +}; + +static struct prandom_test2 {
These arrays can be 'const'.
+ u32 seed;
+ u32 iteration;
+ u32 result;
+} test2[] = {(...)