7
7
* Author: Eric Biggers <[email protected] >
8
8
*/
9
9
#include <kunit/test.h>
10
+ #include <linux/crc7.h>
10
11
#include <linux/crc16.h>
11
12
#include <linux/crc-t10dif.h>
12
13
#include <linux/crc32.h>
@@ -32,8 +33,9 @@ static size_t test_buflen;
32
33
* @poly: The generator polynomial with the highest-order term omitted.
33
34
* Bit-reversed if @le is true.
34
35
* @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.
37
39
* @combine_func: Optional function to combine two CRCs.
38
40
*/
39
41
struct crc_variant {
@@ -252,6 +254,33 @@ crc_benchmark(struct kunit *test,
252
254
}
253
255
}
254
256
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
+
255
284
/* crc16 */
256
285
257
286
static u64 crc16_wrapper (u64 crc , const u8 * p , size_t len )
@@ -434,6 +463,8 @@ static void crc64_nvme_benchmark(struct kunit *test)
434
463
}
435
464
436
465
static struct kunit_case crc_test_cases [] = {
466
+ KUNIT_CASE (crc7_be_test ),
467
+ KUNIT_CASE (crc7_be_benchmark ),
437
468
KUNIT_CASE (crc16_test ),
438
469
KUNIT_CASE (crc16_benchmark ),
439
470
KUNIT_CASE (crc_t10dif_test ),
0 commit comments