api-missing-entries.c 1.2 KB

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