1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/check.c>
6 #include <ccan/tap/tap.h>
9 /* We rig the hash so adjacent-numbered records always clash. */
10 static uint64_t clash(const void *key, size_t len, uint64_t seed, void *priv)
12 return *(unsigned int *)key / 2;
15 int main(int argc, char *argv[])
18 struct tdb_context *tdb;
20 struct tdb_data key = { (unsigned char *)&v, sizeof(v) };
21 struct tdb_data data = { (unsigned char *)&v, sizeof(v) };
22 union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
24 int flags[] = { TDB_INTERNAL, TDB_DEFAULT,
25 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT };
27 hattr.base.next = &tap_log_attr;
29 plan_tests(sizeof(flags) / sizeof(flags[0]) * 11 + 1);
30 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
31 tdb = tdb_open("run-enlarge-hash.tdb", flags[i],
32 O_RDWR|O_CREAT|O_TRUNC, 0600, &hattr);
37 /* Put a single entry in. */
39 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
41 ok1(tdb_check(tdb, NULL, NULL) == 0);
43 /* Put a non-clashing entry in. */
45 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
47 ok1(tdb_check(tdb, NULL, NULL) == 0);
49 /* Now, make a clash. */
51 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
53 ok1(tdb_check(tdb, NULL, NULL) == 0);
56 v = ((1 << tdb->header.v.hash_bits) - 1) * 2;
57 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
59 ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0);
60 ok1(tdb_check(tdb, NULL, NULL) == 0);
62 ok1(tdb_check(tdb, NULL, NULL) == 0);
66 ok1(tap_log_messages == 0);