]> git.ozlabs.org Git - ccan/blob - ccan/crcsync/test/run-roll.c
gitify the tree, especially the web makefile.
[ccan] / ccan / crcsync / test / run-roll.c
1 #include <ccan/crcsync/crcsync.h>
2 #include <ccan/crcsync/crcsync.c>
3 #include <ccan/tap/tap.h>
4 #include <stdlib.h>
5 #include <stdbool.h>
6
7 /* FIXME: ccanize. */
8 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
9
10 static void test_roll(unsigned int wsize)
11 {
12         uint8_t data[wsize * 2];
13         uint64_t uncrc_tab[256];
14         unsigned int i;
15
16         init_uncrc_tab(uncrc_tab, wsize);
17
18         for (i = 0; i < ARRAY_SIZE(data); i++)
19                 data[i] = random();
20
21         for (i = 1; i < ARRAY_SIZE(data) - wsize; i++) {
22                 uint64_t rollcrc, crc;
23
24                 crc = crc64_iso(0, data+i, wsize);
25                 rollcrc = crc_roll(crc64_iso(0, data+i-1, wsize),
26                                    data[i-1], data[i+wsize-1], uncrc_tab);
27
28                 ok(crc == rollcrc, "wsize %u, i %u", wsize, i);
29         }
30 }
31
32 int main(int argc, char *argv[])
33 {
34         plan_tests(100 - 1 + 128 - 1);
35         test_roll(100);
36         test_roll(128);
37         return exit_status();
38 }