diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-10-30 06:50:50 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-11-03 23:04:56 -0500 |
commit | efba721f636ee016859d86d15748650119402b10 (patch) | |
tree | 06b207dedd1f0bd77c6dd499e699e0356b8982b4 /lib | |
parent | 6e95fcaa42e5078ac265964deebed597f9eae07a (diff) |
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>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/crc32.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/lib/crc32.c b/lib/crc32.c index 595205cddc30..69dd124f0cfc 100644 --- a/lib/crc32.c +++ b/lib/crc32.c | |||
@@ -1031,6 +1031,40 @@ static int __init crc32c_test(void) | |||
1031 | return 0; | 1031 | return 0; |
1032 | } | 1032 | } |
1033 | 1033 | ||
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 | |||
1034 | static int __init crc32_test(void) | 1068 | static int __init crc32_test(void) |
1035 | { | 1069 | { |
1036 | int i; | 1070 | int i; |
@@ -1090,10 +1124,48 @@ static int __init crc32_test(void) | |||
1090 | return 0; | 1124 | return 0; |
1091 | } | 1125 | } |
1092 | 1126 | ||
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 | |||
1093 | static int __init crc32test_init(void) | 1161 | static int __init crc32test_init(void) |
1094 | { | 1162 | { |
1095 | crc32_test(); | 1163 | crc32_test(); |
1096 | crc32c_test(); | 1164 | crc32c_test(); |
1165 | |||
1166 | crc32_combine_test(); | ||
1167 | crc32c_combine_test(); | ||
1168 | |||
1097 | return 0; | 1169 | return 0; |
1098 | } | 1170 | } |
1099 | 1171 | ||