1 #include "ntdb-source.h"
2 #include "tap-interface.h"
5 static bool empty_freetable(struct ntdb_context
*ntdb
)
7 struct ntdb_freetable ftab
;
10 /* Now, free table should be completely exhausted in zone 0 */
11 if (ntdb_read_convert(ntdb
, ntdb
->ftable_off
, &ftab
, sizeof(ftab
)) != 0)
14 for (i
= 0; i
< sizeof(ftab
.buckets
)/sizeof(ftab
.buckets
[0]); i
++) {
22 int main(int argc
, char *argv
[])
25 struct ntdb_context
*ntdb
;
26 int flags
[] = { NTDB_INTERNAL
, NTDB_DEFAULT
, NTDB_NOMMAP
,
27 NTDB_INTERNAL
|NTDB_CONVERT
, NTDB_CONVERT
,
28 NTDB_NOMMAP
|NTDB_CONVERT
};
30 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 7 + 1);
32 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
35 bool was_empty
= false;
40 ntdb
= ntdb_open("run-30-exhaust-before-expand.ntdb",
41 flags
[i
]|MAYBE_NOSYNC
,
42 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
47 ok1(ntdb_check(ntdb
, NULL
, NULL
) == 0);
48 /* There's one empty record in initial db. */
49 ok1(!empty_freetable(ntdb
));
51 size
= ntdb
->file
->map_size
;
53 /* Create one record to chew up most space. */
54 d
.dsize
= size
- NEW_DATABASE_HDR_SIZE(ntdb
->hash_bits
) - 32;
55 d
.dptr
= calloc(d
.dsize
, 1);
57 ok1(ntdb_store(ntdb
, k
, d
, NTDB_INSERT
) == 0);
58 ok1(ntdb
->file
->map_size
== size
);
61 /* Now insert minimal-length records until we expand. */
62 for (j
= 1; ntdb
->file
->map_size
== size
; j
++) {
63 was_empty
= empty_freetable(ntdb
);
64 if (ntdb_store(ntdb
, k
, k
, NTDB_INSERT
) != 0)
65 err(1, "Failed to store record %i", j
);
68 /* Would have been empty before expansion, but no longer. */
70 ok1(!empty_freetable(ntdb
));
74 ok1(tap_log_messages
== 0);