]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-missing-entries.c
tdb2: make tests include a single mega-header to simplify future patches
[ccan] / ccan / tdb2 / test / run-missing-entries.c
1 #include "tdb2-source.h"
2 /* Another test revealed that we lost an entry.  This reproduces it. */
3 #include <ccan/tap/tap.h>
4 #include "logging.h"
5
6 #define NUM_RECORDS 1189
7
8 /* We use the same seed which we saw this failure on. */
9 static uint64_t failhash(const void *key, size_t len, uint64_t seed, void *p)
10 {
11         seed = 699537674708983027ULL;
12         return hash64_stable((const unsigned char *)key, len, seed);
13 }
14
15 int main(int argc, char *argv[])
16 {
17         int i;
18         struct tdb_context *tdb;
19         struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
20         struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
21         union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
22                                                 .fn = failhash } };
23
24         hattr.base.next = &tap_log_attr;
25         plan_tests(1 + 2 * NUM_RECORDS + 1);
26
27         tdb = tdb_open("run-missing-entries.tdb", TDB_INTERNAL,
28                        O_RDWR|O_CREAT|O_TRUNC, 0600, &hattr);
29         ok1(tdb);
30         if (tdb) {
31                 for (i = 0; i < NUM_RECORDS; i++) {
32                         ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0);
33                         ok1(tdb_check(tdb, NULL, NULL) == 0);
34                 }
35                 tdb_close(tdb);
36         }
37
38         ok1(tap_log_messages == 0);
39         return exit_status();
40 }