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/tdb2/hash.c>
7 #include <ccan/tap/tap.h>
11 int main(int argc, char *argv[])
14 struct tdb_context *tdb;
15 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
16 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
17 TDB_NOMMAP|TDB_CONVERT };
19 plan_tests(sizeof(flags) / sizeof(flags[0]) * 5 + 1);
21 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
22 tdb_off_t free[BUCKETS_FOR_ZONE(INITIAL_ZONE_BITS) + 1];
29 tdb = tdb_open("run-30-exhaust-before-expand.tdb", flags[i],
30 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
35 /* We don't want the hash to expand, so we use one alloc to
36 * chew up over most of the space first. */
38 d.dsize = (1 << INITIAL_ZONE_BITS) - 500;
39 d.dptr = malloc(d.dsize);
40 ok1(tdb_store(tdb, k, d, TDB_INSERT) == 0);
41 ok1(tdb->map_size == sizeof(struct tdb_header)
42 + (1 << INITIAL_ZONE_BITS));
44 /* Insert minimal-length records until we add a zone. */
46 tdb->map_size == sizeof(struct tdb_header)
47 + (1 << INITIAL_ZONE_BITS);
49 if (tdb_store(tdb, k, k, TDB_INSERT) != 0)
50 err(1, "Failed to store record %i", j);
53 /* Now, free list should be completely exhausted in zone 0 */
54 ok1(tdb_read_convert(tdb,
55 sizeof(struct tdb_header)
56 + sizeof(struct free_zone_header),
57 &free, sizeof(free)) == 0);
60 for (j = 0; j < sizeof(free)/sizeof(free[0]); j++) {
62 diag("Free bucket %i not empty", j);
70 ok1(tap_log_messages == 0);