t/axmap: add pre/post bit set checks
[fio.git] / t / axmap.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <fcntl.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <inttypes.h>
7
8 #include "../lib/lfsr.h"
9 #include "../lib/axmap.h"
10
11 void *smalloc(size_t size)
12 {
13         return malloc(size);
14 }
15
16 void sfree(void *ptr)
17 {
18         free(ptr);
19 }
20
21 int main(int argc, char *argv[])
22 {
23         struct fio_lfsr lfsr;
24         size_t osize, size = (1UL << 28) - 200;
25         struct axmap *map;
26         uint64_t ff;
27         int seed = 1;
28
29         if (argc > 1) {
30                 size = strtoul(argv[1], NULL, 10);
31                 if (argc > 2)
32                         seed = strtoul(argv[2], NULL, 10);
33         }
34
35         printf("Using %llu entries\n", (unsigned long long) size);
36
37         lfsr_init(&lfsr, size, seed);
38         map = axmap_new(size);
39         osize = size;
40
41         while (size--) {
42                 uint64_t val;
43
44                 if (lfsr_next(&lfsr, &val, osize)) {
45                         printf("lfsr: short loop\n");
46                         break;
47                 }
48                 if (axmap_isset(map, val)) {
49                         printf("bit already set\n");
50                         break;
51                 }
52                 axmap_set(map, val);
53                 if (!axmap_isset(map, val)) {
54                         printf("bit not set\n");
55                         break;
56                 }
57         }
58
59         ff = axmap_next_free(map, osize);
60         if (ff != (uint64_t) -1ULL) {
61                 printf("axmap_next_free broken: got %llu\n", (unsigned long long) ff);
62                 return 1;
63         }
64
65         return 0;
66 }