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>
10 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]) * 18 + 1);
21 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
22 tdb = tdb_open("run-expand.tdb", flags[i],
23 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
28 /* First expand. Should not fill zone. */
29 val = tdb->map_size - sizeof(struct tdb_header);
30 ok1(tdb_expand(tdb, 1) == 0);
31 ok1(tdb->map_size < sizeof(struct tdb_header)
32 + (1 << INITIAL_ZONE_BITS));
33 ok1(tdb_check(tdb, NULL, NULL) == 0);
36 val = (1<<INITIAL_ZONE_BITS)
37 - sizeof(struct tdb_used_record)
38 - (tdb->map_size - sizeof(struct tdb_header));
39 ok1(tdb_expand(tdb, val) == 0);
40 ok1(tdb->map_size == sizeof(struct tdb_header)
41 + (1 << INITIAL_ZONE_BITS));
42 ok1(tdb_check(tdb, NULL, NULL) == 0);
44 /* Second expand, adds another zone of same size. */
45 ok1(tdb_expand(tdb, 4 << INITIAL_ZONE_BITS) == 0);
47 (2<<INITIAL_ZONE_BITS) + sizeof(struct tdb_header));
48 ok1(tdb_check(tdb, NULL, NULL) == 0);
50 /* Large expand now will double file. */
51 ok1(tdb_expand(tdb, 4 << INITIAL_ZONE_BITS) == 0);
53 (4<<INITIAL_ZONE_BITS) + sizeof(struct tdb_header));
54 ok1(tdb_check(tdb, NULL, NULL) == 0);
57 ok1(tdb_expand(tdb, 4 << INITIAL_ZONE_BITS) == 0);
59 (8<<INITIAL_ZONE_BITS) + sizeof(struct tdb_header));
60 ok1(tdb_check(tdb, NULL, NULL) == 0);
62 /* Below comfort level, won't fill zone. */
64 ((3 << INITIAL_ZONE_BITS)
65 >> TDB_COMFORT_FACTOR_BITS)
66 - sizeof(struct tdb_used_record)) == 0);
67 ok1(tdb->map_size < (12<<INITIAL_ZONE_BITS)
68 + sizeof(struct tdb_header));
72 ok1(tap_log_messages == 0);