lib/random32: convert selftest to KUnit
Subsystems (5)
PATCH 1/1 lib/random32: convert selftest to KUnit
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.
- 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=y ```
--- 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
arch/s390/configs/debug_defconfig +1 -1
@@ -827,7 +827,7 @@ CONFIG_CRYPTO_KRB5=m CONFIG_CRYPTO_KRB5_SELFTESTS=y CONFIG_CORDIC=m CONFIG_TRACE_MMIO_ACCESS=y -CONFIG_RANDOM32_SELFTEST=y +CONFIG_PRANDOM_KUNIT_TEST=y CONFIG_XZ_DEC_MICROLZMA=y CONFIG_DMA_CMA=y CONFIG_CMA_SIZE_MBYTES=0
lib/Kconfig.debug +12 -0
@@ -3354,6 +3354,18 @@ config PRIME_NUMBERS_KUNIT_TEST If unsure, say N +config PRANDOM_KUNIT_TEST + tristate "KUnit test for prandom" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Enable this option to test the prandom functions at runtime. + + This test suite verifies the correctness of the pseudo-random number + generator across various scenarios, including edge cases. + + If unsure, say N + endif # RUNTIME_TESTING_MENU config ARCH_USE_MEMTEST
lib/random32.c +2 -171
177 lines not on this page · raw message
lib/tests/random32_kunit.c new file +174 -0
174 lines not on this page · raw message
Signature · 1 line
2.52.0
Quoted 18 lines · Kir Chou
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 intolib/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 securerandom.c,The new test:
- Removes the legacyCONFIG_RANDOM32_SELFTEST.
- AddsCONFIG_PRANDOM_KUNIT_TEST(defaulting toKUNIT_ALL_TESTS).
- Moves the test logic tolib/tests/random32_kunit.c.
- Updatesarch/s390/configs/debug_defconfigto use the new KUnit symbol.This commit is verified by
./tools/testing/kunit/kunit.py runwith the .kunit/.kunitconfig:
Quoted 7 lines
``` CONFIG_KUNIT=y CONFIG_PRANDOM_KUNIT_TEST=y ```Signed-off-by Kir Chou <[email protected]>---
Looks good to me. Thanks very much!
Cheers,
-- David
Quoted 10 lines · Kir Chou
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 intolib/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 securerandom.c,The new test:
- Removes the legacyCONFIG_RANDOM32_SELFTEST.
This bit seems to be missing from the patch. 'config RANDOM32_SELFTEST' still exists in lib/Kconfig.
Quoted 21 lines
- Adds
CONFIG_PRANDOM_KUNIT_TEST(defaulting toKUNIT_ALL_TESTS).
- Moves the test logic tolib/tests/random32_kunit.c.
- Updatesarch/s390/configs/debug_defconfigto use the new KUnit symbol.This commit is verified by
./tools/testing/kunit/kunit.py runwith the .kunit/.kunitconfig:``` CONFIG_KUNIT=y CONFIG_PRANDOM_KUNIT_TEST=y ```Signed-off-by Kir Chou <[email protected]>--- 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 14 lines
lib/tests/random32_kunit.c new file +8
-0@@ -0,0 +1,174 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Test cases for random32 functions. +*/ + +#include <kunit/test.h> + +static struct prandom_test1 {
lib/tests/random32_kunit.c line 18
Quoted 10 lines
lib/tests/random32_kunit.c new file +10
-0+u32 seed; +u32 result; +} test1[] = { + { 1U, 3484351685U }, + { 2U, 2623130059U }, + { 3U, 3125133893U }, + { 4U, 984847254U }, +}; + +static struct prandom_test2 {
These arrays can be 'const'.
Quoted 4 lines
lib/tests/random32_kunit.c new file +4
-0+u32 seed; +u32 iteration; +u32 result; +} test2[] = {
(...)