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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
1 #include "crc32i.h"
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
2 #include <stdio.h>
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
3
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
4 /* Test implementations and make sure they agree with each other */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
5 int crc32_test(void)
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
6 {
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
7 /* Force alignment :) */
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
8 static const __attribute__((__aligned__(CRC32_MAX_ALIGNMENT))) unsigned char testdata[1024] =
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
9 #define DOUBLE(x) x x
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
10 DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE(DOUBLE("\x01\x02\x04\x08\x10\x20\x40\x80")))))))
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
11 #undef DOUBLE
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
12 ;
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
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
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
16 };
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
17 size_t i;
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
18
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
19 uint32_t crcc = crc32(testdata, sizeof(testdata));
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
20
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
21 for (i = 0; i < ARRAY_SIZE(crc); i++) {
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
22 uint32_t thiscrc = ~crc[i](0xFFFFFFFF, testdata, sizeof(testdata));
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
23
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
24 if (thiscrc != crcc) {
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
25 fprintf(stderr, "%zu, mismatch: %08x, %08x\n", i, crcc, thiscrc);
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
26 return -1;
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
27 }
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
28 }
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
29
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
30 return 0;
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
31 }
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
32
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
33 int main(void)
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
34 {
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
35 return -crc32_test();
422835bc1aca *: checkin
Paper <paper@tflc.us>
parents:
diff changeset
36 }