s4:torture:rpc: fix a comment typo in samba3.smb2-reauth2
[Samba.git] / lib / tdb / test / run-transaction-expand.c
blob3b79dbb6eaec3e46bf45b803b05879d355efd626
1 #include "../common/tdb_private.h"
3 /* Speed up the tests: setting TDB_NOSYNC removed recovery altogether. */
4 static inline int fake_fsync(int fd)
6 return 0;
8 #define fsync fake_fsync
10 #ifdef MS_SYNC
11 static inline int fake_msync(void *addr, size_t length, int flags)
13 return 0;
15 #define msync fake_msync
16 #endif
18 #ifdef HAVE_FDATASYNC
19 static inline int fake_fdatasync(int fd)
21 return 0;
23 #define fdatasync fake_fdatasync
24 #endif
26 #include "../common/io.c"
27 #include "../common/tdb.c"
28 #include "../common/lock.c"
29 #include "../common/freelist.c"
30 #include "../common/traverse.c"
31 #include "../common/transaction.c"
32 #include "../common/error.c"
33 #include "../common/open.c"
34 #include "../common/check.c"
35 #include "../common/hash.c"
36 #include "tap-interface.h"
37 #include <stdlib.h>
38 #include <err.h>
39 #include "logging.h"
41 static void write_record(struct tdb_context *tdb, size_t extra_len,
42 TDB_DATA *data)
44 TDB_DATA key;
45 key.dsize = strlen("hi");
46 key.dptr = (void *)"hi";
48 data->dsize += extra_len;
49 tdb_transaction_start(tdb);
50 tdb_store(tdb, key, *data, TDB_REPLACE);
51 tdb_transaction_commit(tdb);
54 int main(int argc, char *argv[])
56 struct tdb_context *tdb;
57 size_t i;
58 TDB_DATA data;
59 struct tdb_record rec;
60 tdb_off_t off;
62 plan_tests(4);
63 tdb = tdb_open_ex("run-transaction-expand.tdb",
64 1024, TDB_CLEAR_IF_FIRST,
65 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
66 ok1(tdb);
68 data.dsize = 0;
69 data.dptr = calloc(1000, getpagesize());
71 /* Simulate a slowly growing record. */
72 for (i = 0; i < 1000; i++)
73 write_record(tdb, getpagesize(), &data);
75 tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &off);
76 tdb_read(tdb, off, &rec, sizeof(rec), DOCONV());
77 diag("TDB size = %zu, recovery = %u-%u",
78 (size_t)tdb->map_size, off, off + sizeof(rec) + rec.rec_len);
80 /* We should only be about 5 times larger than largest record. */
81 ok1(tdb->map_size < 6 * i * getpagesize());
82 tdb_close(tdb);
84 tdb = tdb_open_ex("run-transaction-expand.tdb",
85 1024, TDB_CLEAR_IF_FIRST,
86 O_CREAT|O_TRUNC|O_RDWR, 0600, &taplogctx, NULL);
87 ok1(tdb);
89 data.dsize = 0;
91 /* Simulate a slowly growing record, repacking to keep
92 * recovery area at end. */
93 for (i = 0; i < 1000; i++) {
94 write_record(tdb, getpagesize(), &data);
95 if (i % 10 == 0)
96 tdb_repack(tdb);
99 tdb_ofs_read(tdb, TDB_RECOVERY_HEAD, &off);
100 tdb_read(tdb, off, &rec, sizeof(rec), DOCONV());
101 diag("TDB size = %zu, recovery = %u-%u",
102 (size_t)tdb->map_size, off, off + sizeof(rec) + rec.rec_len);
104 /* We should only be about 4 times larger than largest record. */
105 ok1(tdb->map_size < 5 * i * getpagesize());
106 tdb_close(tdb);
107 free(data.dptr);
109 return exit_status();