* Test if all CRC32 implementations yield the same hash value */
| 163 | * Test if all CRC32 implementations yield the same hash value |
| 164 | */ |
| 165 | static int |
| 166 | test_crc32_hash_alg_equiv(void) |
| 167 | { |
| 168 | uint32_t hash_val; |
| 169 | uint32_t init_val; |
| 170 | uint64_t data64[CRC32_DWORDS]; |
| 171 | unsigned i, j; |
| 172 | size_t data_len; |
| 173 | |
| 174 | printf("\n# CRC32 implementations equivalence test\n"); |
| 175 | for (i = 0; i < CRC32_ITERATIONS; i++) { |
| 176 | /* Randomizing data_len of data set */ |
| 177 | data_len = (size_t) ((rte_rand() % sizeof(data64)) + 1); |
| 178 | init_val = (uint32_t) rte_rand(); |
| 179 | |
| 180 | /* Fill the data set */ |
| 181 | for (j = 0; j < CRC32_DWORDS; j++) |
| 182 | data64[j] = rte_rand(); |
| 183 | |
| 184 | /* Calculate software CRC32 */ |
| 185 | rte_hash_crc_set_alg(CRC32_SW); |
| 186 | hash_val = rte_hash_crc(data64, data_len, init_val); |
| 187 | |
| 188 | /* Check against 4-byte-operand sse4.2 CRC32 if available */ |
| 189 | rte_hash_crc_set_alg(CRC32_SSE42); |
| 190 | if (hash_val != rte_hash_crc(data64, data_len, init_val)) { |
| 191 | printf("Failed checking CRC32_SW against CRC32_SSE42\n"); |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | /* Check against 8-byte-operand sse4.2 CRC32 if available */ |
| 196 | rte_hash_crc_set_alg(CRC32_SSE42_x64); |
| 197 | if (hash_val != rte_hash_crc(data64, data_len, init_val)) { |
| 198 | printf("Failed checking CRC32_SW against CRC32_SSE42_x64\n"); |
| 199 | break; |
| 200 | } |
| 201 | |
| 202 | /* Check against 8-byte-operand ARM64 CRC32 if available */ |
| 203 | rte_hash_crc_set_alg(CRC32_ARM64); |
| 204 | if (hash_val != rte_hash_crc(data64, data_len, init_val)) { |
| 205 | printf("Failed checking CRC32_SW against CRC32_ARM64\n"); |
| 206 | break; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | /* Resetting to best available algorithm */ |
| 211 | rte_hash_crc_set_alg(CRC32_SSE42_x64); |
| 212 | |
| 213 | if (i == CRC32_ITERATIONS) |
| 214 | return 0; |
| 215 | |
| 216 | printf("Failed test data (hex, %zu bytes total):\n", data_len); |
| 217 | for (j = 0; j < data_len; j++) |
| 218 | printf("%02X%c", ((uint8_t *)data64)[j], |
| 219 | ((j+1) % 16 == 0 || j == data_len - 1) ? '\n' : ' '); |
| 220 | |
| 221 | return -1; |
| 222 | } |
no test coverage detected