ntdb: respect TDB_NO_FSYNC flag for 'make test'
[ddiss/samba.git] / lib / ntdb / test / api-missing-entries.c
1 /* Another test revealed that we lost an entry.  This reproduces it. */
2 #include "config.h"
3 #include "ntdb.h"
4 #include <ccan/hash/hash.h>
5 #include "tap-interface.h"
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <fcntl.h>
9 #include "logging.h"
10
11 #define NUM_RECORDS 1189
12
13 /* We use the same seed which we saw this failure on. */
14 static uint32_t failhash(const void *key, size_t len, uint32_t seed, void *p)
15 {
16         return hash64_stable((const unsigned char *)key, len,
17                              699537674708983027ULL);
18 }
19
20 int main(int argc, char *argv[])
21 {
22         int i;
23         struct ntdb_context *ntdb;
24         NTDB_DATA key = { (unsigned char *)&i, sizeof(i) };
25         NTDB_DATA data = { (unsigned char *)&i, sizeof(i) };
26         union ntdb_attribute hattr = { .hash = { .base = { NTDB_ATTRIBUTE_HASH },
27                                                 .fn = failhash } };
28
29         hattr.base.next = &tap_log_attr;
30         plan_tests(1 + NUM_RECORDS + 2);
31
32         ntdb = ntdb_open("run-missing-entries.ntdb", NTDB_INTERNAL,
33                          O_RDWR|O_CREAT|O_TRUNC, 0600, &hattr);
34         if (ok1(ntdb)) {
35                 for (i = 0; i < NUM_RECORDS; i++) {
36                         ok1(ntdb_store(ntdb, key, data, NTDB_REPLACE) == 0);
37                 }
38                 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
39                 ntdb_close(ntdb);
40         }
41
42         ok1(tap_log_messages == 0);
43         return exit_status();
44 }