The patch titled Subject: lib/test_crc: add test cases for crc calculation has been removed from the -mm tree. Its filename was lib-test_crc-add-test-cases-for-crc-calculation.patch This patch was dropped because an updated version will be merged ------------------------------------------------------ From: Coly Li <colyli@xxxxxxx> Subject: lib/test_crc: add test cases for crc calculation Add a kernel module to test the consistency of multiple crc calculation in Linux kernel. It is enabled with CONFIG_TEST_CRC enabled. The test results are printed into kernel message, which look like, test_crc: crc64_be: FAILED (0x03d4d0d85685d9a1, expected 0x3d4d0d85685d9a1f) kernel 0day system has framework to check kernel message, then the above result can be handled by 0day system. If crc calculation inconsistency happens, it can be detected quite soon. lib/test_crc.c is a testing frame work for many crc consistency testings. For now, there is only one test caes for crc64_be(). [akpm@xxxxxxxxxxxxxxxxxxxx: make two globals static, regularize code layout, remove unneeded initialization] Link: http://lkml.kernel.org/r/20180718165545.1622-4-colyli@xxxxxxx Signed-off-by: Coly Li <colyli@xxxxxxx> Reviewed-by: Hannes Reinecke <hare@xxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx> Cc: Kate Stewart <kstewart@xxxxxxxxxxxxxxxxxxx> Cc: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> Cc: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx> Cc: Noah Massey <noah.massey@xxxxxxxxx> Cc: Eric Biggers <ebiggers3@xxxxxxxxx> Cc: Kent Overstreet <kent.overstreet@xxxxxxxxx> Cc: Michael Lyle <mlyle@xxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/Kconfig.debug | 10 ++++ lib/Makefile | 1 lib/test_crc.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) diff -puN lib/Kconfig.debug~lib-test_crc-add-test-cases-for-crc-calculation lib/Kconfig.debug --- a/lib/Kconfig.debug~lib-test_crc-add-test-cases-for-crc-calculation +++ a/lib/Kconfig.debug @@ -1911,6 +1911,16 @@ config TEST_SYSCTL If unsure, say N. +config TEST_CRC + tristate "CRC calculation test driver" + depends on CRC64 + help + This builds the "test_crc" module. This driver enables to test the + CRC calculation consistency to make sure new modification does not + break existing checksum calculation. + + if unsure, say N. + config TEST_UDELAY tristate "udelay test driver" default n diff -puN lib/Makefile~lib-test_crc-add-test-cases-for-crc-calculation lib/Makefile --- a/lib/Makefile~lib-test_crc-add-test-cases-for-crc-calculation +++ a/lib/Makefile @@ -49,6 +49,7 @@ obj-$(CONFIG_FIND_BIT_BENCHMARK) += find obj-$(CONFIG_TEST_BPF) += test_bpf.o obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o +obj-$(CONFIG_TEST_CRC) += test_crc.o obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o obj-$(CONFIG_TEST_KASAN) += test_kasan.o CFLAGS_test_kasan.o += -fno-builtin diff -puN /dev/null lib/test_crc.c --- /dev/null +++ a/lib/test_crc.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * CRC test driver + * + * Copyright (C) 2018 Coly Li <colyli@xxxxxxx> + * + * This module provides an simple framework to check the consistency of + * Linux kernel CRC calculation routines in lib/crc*.c. This driver + * requires CONFIG_CRC* items to be enabled if the associated routines are + * tested here. The test results will be printed to kernel message + * when this test driver is loaded. + * + * Current test routines are, + * - crc64_be() + */ + +#include <linux/module.h> +#include <linux/crc64.h> + +struct crc_test_record { + char *name; + u64 data[4]; + u64 initval; + u64 expval; + void (*handler)(struct crc_test_record *rec); +}; + +static int failed_tests; +static int total_tests; + +static void chk_and_msg(const char *name, u64 crc, u64 expval) +{ + total_tests++; + if (crc == expval) + return; + + pr_err("test_crc: %s: FAILED:(0x%016llx, expected 0x%016llx)\n", + name, crc, expval); + failed_tests++; +} + +/* Add your crc test cases here */ +static void test_crc64_be(struct crc_test_record *rec) +{ + u64 crc; + + crc = crc64_be(rec->initval, rec->data, sizeof(rec->data)); + chk_and_msg(rec->name, crc, rec->expval); +} + +/* + * Set up your crc test initial data here. + * Do not change the existing items, they are hard coded with + * pre-calculated values. + */ +static struct crc_test_record test_data[] = { + { .name = "crc64_be", + .data = { 0x42F0E1EBA9EA3693, 0x85E1C3D753D46D26, + 0xC711223CFA3E5BB5, 0x493366450E42ECDF }, + .initval = 0x61C8864680B583EB, + .expval = 0xb2c863673f4292bf, + .handler = test_crc64_be, + }, + {} +}; + +static int __init test_crc_init(void) +{ + int i; + + pr_info("Kernel CRC consistency testing:\n"); + for (i = 0; test_data[i].name; i++) + test_data[i].handler(&test_data[i]); + + if (failed_tests == 0) + pr_info("test_crc: all %d tests passed\n", i); + else + pr_err("test_crc: %d cases tested, %d passed, %d failed\n", + total_tests, total_tests - failed_tests, failed_tests); + + return (failed_tests == 0) ? 0 : -EINVAL; +} +late_initcall(test_crc_init); + +static void __exit test_crc_exit(void) +{ +} +module_exit(test_crc_exit); + +MODULE_DESCRIPTION("CRC consistency testing driver"); +MODULE_AUTHOR("Coly Li <colyli@xxxxxxx>"); +MODULE_LICENSE("GPL v2"); _ Patches currently in -mm which might be from colyli@xxxxxxx are lib-add-crc64-calculation-routines.patch lib-add-crc64-calculation-routines-v5.patch bcache-use-routines-from-lib-crc64c-for-crc64-calculation.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html