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 add a zone, doubling file size.. */
29 val = tdb->map_size - 1 - sizeof(struct tdb_header);
30 ok1(tdb_expand(tdb, 1) == 0);
31 ok1(tdb->map_size == 2 * val + 1 + sizeof(struct tdb_header));
32 ok1(tdb_check(tdb, NULL, NULL) == 0);
34 /* Second expand, add another zone of same size. */
35 ok1(tdb_expand(tdb, 1) == 0);
36 ok1(tdb->map_size == 3 * val + 1 + sizeof(struct tdb_header));
37 ok1(tdb_check(tdb, NULL, NULL) == 0);
39 /* Large expand, but can only add 4th zone of same size. */
40 ok1(tdb_expand(tdb, 4*val) == 0);
41 ok1(tdb->map_size == 4 * val + 1 + sizeof(struct tdb_header));
42 ok1(tdb_check(tdb, NULL, NULL) == 0);
44 /* Large expand now will double file. */
45 ok1(tdb_expand(tdb, 4*val) == 0);
46 ok1(tdb->map_size == 8 * val + 1 + sizeof(struct tdb_header));
47 ok1(tdb_check(tdb, NULL, NULL) == 0);
50 ok1(tdb_expand(tdb, 4*val) == 0);
51 ok1(tdb->map_size == 16 * val + 1 + sizeof(struct tdb_header));
52 ok1(tdb_check(tdb, NULL, NULL) == 0);
54 /* Below comfort level, will add a single 8*val zone. */
55 ok1(tdb_expand(tdb, ((8*val) >> TDB_COMFORT_FACTOR_BITS)
56 - sizeof(struct tdb_used_record)) == 0);
57 ok1(tdb->map_size == 24 * val + 1 + sizeof(struct tdb_header));
61 ok1(tap_log_messages == 0);