Mercurial > crc32
annotate crc32-test.c @ 1:90cb48b87dcc
*: don't hardcode the list of impls in multiple places
| author | Paper <paper@tflc.us> |
|---|---|
| date | Mon, 09 Feb 2026 01:18:06 -0500 |
| parents | 422835bc1aca |
| children | ead9f84d11db |
| rev | line source |
|---|---|
| 0 | 1 #include "crc32i.h" |
| 2 #include <stdio.h> | |
| 3 | |
| 4 /* Test implementations and make sure they agree with each other */ | |
| 5 int crc32_test(void) | |
| 6 { | |
| 7 /* Force alignment :) */ | |
| 8 static const __attribute__((__aligned__(CRC32_MAX_ALIGNMENT))) unsigned char testdata[1024] = | |
| 9 #define DOUBLE(x) x x | |
| 10 DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE("\x01\x02\x04\x08\x10\x20\x40\x80"))))))) | |
| 11 #undef DOUBLE | |
| 12 ; | |
| 13 static const crc32_r_spec crc[] = { | |
|
1
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
14 #define CRC32_IMPL(name) crc32##name##_r, |
|
90cb48b87dcc
*: don't hardcode the list of impls in multiple places
Paper <paper@tflc.us>
parents:
0
diff
changeset
|
15 #include "crc32-impls.h" |
| 0 | 16 }; |
| 17 size_t i; | |
| 18 | |
| 19 uint32_t crcc = crc32(testdata, sizeof(testdata)); | |
| 20 | |
| 21 for (i = 0; i < ARRAY_SIZE(crc); i++) { | |
| 22 uint32_t thiscrc = ~crc[i](0xFFFFFFFF, testdata, sizeof(testdata)); | |
| 23 | |
| 24 if (thiscrc != crcc) { | |
| 25 fprintf(stderr, "%zu, mismatch: %08x, %08x\n", i, crcc, thiscrc); | |
| 26 return -1; | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 return 0; | |
| 31 } | |
| 32 | |
| 33 int main(void) | |
| 34 { | |
| 35 return -crc32_test(); | |
| 36 } |
