1 #include <ccan/failtest/failtest_override.h>
2 #include "tdb2-source.h"
3 #include <ccan/tap/tap.h>
4 #include <ccan/failtest/failtest.h>
6 #include "failtest_helper.h"
8 static bool failtest_suppress
= false;
10 /* Don't need to test everything here, just want expand testing. */
11 static enum failtest_result
12 suppress_failure(struct failtest_call
*history
, unsigned num
)
14 if (failtest_suppress
)
15 return FAIL_DONT_FAIL
;
16 return block_repeat_failures(history
, num
);
19 int main(int argc
, char *argv
[])
23 struct tdb_context
*tdb
;
24 int flags
[] = { TDB_INTERNAL
, TDB_DEFAULT
, TDB_NOMMAP
,
25 TDB_INTERNAL
|TDB_CONVERT
, TDB_CONVERT
,
26 TDB_NOMMAP
|TDB_CONVERT
};
28 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 11 + 1);
30 failtest_init(argc
, argv
);
31 failtest_hook
= suppress_failure
;
32 failtest_exit_check
= exit_check_log
;
34 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
35 failtest_suppress
= true;
36 tdb
= tdb_open("run-expand.tdb", flags
[i
],
37 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &tap_log_attr
);
41 val
= tdb
->file
->map_size
;
42 /* Need some hash lock for expand. */
43 ok1(tdb_lock_hashes(tdb
, 0, 1, F_WRLCK
, TDB_LOCK_WAIT
) == 0);
44 failtest_suppress
= false;
45 if (!ok1(tdb_expand(tdb
, 1) == 0)) {
46 failtest_suppress
= true;
50 failtest_suppress
= true;
52 ok1(tdb
->file
->map_size
>= val
+ 1 * TDB_EXTENSION_FACTOR
);
53 ok1(tdb_unlock_hashes(tdb
, 0, 1, F_WRLCK
) == 0);
54 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
56 val
= tdb
->file
->map_size
;
57 ok1(tdb_lock_hashes(tdb
, 0, 1, F_WRLCK
, TDB_LOCK_WAIT
) == 0);
58 failtest_suppress
= false;
59 if (!ok1(tdb_expand(tdb
, 1024) == 0)) {
60 failtest_suppress
= true;
64 failtest_suppress
= true;
65 ok1(tdb_unlock_hashes(tdb
, 0, 1, F_WRLCK
) == 0);
66 ok1(tdb
->file
->map_size
>= val
+ 1024 * TDB_EXTENSION_FACTOR
);
67 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
71 ok1(tap_log_messages
== 0);
72 failtest_exit(exit_status());