Skip to content

Commit 85c9f3a

Browse files
author
Eric Biggers
committed
lib/crc: tests: Make crc_kunit test only the enabled CRC variants
Like commit 4478e8e ("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: e47d9b1 ("lib/crc_kunit.c: add KUnit test suite for CRC library functions") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20260306033557.250499-2-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 1f318b9 commit 85c9f3a

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

lib/crc/Kconfig

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,8 @@ config CRC_OPTIMIZATIONS
9999

100100
config CRC_KUNIT_TEST
101101
tristate "KUnit tests for CRC functions" if !KUNIT_ALL_TESTS
102-
depends on KUNIT
102+
depends on KUNIT && (CRC7 || CRC16 || CRC_T10DIF || CRC32 || CRC64)
103103
default KUNIT_ALL_TESTS
104-
select CRC7
105-
select CRC16
106-
select CRC_T10DIF
107-
select CRC32
108-
select CRC64
109104
help
110105
Unit tests for the CRC library functions.
111106

lib/crc/tests/crc_kunit.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,7 @@ crc_benchmark(struct kunit *test,
268268
}
269269
}
270270

271-
/* crc7_be */
272-
271+
#if IS_REACHABLE(CONFIG_CRC7)
273272
static u64 crc7_be_wrapper(u64 crc, const u8 *p, size_t len)
274273
{
275274
/*
@@ -294,9 +293,9 @@ static void crc7_be_benchmark(struct kunit *test)
294293
{
295294
crc_benchmark(test, crc7_be_wrapper);
296295
}
296+
#endif /* CONFIG_CRC7 */
297297

298-
/* crc16 */
299-
298+
#if IS_REACHABLE(CONFIG_CRC16)
300299
static u64 crc16_wrapper(u64 crc, const u8 *p, size_t len)
301300
{
302301
return crc16(crc, p, len);
@@ -318,9 +317,9 @@ static void crc16_benchmark(struct kunit *test)
318317
{
319318
crc_benchmark(test, crc16_wrapper);
320319
}
320+
#endif /* CONFIG_CRC16 */
321321

322-
/* crc_t10dif */
323-
322+
#if IS_REACHABLE(CONFIG_CRC_T10DIF)
324323
static u64 crc_t10dif_wrapper(u64 crc, const u8 *p, size_t len)
325324
{
326325
return crc_t10dif_update(crc, p, len);
@@ -342,6 +341,9 @@ static void crc_t10dif_benchmark(struct kunit *test)
342341
{
343342
crc_benchmark(test, crc_t10dif_wrapper);
344343
}
344+
#endif /* CONFIG_CRC_T10DIF */
345+
346+
#if IS_REACHABLE(CONFIG_CRC32)
345347

346348
/* crc32_le */
347349

@@ -414,6 +416,9 @@ static void crc32c_benchmark(struct kunit *test)
414416
{
415417
crc_benchmark(test, crc32c_wrapper);
416418
}
419+
#endif /* CONFIG_CRC32 */
420+
421+
#if IS_REACHABLE(CONFIG_CRC64)
417422

418423
/* crc64_be */
419424

@@ -463,24 +468,35 @@ static void crc64_nvme_benchmark(struct kunit *test)
463468
{
464469
crc_benchmark(test, crc64_nvme_wrapper);
465470
}
471+
#endif /* CONFIG_CRC64 */
466472

467473
static struct kunit_case crc_test_cases[] = {
474+
#if IS_REACHABLE(CONFIG_CRC7)
468475
KUNIT_CASE(crc7_be_test),
469476
KUNIT_CASE(crc7_be_benchmark),
477+
#endif
478+
#if IS_REACHABLE(CONFIG_CRC16)
470479
KUNIT_CASE(crc16_test),
471480
KUNIT_CASE(crc16_benchmark),
481+
#endif
482+
#if IS_REACHABLE(CONFIG_CRC_T10DIF)
472483
KUNIT_CASE(crc_t10dif_test),
473484
KUNIT_CASE(crc_t10dif_benchmark),
485+
#endif
486+
#if IS_REACHABLE(CONFIG_CRC32)
474487
KUNIT_CASE(crc32_le_test),
475488
KUNIT_CASE(crc32_le_benchmark),
476489
KUNIT_CASE(crc32_be_test),
477490
KUNIT_CASE(crc32_be_benchmark),
478491
KUNIT_CASE(crc32c_test),
479492
KUNIT_CASE(crc32c_benchmark),
493+
#endif
494+
#if IS_REACHABLE(CONFIG_CRC64)
480495
KUNIT_CASE(crc64_be_test),
481496
KUNIT_CASE(crc64_be_benchmark),
482497
KUNIT_CASE(crc64_nvme_test),
483498
KUNIT_CASE(crc64_nvme_benchmark),
499+
#endif
484500
{},
485501
};
486502

0 commit comments

Comments
 (0)