api-missing-entries.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /* Another test revealed that we lost an entry. This reproduces it. */
  2. #include <ccan/tdb2/tdb2.h>
  3. #include <ccan/hash/hash.h>
  4. #include <ccan/tap/tap.h>
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include "logging.h"
  9. #define NUM_RECORDS 1189
  10. /* We use the same seed which we saw this failure on. */
  11. static uint64_t failhash(const void *key, size_t len, uint64_t seed, void *p)
  12. {
  13. seed = 699537674708983027ULL;
  14. return hash64_stable((const unsigned char *)key, len, seed);
  15. }
  16. int main(int argc, char *argv[])
  17. {
  18. int i;
  19. struct tdb_context *tdb;
  20. struct tdb_data key = { (unsigned char *)&i, sizeof(i) };
  21. struct tdb_data data = { (unsigned char *)&i, sizeof(i) };
  22. union tdb_attribute hattr = { .hash = { .base = { TDB_ATTRIBUTE_HASH },
  23. .fn = failhash } };
  24. hattr.base.next = &tap_log_attr;
  25. plan_tests(1 + 2 * NUM_RECORDS + 1);
  26. tdb = tdb_open("run-missing-entries.tdb", TDB_INTERNAL,
  27. O_RDWR|O_CREAT|O_TRUNC, 0600, &hattr);
  28. ok1(tdb);
  29. if (tdb) {
  30. for (i = 0; i < NUM_RECORDS; i++) {
  31. ok1(tdb_store(tdb, key, data, TDB_REPLACE) == 0);
  32. ok1(tdb_check(tdb, NULL, NULL) == 0);
  33. }
  34. tdb_close(tdb);
  35. }
  36. ok1(tap_log_messages == 0);
  37. return exit_status();
  38. }