aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/crc32.c72
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
1034static 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
1034static int __init crc32_test(void) 1068static 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
1127static 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
1093static int __init crc32test_init(void) 1161static 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