api-12-store.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "config.h"
  2. #include "../ntdb.h"
  3. #include "../private.h"
  4. #include "tap-interface.h"
  5. #include <ccan/hash/hash.h>
  6. #include "logging.h"
  7. #include "helpapi-external-agent.h"
  8. /* We use the same seed which we saw a failure on. */
  9. static uint32_t fixedhash(const void *key, size_t len, uint32_t seed, void *p)
  10. {
  11. return hash64_stable((const unsigned char *)key, len,
  12. *(uint64_t *)p);
  13. }
  14. int main(int argc, char *argv[])
  15. {
  16. unsigned int i, j;
  17. struct ntdb_context *ntdb;
  18. uint64_t seed = 16014841315512641303ULL;
  19. union ntdb_attribute fixed_hattr
  20. = { .hash = { .base = { NTDB_ATTRIBUTE_HASH },
  21. .fn = fixedhash,
  22. .data = &seed } };
  23. int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
  24. NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
  25. NTDB_NOMMAP|NTDB_CONVERT };
  26. NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
  27. NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
  28. fixed_hattr.base.next = &tap_log_attr;
  29. plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 500 * 3) + 1);
  30. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  31. ntdb = ntdb_open("run-12-store.ntdb", flags[i]|MAYBE_NOSYNC,
  32. O_RDWR|O_CREAT|O_TRUNC, 0600, &fixed_hattr);
  33. ok1(ntdb);
  34. if (!ntdb)
  35. continue;
  36. /* We seemed to lose some keys.
  37. * Insert and check they're in there! */
  38. for (j = 0; j < 500; j++) {
  39. NTDB_DATA d = { NULL, 0 }; /* Bogus GCC warning */
  40. ok1(ntdb_store(ntdb, key, data, NTDB_REPLACE) == 0);
  41. ok1(ntdb_fetch(ntdb, key, &d) == NTDB_SUCCESS);
  42. ok1(ntdb_deq(d, data));
  43. free(d.dptr);
  44. }
  45. ntdb_close(ntdb);
  46. }
  47. ok1(tap_log_messages == 0);
  48. return exit_status();
  49. }