Tests: Improve the CRC32 test

A similar one was already there for CRC64 but nowadays also CRC32
has a CLMUL implementation, so it's good to test it better too.

(cherry picked from commit 89e9f12e03)
This commit is contained in:
Lasse Collin 2024-06-11 11:15:49 +03:00
parent a44493ec41
commit 1305056a54
No known key found for this signature in database
GPG Key ID: 38EE757D69184620
1 changed files with 13 additions and 4 deletions

View File

@ -49,7 +49,7 @@ static uint8_t *sha256_xz_data;
#endif #endif
#ifdef HAVE_CHECK_CRC64 #if defined(HAVE_CHECK_CRC32) || defined(HAVE_CHECK_CRC64)
static const uint8_t * static const uint8_t *
get_random256(uint32_t *seed) get_random256(uint32_t *seed)
{ {
@ -86,6 +86,16 @@ test_lzma_crc32(void)
for (size_t i = 0; i < sizeof(test_string); ++i) for (size_t i = 0; i < sizeof(test_string); ++i)
crc = lzma_crc32(test_string + i, 1, crc); crc = lzma_crc32(test_string + i, 1, crc);
assert_uint_eq(crc, test_vector); assert_uint_eq(crc, test_vector);
// Test 4: Test combination of different start and end alignments
// and different buffer lengths.
uint32_t seed = 23;
crc = 0x760CD032; // Random initial value
for (size_t start = 0; start < 32; ++start)
for (size_t size = 1; size < 256 - 32; ++size)
crc = lzma_crc32(get_random256(&seed), size, crc);
assert_uint_eq(crc, 0x924E35FD);
} }
@ -115,9 +125,8 @@ test_lzma_crc64(void)
crc = lzma_crc64(test_string + i, 1, crc); crc = lzma_crc64(test_string + i, 1, crc);
assert_uint_eq(crc, test_vector); assert_uint_eq(crc, test_vector);
// Test 4: The CLMUL implementation works on 16-byte chunks. // Test 4: Test combination of different start and end alignments
// Test combination of different start and end alignments // and different buffer lengths.
// and also short buffer lengths where special handling is needed.
uint32_t seed = 29; uint32_t seed = 29;
crc = 0x96E30D5184B7FA2C; // Random initial value crc = 0x96E30D5184B7FA2C; // Random initial value
for (size_t start = 0; start < 32; ++start) for (size_t start = 0; start < 32; ++start)