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