Skip to content

Commit e47d9b1

Browse files
committed
lib/crc_kunit.c: add KUnit test suite for CRC library functions
Add a KUnit test suite for the crc16, crc_t10dif, crc32_le, crc32_be, crc32c, and crc64_be library functions. It avoids code duplication by sharing most logic among all CRC variants. The test suite includes: - Differential fuzz test of each CRC function against a simple bit-at-a-time reference implementation. - Test for CRC combination, when implemented by a CRC variant. - Optional benchmark of each CRC function with various data lengths. This is intended as a replacement for crc32test and crc16_kunit, as well as a new test for CRC variants which didn't previously have a test. Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Cc: Vinicius Peixoto <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent 7439cfe commit e47d9b1

File tree

3 files changed

+456
-0
lines changed

3 files changed

+456
-0
lines changed

lib/Kconfig.debug

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,6 +2838,26 @@ config HW_BREAKPOINT_KUNIT_TEST
28382838

28392839
If unsure, say N.
28402840

2841+
config CRC_KUNIT_TEST
2842+
tristate "KUnit tests for CRC functions" if !KUNIT_ALL_TESTS
2843+
depends on KUNIT
2844+
default KUNIT_ALL_TESTS
2845+
select CRC16
2846+
select CRC_T10DIF
2847+
select CRC32
2848+
select CRC64
2849+
help
2850+
Unit tests for the CRC library functions.
2851+
2852+
This is intended to help people writing architecture-specific
2853+
optimized versions. If unsure, say N.
2854+
2855+
config CRC_BENCHMARK
2856+
bool "Benchmark for the CRC functions"
2857+
depends on CRC_KUNIT_TEST
2858+
help
2859+
Include benchmarks in the KUnit test suite for the CRC functions.
2860+
28412861
config SIPHASH_KUNIT_TEST
28422862
tristate "Perform selftest on siphash functions" if !KUNIT_ALL_TESTS
28432863
depends on KUNIT

lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-overread)
391391
CFLAGS_fortify_kunit.o += $(call cc-disable-warning, stringop-truncation)
392392
CFLAGS_fortify_kunit.o += $(DISABLE_STRUCTLEAK_PLUGIN)
393393
obj-$(CONFIG_FORTIFY_KUNIT_TEST) += fortify_kunit.o
394+
obj-$(CONFIG_CRC_KUNIT_TEST) += crc_kunit.o
394395
obj-$(CONFIG_SIPHASH_KUNIT_TEST) += siphash_kunit.o
395396
obj-$(CONFIG_USERCOPY_KUNIT_TEST) += usercopy_kunit.o
396397
obj-$(CONFIG_CRC16_KUNIT_TEST) += crc16_kunit.o

0 commit comments

Comments
 (0)