1 #include "ntdb-source.h"
2 #include "tap-interface.h"
4 #include "helprun-external-agent.h"
8 static uint32_t badhash(const void *key, size_t len, uint32_t seed, void *priv)
13 static int trav(struct ntdb_context *ntdb, NTDB_DATA key, NTDB_DATA dbuf, void *p)
16 return ntdb_delete(ntdb, key);
20 int main(int argc, char *argv[])
23 struct ntdb_context *ntdb;
24 NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
25 NTDB_DATA dbuf = { (unsigned char *)&j, sizeof(j) };
26 union ntdb_attribute hattr = { .hash = { .base = { NTDB_ATTRIBUTE_HASH },
28 int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
29 NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
30 NTDB_NOMMAP|NTDB_CONVERT,
33 hattr.base.next = &tap_log_attr;
35 plan_tests(sizeof(flags) / sizeof(flags[0]) * (7 * OVERLOAD + 11) + 1);
36 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
37 NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */
39 ntdb = ntdb_open("run-25-hashoverload.ntdb",
40 flags[i]|MAYBE_NOSYNC,
41 O_RDWR|O_CREAT|O_TRUNC, 0600, &hattr);
46 /* Overload a bucket. */
47 for (j = 0; j < OVERLOAD; j++) {
48 ok1(ntdb_store(ntdb, key, dbuf, NTDB_INSERT) == 0);
50 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
52 /* Check we can find them all. */
53 for (j = 0; j < OVERLOAD; j++) {
54 ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS);
55 ok1(d.dsize == sizeof(j));
57 ok1(d.dptr && memcmp(d.dptr, &j, d.dsize) == 0);
61 /* Traverse through them. */
62 ok1(ntdb_traverse(ntdb, trav, NULL) == OVERLOAD);
64 /* Delete the first 99. */
65 for (j = 0; j < OVERLOAD-1; j++)
66 ok1(ntdb_delete(ntdb, key) == 0);
68 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
70 ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS);
71 ok1(d.dsize == sizeof(j));
73 ok1(d.dptr && memcmp(d.dptr, &j, d.dsize) == 0);
76 /* Traverse through them. */
77 ok1(ntdb_traverse(ntdb, trav, NULL) == 1);
80 for (j = 0; j < OVERLOAD-1; j++) {
81 ok1(ntdb_store(ntdb, key, dbuf, NTDB_INSERT) == 0);
83 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
85 /* Now try deleting as we go. */
86 ok1(ntdb_traverse(ntdb, trav, trav) == OVERLOAD);
87 ok1(ntdb_check(ntdb, NULL, NULL) == 0);
88 ok1(ntdb_traverse(ntdb, trav, NULL) == 0);
92 ok1(tap_log_messages == 0);