]> git.ozlabs.org Git - ccan/blob - junkcode/rusty@rustcorp.com.au-ntdb/test/run-02-expand.c
ccan/ntdb: demote to junkcode.
[ccan] / junkcode / rusty@rustcorp.com.au-ntdb / test / run-02-expand.c
1 #include <ccan/failtest/failtest_override.h>
2 #include "ntdb-source.h"
3 #include "tap-interface.h"
4 #include <ccan/failtest/failtest.h>
5 #include "logging.h"
6 #include "failtest_helper.h"
7 #include "helprun-external-agent.h"
8
9 int main(int argc, char *argv[])
10 {
11         unsigned int i;
12         uint64_t val;
13         struct ntdb_context *ntdb;
14         int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
15                         NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
16                         NTDB_NOMMAP|NTDB_CONVERT };
17
18         plan_tests(sizeof(flags) / sizeof(flags[0]) * 11 + 1);
19
20         failtest_init(argc, argv);
21         failtest_hook = block_repeat_failures;
22         failtest_exit_check = exit_check_log;
23
24         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
25                 failtest_suppress = true;
26                 ntdb = ntdb_open("run-expand.ntdb", flags[i]|MAYBE_NOSYNC,
27                                  O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
28                 if (!ok1(ntdb))
29                         break;
30
31                 val = ntdb->file->map_size;
32                 /* Need some hash lock for expand. */
33                 ok1(ntdb_lock_hash(ntdb, 0, F_WRLCK) == 0);
34                 failtest_suppress = false;
35                 if (!ok1(ntdb_expand(ntdb, 1) == 0)) {
36                         failtest_suppress = true;
37                         ntdb_close(ntdb);
38                         break;
39                 }
40                 failtest_suppress = true;
41
42                 ok1(ntdb->file->map_size >= val + 1 * NTDB_EXTENSION_FACTOR);
43                 ok1(ntdb_unlock_hash(ntdb, 0, F_WRLCK) == 0);
44                 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
45
46                 val = ntdb->file->map_size;
47                 ok1(ntdb_lock_hash(ntdb, 0, F_WRLCK) == 0);
48                 failtest_suppress = false;
49                 if (!ok1(ntdb_expand(ntdb, 1024) == 0)) {
50                         failtest_suppress = true;
51                         ntdb_close(ntdb);
52                         break;
53                 }
54                 failtest_suppress = true;
55                 ok1(ntdb_unlock_hash(ntdb, 0, F_WRLCK) == 0);
56                 ok1(ntdb->file->map_size >= val + 1024 * NTDB_EXTENSION_FACTOR);
57                 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
58                 ntdb_close(ntdb);
59         }
60
61         ok1(tap_log_messages == 0);
62         failtest_exit(exit_status());
63
64         /*
65          * We will never reach this but the compiler complains if we do not
66          * return in this function.
67          */
68         return EFAULT;
69 }