s3:smb2_write: pass fsp->fnum to init_strict_lock_struct()
[Samba/gebeck_regimport.git] / lib / tdb2 / test / run-30-exhaust-before-expand.c
blobc39f0591f0c97cc252e5c04cedbe80e8f92dbade
1 #include "tdb2-source.h"
2 #include "tap-interface.h"
3 #include "logging.h"
5 static bool empty_freetable(struct tdb_context *tdb)
7 struct tdb_freetable ftab;
8 unsigned int i;
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)
12 abort();
14 for (i = 0; i < sizeof(ftab.buckets)/sizeof(ftab.buckets[0]); i++) {
15 if (ftab.buckets[i])
16 return false;
18 return true;
22 int main(int argc, char *argv[])
24 unsigned int i, j;
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++) {
33 TDB_DATA k;
34 uint64_t size;
35 bool was_empty = false;
37 k.dptr = (void *)&j;
38 k.dsize = sizeof(j);
40 tdb = tdb_open("run-30-exhaust-before-expand.tdb", flags[i],
41 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
42 ok1(tdb);
43 if (!tdb)
44 continue;
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. */
64 ok1(was_empty);
65 ok1(!empty_freetable(tdb));
66 tdb_close(tdb);
69 ok1(tap_log_messages == 0);
70 return exit_status();