]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/api-12-store.c
tdb2: suppress failtest more than once on mmap.
[ccan] / ccan / tdb2 / test / api-12-store.c
1 #include <ccan/tdb2/tdb2.h>
2 #include <ccan/tap/tap.h>
3 #include <ccan/hash/hash.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7
8 #include "logging.h"
9
10 /* We use the same seed which we saw a failure on. */
11 static uint64_t fixedhash(const void *key, size_t len, uint64_t seed, void *p)
12 {
13         return hash64_stable((const unsigned char *)key, len,
14                              *(uint64_t *)p);
15 }
16
17 int main(int argc, char *argv[])
18 {
19         unsigned int i, j;
20         struct tdb_context *tdb;
21         uint64_t seed = 16014841315512641303ULL;
22         union tdb_attribute fixed_hattr
23                 = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
24                               .fn = fixedhash,
25                               .data = &seed } };
26         int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
27                         TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
28                         TDB_NOMMAP|TDB_CONVERT };
29         struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
30         struct tdb_data data = { (unsigned char *)&j, sizeof(j) };
31
32         fixed_hattr.base.next = &tap_log_attr;
33
34         plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 500 * 3) + 1);
35         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
36                 tdb = tdb_open("run-12-store.tdb", flags[i],
37                                O_RDWR|O_CREAT|O_TRUNC, 0600, &fixed_hattr);
38                 ok1(tdb);
39                 if (!tdb)
40                         continue;
41
42                 /* We seemed to lose some keys.
43                  * Insert and check they're in there! */
44                 for (j = 0; j < 500; j++) {
45                         struct tdb_data d = { NULL, 0 }; /* Bogus GCC warning */
46                         ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0);
47                         ok1(tdb_fetch(tdb, key, &d) == TDB_SUCCESS);
48                         ok1(tdb_deq(d, data));
49                         free(d.dptr);
50                 }
51                 tdb_close(tdb);
52         }
53
54         ok1(tap_log_messages == 0);
55         return exit_status();
56 }