Skip to content

Commit efba721

Browse files
Daniel Borkmanndavem330
authored andcommitted
lib: crc32: add test cases for crc32{, c}_combine routines
We already have 100 test cases for crcs itself, so split the test buffer with a-prio known checksums, and test crc of two blocks against crc of the whole block for the same results. Output/result with CONFIG_CRC32_SELFTEST=y: [ 2.687095] crc32: CRC_LE_BITS = 64, CRC_BE BITS = 64 [ 2.687097] crc32: self tests passed, processed 225944 bytes in 278177 nsec [ 2.687383] crc32c: CRC_LE_BITS = 64 [ 2.687385] crc32c: self tests passed, processed 225944 bytes in 141708 nsec [ 7.336771] crc32_combine: 113072 self tests passed [ 12.050479] crc32c_combine: 113072 self tests passed [ 17.633089] alg: No test for crc32 (crc32-pclmul) Signed-off-by: Daniel Borkmann <dborkman@redhat.com> Cc: linux-kernel@vger.kernel.org Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6e95fca commit efba721

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

lib/crc32.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,40 @@ static int __init crc32c_test(void)
10311031
return 0;
10321032
}
10331033

1034+
static int __init crc32c_combine_test(void)
1035+
{
1036+
int i, j;
1037+
int errors = 0, runs = 0;
1038+
1039+
for (i = 0; i < 100; i++) {
1040+
u32 crc_full;
1041+
1042+
crc_full = __crc32c_le(test[i].crc, test_buf + test[i].start,
1043+
test[i].length);
1044+
for (j = 0; j <= test[i].length; ++j) {
1045+
u32 crc1, crc2;
1046+
u32 len1 = j, len2 = test[i].length - j;
1047+
1048+
crc1 = __crc32c_le(test[i].crc, test_buf +
1049+
test[i].start, len1);
1050+
crc2 = __crc32c_le(0, test_buf + test[i].start +
1051+
len1, len2);
1052+
1053+
if (!(crc_full == __crc32c_le_combine(crc1, crc2, len2) &&
1054+
crc_full == test[i].crc32c_le))
1055+
errors++;
1056+
runs++;
1057+
}
1058+
}
1059+
1060+
if (errors)
1061+
pr_warn("crc32c_combine: %d/%d self tests failed\n", errors, runs);
1062+
else
1063+
pr_info("crc32c_combine: %d self tests passed\n", runs);
1064+
1065+
return 0;
1066+
}
1067+
10341068
static int __init crc32_test(void)
10351069
{
10361070
int i;
@@ -1090,10 +1124,48 @@ static int __init crc32_test(void)
10901124
return 0;
10911125
}
10921126

1127+
static int __init crc32_combine_test(void)
1128+
{
1129+
int i, j;
1130+
int errors = 0, runs = 0;
1131+
1132+
for (i = 0; i < 100; i++) {
1133+
u32 crc_full;
1134+
1135+
crc_full = crc32_le(test[i].crc, test_buf + test[i].start,
1136+
test[i].length);
1137+
for (j = 0; j <= test[i].length; ++j) {
1138+
u32 crc1, crc2;
1139+
u32 len1 = j, len2 = test[i].length - j;
1140+
1141+
crc1 = crc32_le(test[i].crc, test_buf +
1142+
test[i].start, len1);
1143+
crc2 = crc32_le(0, test_buf + test[i].start +
1144+
len1, len2);
1145+
1146+
if (!(crc_full == crc32_le_combine(crc1, crc2, len2) &&
1147+
crc_full == test[i].crc_le))
1148+
errors++;
1149+
runs++;
1150+
}
1151+
}
1152+
1153+
if (errors)
1154+
pr_warn("crc32_combine: %d/%d self tests failed\n", errors, runs);
1155+
else
1156+
pr_info("crc32_combine: %d self tests passed\n", runs);
1157+
1158+
return 0;
1159+
}
1160+
10931161
static int __init crc32test_init(void)
10941162
{
10951163
crc32_test();
10961164
crc32c_test();
1165+
1166+
crc32_combine_test();
1167+
crc32c_combine_test();
1168+
10971169
return 0;
10981170
}
10991171

0 commit comments

Comments
 (0)