* [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig
@ 2026-03-06 3:35 Eric Biggers
2026-03-06 3:35 ` [PATCH 1/3] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Eric Biggers @ 2026-03-06 3:35 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-crypto, Ard Biesheuvel, kunit-dev, Eric Biggers
This series fixes crc_kunit to follow the standard KUnit convention of
depending on the code it tests rather than selecting it, adds a kconfig
option that enables all the CRC variants for KUnit testing, and adds a
kunitconfig file for lib/crc/.
This follows similar changes to lib/crypto/ (except lib/crypto/ doesn't
have an equivalent to CRC_ENABLE_ALL_FOR_KUNIT yet, but we could
consider adding one).
This series applies to v7.0-rc2 and is targeting crc-next.
Eric Biggers (3):
lib/crc: tests: Make crc_kunit test only the enabled CRC variants
lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT
lib/crc: tests: Add a .kunitconfig file
lib/crc/.kunitconfig | 3 +++
lib/crc/Kconfig | 17 +++++++++++++----
lib/crc/tests/crc_kunit.c | 28 ++++++++++++++++++++++------
3 files changed, 38 insertions(+), 10 deletions(-)
create mode 100644 lib/crc/.kunitconfig
base-commit: 11439c4635edd669ae435eec308f4ab8a0804808
--
2.53.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] lib/crc: tests: Make crc_kunit test only the enabled CRC variants
2026-03-06 3:35 [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
@ 2026-03-06 3:35 ` Eric Biggers
2026-03-06 3:35 ` [PATCH 2/3] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT Eric Biggers
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-03-06 3:35 UTC (permalink / raw)
To: linux-kernel
Cc: linux-crypto, Ard Biesheuvel, kunit-dev, Eric Biggers, stable
Like commit 4478e8eeb871 ("lib/crypto: tests: Depend on library options
rather than selecting them") did with the crypto library tests, make
crc_kunit depend on the code it tests rather than selecting it. This
follows the standard convention for KUnit and fixes an issue where
enabling KUNIT_ALL_TESTS enabled non-test code.
crc_kunit does differ from the crypto library tests in that it
consolidates the tests for multiple CRC variants, with 5 kconfig
options, into one KUnit suite. Since depending on *all* of these
kconfig options would greatly restrict the ability to enable crc_kunit,
instead just depend on *any* of these options. Update crc_kunit
accordingly to test only the reachable code.
Alternatively we could split crc_kunit into 5 test suites. But keeping
it as one is simpler for now.
Fixes: e47d9b1a76ed ("lib/crc_kunit.c: add KUnit test suite for CRC library functions")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
lib/crc/Kconfig | 7 +------
lib/crc/tests/crc_kunit.c | 28 ++++++++++++++++++++++------
2 files changed, 23 insertions(+), 12 deletions(-)
diff --git a/lib/crc/Kconfig b/lib/crc/Kconfig
index 70e7a6016de3..9ddfd1a29757 100644
--- a/lib/crc/Kconfig
+++ b/lib/crc/Kconfig
@@ -97,17 +97,12 @@ config CRC_OPTIMIZATIONS
Keep this enabled unless you're really trying to minimize the size of
the kernel.
config CRC_KUNIT_TEST
tristate "KUnit tests for CRC functions" if !KUNIT_ALL_TESTS
- depends on KUNIT
+ depends on KUNIT && (CRC7 || CRC16 || CRC_T10DIF || CRC32 || CRC64)
default KUNIT_ALL_TESTS
- select CRC7
- select CRC16
- select CRC_T10DIF
- select CRC32
- select CRC64
help
Unit tests for the CRC library functions.
This is intended to help people writing architecture-specific
optimized versions. If unsure, say N.
diff --git a/lib/crc/tests/crc_kunit.c b/lib/crc/tests/crc_kunit.c
index 9a450e25ac81..9428cd913625 100644
--- a/lib/crc/tests/crc_kunit.c
+++ b/lib/crc/tests/crc_kunit.c
@@ -266,12 +266,11 @@ crc_benchmark(struct kunit *test,
kunit_info(test, "len=%zu: %llu MB/s\n",
len, div64_u64((u64)len * num_iters * 1000, t));
}
}
-/* crc7_be */
-
+#if IS_REACHABLE(CONFIG_CRC7)
static u64 crc7_be_wrapper(u64 crc, const u8 *p, size_t len)
{
/*
* crc7_be() left-aligns the 7-bit CRC in a u8, whereas the test wants a
* right-aligned CRC (in a u64). Convert between the conventions.
@@ -292,13 +291,13 @@ static void crc7_be_test(struct kunit *test)
static void crc7_be_benchmark(struct kunit *test)
{
crc_benchmark(test, crc7_be_wrapper);
}
+#endif /* CONFIG_CRC7 */
-/* crc16 */
-
+#if IS_REACHABLE(CONFIG_CRC16)
static u64 crc16_wrapper(u64 crc, const u8 *p, size_t len)
{
return crc16(crc, p, len);
}
@@ -316,13 +315,13 @@ static void crc16_test(struct kunit *test)
static void crc16_benchmark(struct kunit *test)
{
crc_benchmark(test, crc16_wrapper);
}
+#endif /* CONFIG_CRC16 */
-/* crc_t10dif */
-
+#if IS_REACHABLE(CONFIG_CRC_T10DIF)
static u64 crc_t10dif_wrapper(u64 crc, const u8 *p, size_t len)
{
return crc_t10dif_update(crc, p, len);
}
@@ -340,10 +339,13 @@ static void crc_t10dif_test(struct kunit *test)
static void crc_t10dif_benchmark(struct kunit *test)
{
crc_benchmark(test, crc_t10dif_wrapper);
}
+#endif /* CONFIG_CRC_T10DIF */
+
+#if IS_REACHABLE(CONFIG_CRC32)
/* crc32_le */
static u64 crc32_le_wrapper(u64 crc, const u8 *p, size_t len)
{
@@ -412,10 +414,13 @@ static void crc32c_test(struct kunit *test)
static void crc32c_benchmark(struct kunit *test)
{
crc_benchmark(test, crc32c_wrapper);
}
+#endif /* CONFIG_CRC32 */
+
+#if IS_REACHABLE(CONFIG_CRC64)
/* crc64_be */
static u64 crc64_be_wrapper(u64 crc, const u8 *p, size_t len)
{
@@ -461,28 +466,39 @@ static void crc64_nvme_test(struct kunit *test)
static void crc64_nvme_benchmark(struct kunit *test)
{
crc_benchmark(test, crc64_nvme_wrapper);
}
+#endif /* CONFIG_CRC64 */
static struct kunit_case crc_test_cases[] = {
+#if IS_REACHABLE(CONFIG_CRC7)
KUNIT_CASE(crc7_be_test),
KUNIT_CASE(crc7_be_benchmark),
+#endif
+#if IS_REACHABLE(CONFIG_CRC16)
KUNIT_CASE(crc16_test),
KUNIT_CASE(crc16_benchmark),
+#endif
+#if IS_REACHABLE(CONFIG_CRC_T10DIF)
KUNIT_CASE(crc_t10dif_test),
KUNIT_CASE(crc_t10dif_benchmark),
+#endif
+#if IS_REACHABLE(CONFIG_CRC32)
KUNIT_CASE(crc32_le_test),
KUNIT_CASE(crc32_le_benchmark),
KUNIT_CASE(crc32_be_test),
KUNIT_CASE(crc32_be_benchmark),
KUNIT_CASE(crc32c_test),
KUNIT_CASE(crc32c_benchmark),
+#endif
+#if IS_REACHABLE(CONFIG_CRC64)
KUNIT_CASE(crc64_be_test),
KUNIT_CASE(crc64_be_benchmark),
KUNIT_CASE(crc64_nvme_test),
KUNIT_CASE(crc64_nvme_benchmark),
+#endif
{},
};
static struct kunit_suite crc_test_suite = {
.name = "crc",
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT
2026-03-06 3:35 [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
2026-03-06 3:35 ` [PATCH 1/3] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
@ 2026-03-06 3:35 ` Eric Biggers
2026-03-06 3:35 ` [PATCH 3/3] lib/crc: tests: Add a .kunitconfig file Eric Biggers
2026-03-14 0:03 ` [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-03-06 3:35 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-crypto, Ard Biesheuvel, kunit-dev, Eric Biggers
Now that crc_kunit uses the standard "depends on" pattern, enabling the
full set of CRC tests is a bit difficult, mainly due to CRC7 being
rarely used. Add a kconfig option to make it easier. It is visible
only when KUNIT, so hopefully the extra prompt won't be too annoying.
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
lib/crc/Kconfig | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/lib/crc/Kconfig b/lib/crc/Kconfig
index 9ddfd1a29757..cca228879bb5 100644
--- a/lib/crc/Kconfig
+++ b/lib/crc/Kconfig
@@ -105,10 +105,24 @@ config CRC_KUNIT_TEST
Unit tests for the CRC library functions.
This is intended to help people writing architecture-specific
optimized versions. If unsure, say N.
+config CRC_ENABLE_ALL_FOR_KUNIT
+ tristate "Enable all CRC functions for KUnit test"
+ depends on KUNIT
+ select CRC7
+ select CRC16
+ select CRC_T10DIF
+ select CRC32
+ select CRC64
+ help
+ Enable all CRC functions that have test code in CRC_KUNIT_TEST.
+
+ Enable this only if you'd like the CRC KUnit test suite to test all
+ the CRC variants, even ones that wouldn't otherwise need to be built.
+
config CRC_BENCHMARK
bool "Benchmark for the CRC functions"
depends on CRC_KUNIT_TEST
help
Include benchmarks in the KUnit test suite for the CRC functions.
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] lib/crc: tests: Add a .kunitconfig file
2026-03-06 3:35 [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
2026-03-06 3:35 ` [PATCH 1/3] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
2026-03-06 3:35 ` [PATCH 2/3] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT Eric Biggers
@ 2026-03-06 3:35 ` Eric Biggers
2026-03-14 0:03 ` [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-03-06 3:35 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-crypto, Ard Biesheuvel, kunit-dev, Eric Biggers
Add a .kunitconfig file to the lib/crc/ directory so that the CRC
library tests can be run more easily using kunit.py. Example with UML:
tools/testing/kunit/kunit.py run --kunitconfig=lib/crc
Example with QEMU:
tools/testing/kunit/kunit.py run --kunitconfig=lib/crc --arch=arm64 --make_options LLVM=1
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
lib/crc/.kunitconfig | 3 +++
1 file changed, 3 insertions(+)
create mode 100644 lib/crc/.kunitconfig
diff --git a/lib/crc/.kunitconfig b/lib/crc/.kunitconfig
new file mode 100644
index 000000000000..0a3671ba573f
--- /dev/null
+++ b/lib/crc/.kunitconfig
@@ -0,0 +1,3 @@
+CONFIG_KUNIT=y
+CONFIG_CRC_ENABLE_ALL_FOR_KUNIT=y
+CONFIG_CRC_KUNIT_TEST=y
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig
2026-03-06 3:35 [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
` (2 preceding siblings ...)
2026-03-06 3:35 ` [PATCH 3/3] lib/crc: tests: Add a .kunitconfig file Eric Biggers
@ 2026-03-14 0:03 ` Eric Biggers
3 siblings, 0 replies; 5+ messages in thread
From: Eric Biggers @ 2026-03-14 0:03 UTC (permalink / raw)
To: linux-kernel; +Cc: linux-crypto, Ard Biesheuvel, kunit-dev
On Thu, Mar 05, 2026 at 07:35:54PM -0800, Eric Biggers wrote:
> This series fixes crc_kunit to follow the standard KUnit convention of
> depending on the code it tests rather than selecting it, adds a kconfig
> option that enables all the CRC variants for KUnit testing, and adds a
> kunitconfig file for lib/crc/.
>
> This follows similar changes to lib/crypto/ (except lib/crypto/ doesn't
> have an equivalent to CRC_ENABLE_ALL_FOR_KUNIT yet, but we could
> consider adding one).
>
> This series applies to v7.0-rc2 and is targeting crc-next.
>
> Eric Biggers (3):
> lib/crc: tests: Make crc_kunit test only the enabled CRC variants
> lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT
> lib/crc: tests: Add a .kunitconfig file
>
> lib/crc/.kunitconfig | 3 +++
> lib/crc/Kconfig | 17 +++++++++++++----
> lib/crc/tests/crc_kunit.c | 28 ++++++++++++++++++++++------
> 3 files changed, 38 insertions(+), 10 deletions(-)
> create mode 100644 lib/crc/.kunitconfig
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=crc-next
- Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-14 0:03 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 3:35 [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
2026-03-06 3:35 ` [PATCH 1/3] lib/crc: tests: Make crc_kunit test only the enabled CRC variants Eric Biggers
2026-03-06 3:35 ` [PATCH 2/3] lib/crc: tests: Add CRC_ENABLE_ALL_FOR_KUNIT Eric Biggers
2026-03-06 3:35 ` [PATCH 3/3] lib/crc: tests: Add a .kunitconfig file Eric Biggers
2026-03-14 0:03 ` [PATCH 0/3] lib/crc: Fix crc_kunit dependency and add kunitconfig Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox