1 #include "ntdb-source.h"
2 #include "tap-interface.h"
4 #include "helprun-external-agent.h"
6 static bool empty_freetable(struct ntdb_context *ntdb)
8 struct ntdb_freetable ftab;
11 /* Now, free table should be completely exhausted in zone 0 */
12 if (ntdb_read_convert(ntdb, ntdb->ftable_off, &ftab, sizeof(ftab)) != 0)
15 for (i = 0; i < sizeof(ftab.buckets)/sizeof(ftab.buckets[0]); i++) {
23 int main(int argc, char *argv[])
26 struct ntdb_context *ntdb;
27 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
28 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
29 NTDB_NOMMAP|NTDB_CONVERT };
31 plan_tests(sizeof(flags) / sizeof(flags[0]) * 7 + 1);
33 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
36 bool was_empty = false;
41 ntdb = ntdb_open("run-30-exhaust-before-expand.ntdb",
42 flags[i]|MAYBE_NOSYNC,
43 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
48 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
49 /* There's one empty record in initial db. */
50 ok1(!empty_freetable(ntdb));
52 size = ntdb->file->map_size;
54 /* Create one record to chew up most space. */
55 d.dsize = size - NEW_DATABASE_HDR_SIZE(ntdb->hash_bits) - 32;
56 d.dptr = calloc(d.dsize, 1);
58 ok1(ntdb_store(ntdb, k, d, NTDB_INSERT) == 0);
59 ok1(ntdb->file->map_size == size);
62 /* Now insert minimal-length records until we expand. */
63 for (j = 1; ntdb->file->map_size == size; j++) {
64 was_empty = empty_freetable(ntdb);
65 if (ntdb_store(ntdb, k, k, NTDB_INSERT) != 0)
66 err(1, "Failed to store record %i", j);
69 /* Would have been empty before expansion, but no longer. */
71 ok1(!empty_freetable(ntdb));
75 ok1(tap_log_messages == 0);