1 #include "tdb2-source.h"
2 #include "tap-interface.h"
5 static bool empty_freetable(struct tdb_context
*tdb
)
7 struct tdb_freetable ftab
;
10 /* Now, free table should be completely exhausted in zone 0 */
11 if (tdb_read_convert(tdb
, tdb
->tdb2
.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 tdb_context
*tdb
;
26 int flags
[] = { TDB_INTERNAL
, TDB_DEFAULT
, TDB_NOMMAP
,
27 TDB_INTERNAL
|TDB_CONVERT
, TDB_CONVERT
,
28 TDB_NOMMAP
|TDB_CONVERT
};
30 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 9 + 1);
32 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
35 bool was_empty
= false;
40 tdb
= tdb_open("run-30-exhaust-before-expand.tdb", flags
[i
],
41 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
46 ok1(empty_freetable(tdb
));
47 /* Need some hash lock for expand. */
48 ok1(tdb_lock_hashes(tdb
, 0, 1, F_WRLCK
, TDB_LOCK_WAIT
) == 0);
49 /* Create some free space. */
50 ok1(tdb_expand(tdb
, 1) == 0);
51 ok1(tdb_unlock_hashes(tdb
, 0, 1, F_WRLCK
) == 0);
52 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
53 ok1(!empty_freetable(tdb
));
55 size
= tdb
->file
->map_size
;
56 /* Insert minimal-length records until we expand. */
57 for (j
= 0; tdb
->file
->map_size
== size
; j
++) {
58 was_empty
= empty_freetable(tdb
);
59 if (tdb_store(tdb
, k
, k
, TDB_INSERT
) != 0)
60 err(1, "Failed to store record %i", j
);
63 /* Would have been empty before expansion, but no longer. */
65 ok1(!empty_freetable(tdb
));
69 ok1(tap_log_messages
== 0);