Skip to content

Commit 23709bd

Browse files
committed
lib/crc_kunit.c: add test and benchmark for CRC64-NVME
Wire up crc64_nvme() to the new CRC unit test and benchmark. This replaces and improves on the test coverage that was lost by removing this CRC variant from the crypto API. Reviewed-by: Ard Biesheuvel <[email protected]> Reviewed-by: "Martin K. Petersen" <[email protected]> Acked-by: Keith Busch <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent f6c3f6f commit 23709bd

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

lib/crc_kunit.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ static size_t test_buflen;
3232
* @poly: The generator polynomial with the highest-order term omitted.
3333
* Bit-reversed if @le is true.
3434
* @func: The function to compute a CRC. The type signature uses u64 so that it
35-
* can fit any CRC up to CRC-64.
35+
* can fit any CRC up to CRC-64. The function is expected to *not*
36+
* invert the CRC at the beginning and end.
3637
* @combine_func: Optional function to combine two CRCs.
3738
*/
3839
struct crc_variant {
@@ -407,6 +408,31 @@ static void crc64_be_benchmark(struct kunit *test)
407408
crc_benchmark(test, crc64_be_wrapper);
408409
}
409410

411+
/* crc64_nvme */
412+
413+
static u64 crc64_nvme_wrapper(u64 crc, const u8 *p, size_t len)
414+
{
415+
/* The inversions that crc64_nvme() does have to be undone here. */
416+
return ~crc64_nvme(~crc, p, len);
417+
}
418+
419+
static const struct crc_variant crc_variant_crc64_nvme = {
420+
.bits = 64,
421+
.le = true,
422+
.poly = 0x9a6c9329ac4bc9b5,
423+
.func = crc64_nvme_wrapper,
424+
};
425+
426+
static void crc64_nvme_test(struct kunit *test)
427+
{
428+
crc_test(test, &crc_variant_crc64_nvme);
429+
}
430+
431+
static void crc64_nvme_benchmark(struct kunit *test)
432+
{
433+
crc_benchmark(test, crc64_nvme_wrapper);
434+
}
435+
410436
static struct kunit_case crc_test_cases[] = {
411437
KUNIT_CASE(crc16_test),
412438
KUNIT_CASE(crc16_benchmark),
@@ -420,6 +446,8 @@ static struct kunit_case crc_test_cases[] = {
420446
KUNIT_CASE(crc32c_benchmark),
421447
KUNIT_CASE(crc64_be_test),
422448
KUNIT_CASE(crc64_be_benchmark),
449+
KUNIT_CASE(crc64_nvme_test),
450+
KUNIT_CASE(crc64_nvme_benchmark),
423451
{},
424452
};
425453

0 commit comments

Comments
 (0)