lib/random32: convert selftest to KUnit
Subsystems (4)
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.
The new test:
- Removes the legacy CONFIG_RANDOM32_SELFTEST from lib/random32.c.
- Adds CONFIG_PRANDOM_KUNIT_TEST (defaulting to KUNIT_ALL_TESTS).
- Moves the test logic to lib/tests/random32_kunit.c.
v2:
- Removes the legacy CONFIG_RANDOM32_SELFTEST from lib/Kconfig.
- Add const to arrays in lib/tests/random32_kunit.c.
v3:
- Changes from tristate to bool in lib/Kconfig.debug.
v4:
- Changes from bool to tristate in lib/Kconfig.debug.
- Spins off the test into its own module under lib/tests/.
- Adds a prototype for prandom_warmup() to avoid a warning.
- Makes prandom_warmup() visible to the test in lib/random32.c.
- Adds the build rule for random32_kunit.o to lib/tests/Makefile.
This commit is verified by ./tools/testing/kunit/kunit.py run with the .kunit/.kunitconfig:
``` CONFIG_KUNIT=y CONFIG_PRANDOM_KUNIT_TEST=y ```
--- lib/Kconfig | 6 -- lib/Kconfig.debug | 9 ++ lib/random32.c | 184 ++----------------------------------- lib/tests/Makefile | 1 + lib/tests/random32_kunit.c | 181 ++++++++++++++++++++++++++++++++++++ 5 files changed, 201 insertions(+), 180 deletions(-) create mode 100644 lib/tests/random32_kunit.c
lib/Kconfig +0 -6
@@ -156,12 +156,6 @@ config AUDIT_COMPAT_GENERIC depends on AUDIT_GENERIC && AUDIT_ARCH_COMPAT_GENERIC && COMPAT default y -config RANDOM32_SELFTEST - bool "PRNG perform self test on init" - help - This option enables the 32 bit PRNG library functions to perform a - self test on initialization. - # # compression support is select'ed if needed #
lib/Kconfig.debug +9 -0
@@ -3354,6 +3354,15 @@ 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. + + If unsure, say N + endif # RUNTIME_TESTING_MENU config ARCH_USE_MEMTEST
lib/random32.c +10 -174
205 lines not on this page · raw message
lib/tests/Makefile +1 -0
@@ -49,5 +49,6 @@ obj-$(CONFIG_STRING_HELPERS_KUNIT_TEST) += string_helpers_kunit.o obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o obj-$(CONFIG_UTIL_MACROS_KUNIT) += util_macros_kunit.o obj-$(CONFIG_RATELIMIT_KUNIT_TEST) += test_ratelimit.o +obj-$(CONFIG_PRANDOM_KUNIT_TEST) += random32_kunit.o obj-$(CONFIG_TEST_RUNTIME_MODULE) += module/
lib/tests/random32_kunit.c new file +181 -0
181 lines not on this page · raw message
Signature · 1 line
2.52.0