lib/prime_numbers: convert self-test to KUnit

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@gmail.com>
Link: https://lore.kernel.org/r/20250208-prime_numbers-kunit-convert-v5-2-b0cb82ae7c7d@gmail.com
Signed-off-by: Kees Cook <kees@kernel.org>
This commit is contained in:
Tamir Duberstein
2025-02-08 21:44:39 -05:00
committed by Kees Cook
parent 9ab61886ac
commit 313b38a6ec
7 changed files with 109 additions and 77 deletions

View File

@@ -3235,6 +3235,20 @@ config GCD_KUNIT_TEST
If unsure, say N
config PRIME_NUMBERS_KUNIT_TEST
tristate "Prime number generator test" if !KUNIT_ALL_TESTS
depends on KUNIT
select PRIME_NUMBERS
default KUNIT_ALL_TESTS
help
This option enables the KUnit test suite for the {is,next}_prime_number
functions.
Enabling this option will include tests that compare the prime number
generator functions against a brute force implementation.
If unsure, say N
endif # RUNTIME_TESTING_MENU
config ARCH_USE_MEMTEST