Don't fail mysteriously on existing trace file.
[ccan] / ccan / crcsync / test / run-crc.c
1 #include "crcsync/crcsync.h"
2 #include "crcsync/crcsync.c"
3 #include "tap/tap.h"
4
5 int main(int argc, char *argv[])
6 {
7         char buffer[1024];
8         unsigned int i, j;
9         uint64_t crcs[12] = { 0xFFFFF, 0xdeadf00d };
10
11         plan_tests(3 + 8192);
12
13         /* Simple test (we know currently crc of 0s is 0) */
14         memset(buffer, 0, sizeof(buffer));
15         crc_of_blocks(buffer, sizeof(buffer), sizeof(buffer), 64, crcs);
16         ok1(crcs[0] == 0);
17         crc_of_blocks(buffer, sizeof(buffer), sizeof(buffer)/2, 64, crcs);
18         ok1(crcs[0] == 0);
19         ok1(crcs[1] == 0);
20
21         /* We know they're using crc64_iso. */
22         for (i = 0; i < sizeof(buffer); i++) {
23                 buffer[i] = i;
24                 crc_of_blocks(buffer, sizeof(buffer), sizeof(buffer)/7,
25                               64, crcs);
26                 for (j = 0; j < sizeof(buffer); j += sizeof(buffer)/7) {
27                         unsigned int len = sizeof(buffer)/7;
28                         if (j + len > sizeof(buffer))
29                                 len = sizeof(buffer) - j;
30                         
31                         ok1(crc64_iso(0, buffer + j, len) == crcs[j/(sizeof(buffer)/7)]);
32                 }
33         }
34
35         return exit_status();
36 }