X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=junkcode%2Frusty%40rustcorp.com.au-ntdb%2Ftest%2Fapi-12-store.c;fp=junkcode%2Frusty%40rustcorp.com.au-ntdb%2Ftest%2Fapi-12-store.c;h=f5b3b72a373e4dd17dafde6999c21bff88b08bfa;hb=1aab74723e837a0fd8091e264a325bb2cdcdd0fa;hp=0000000000000000000000000000000000000000;hpb=979071e8587d4819a7f78613b68d29e222e5db63;p=ccan diff --git a/junkcode/rusty@rustcorp.com.au-ntdb/test/api-12-store.c b/junkcode/rusty@rustcorp.com.au-ntdb/test/api-12-store.c new file mode 100644 index 00000000..f5b3b72a --- /dev/null +++ b/junkcode/rusty@rustcorp.com.au-ntdb/test/api-12-store.c @@ -0,0 +1,55 @@ +#include "config.h" +#include "../ntdb.h" +#include "../private.h" +#include "tap-interface.h" +#include +#include "logging.h" +#include "helpapi-external-agent.h" + +/* We use the same seed which we saw a failure on. */ +static uint32_t fixedhash(const void *key, size_t len, uint32_t seed, void *p) +{ + return hash64_stable((const unsigned char *)key, len, + *(uint64_t *)p); +} + +int main(int argc, char *argv[]) +{ + unsigned int i, j; + struct ntdb_context *ntdb; + uint64_t seed = 16014841315512641303ULL; + union ntdb_attribute fixed_hattr + = { .hash = { .base = { NTDB_ATTRIBUTE_HASH }, + .fn = fixedhash, + .data = &seed } }; + int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP, + NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT, + NTDB_NOMMAP|NTDB_CONVERT }; + NTDB_DATA key = { (unsigned char *)&j, sizeof(j) }; + NTDB_DATA data = { (unsigned char *)&j, sizeof(j) }; + + fixed_hattr.base.next = &tap_log_attr; + + plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 500 * 3) + 1); + for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { + ntdb = ntdb_open("run-12-store.ntdb", flags[i]|MAYBE_NOSYNC, + O_RDWR|O_CREAT|O_TRUNC, 0600, &fixed_hattr); + ok1(ntdb); + if (!ntdb) + continue; + + /* We seemed to lose some keys. + * Insert and check they're in there! */ + for (j = 0; j < 500; j++) { + NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */ + ok1(ntdb_store(ntdb, key, data, NTDB_REPLACE) == 0); + ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS); + ok1(ntdb_deq(d, data)); + free(d.dptr); + } + ntdb_close(ntdb); + } + + ok1(tap_log_messages == 0); + return exit_status(); +}