77 * Author: Eric Biggers <[email protected] > 88 */
99#include <kunit/test.h>
10+ #include <linux/crc7.h>
1011#include <linux/crc16.h>
1112#include <linux/crc-t10dif.h>
1213#include <linux/crc32.h>
@@ -32,8 +33,9 @@ static size_t test_buflen;
3233 * @poly: The generator polynomial with the highest-order term omitted.
3334 * Bit-reversed if @le is true.
3435 * @func: The function to compute a CRC. The type signature uses u64 so that it
35- * can fit any CRC up to CRC-64. The function is expected to *not*
36- * invert the CRC at the beginning and end.
36+ * can fit any CRC up to CRC-64. The CRC is passed in, and is expected
37+ * to be returned in, the least significant bits of the u64. The
38+ * function is expected to *not* invert the CRC at the beginning and end.
3739 * @combine_func: Optional function to combine two CRCs.
3840 */
3941struct crc_variant {
@@ -252,6 +254,33 @@ crc_benchmark(struct kunit *test,
252254 }
253255}
254256
257+ /* crc7_be */
258+
259+ static u64 crc7_be_wrapper (u64 crc , const u8 * p , size_t len )
260+ {
261+ /*
262+ * crc7_be() left-aligns the 7-bit CRC in a u8, whereas the test wants a
263+ * right-aligned CRC (in a u64). Convert between the conventions.
264+ */
265+ return crc7_be (crc << 1 , p , len ) >> 1 ;
266+ }
267+
268+ static const struct crc_variant crc_variant_crc7_be = {
269+ .bits = 7 ,
270+ .poly = 0x9 ,
271+ .func = crc7_be_wrapper ,
272+ };
273+
274+ static void crc7_be_test (struct kunit * test )
275+ {
276+ crc_test (test , & crc_variant_crc7_be );
277+ }
278+
279+ static void crc7_be_benchmark (struct kunit * test )
280+ {
281+ crc_benchmark (test , crc7_be_wrapper );
282+ }
283+
255284/* crc16 */
256285
257286static u64 crc16_wrapper (u64 crc , const u8 * p , size_t len )
@@ -434,6 +463,8 @@ static void crc64_nvme_benchmark(struct kunit *test)
434463}
435464
436465static struct kunit_case crc_test_cases [] = {
466+ KUNIT_CASE (crc7_be_test ),
467+ KUNIT_CASE (crc7_be_benchmark ),
437468 KUNIT_CASE (crc16_test ),
438469 KUNIT_CASE (crc16_benchmark ),
439470 KUNIT_CASE (crc_t10dif_test ),
0 commit comments