run-02-expand.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <ccan/failtest/failtest_override.h>
  2. #include "ntdb-source.h"
  3. #include "tap-interface.h"
  4. #include <ccan/failtest/failtest.h>
  5. #include "logging.h"
  6. #include "failtest_helper.h"
  7. #include "helprun-external-agent.h"
  8. int main(int argc, char *argv[])
  9. {
  10. unsigned int i;
  11. uint64_t val;
  12. struct ntdb_context *ntdb;
  13. int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
  14. NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
  15. NTDB_NOMMAP|NTDB_CONVERT };
  16. plan_tests(sizeof(flags) / sizeof(flags[0]) * 11 + 1);
  17. failtest_init(argc, argv);
  18. failtest_hook = block_repeat_failures;
  19. failtest_exit_check = exit_check_log;
  20. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  21. failtest_suppress = true;
  22. ntdb = ntdb_open("run-expand.ntdb", flags[i]|MAYBE_NOSYNC,
  23. O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
  24. if (!ok1(ntdb))
  25. break;
  26. val = ntdb->file->map_size;
  27. /* Need some hash lock for expand. */
  28. ok1(ntdb_lock_hash(ntdb, 0, F_WRLCK) == 0);
  29. failtest_suppress = false;
  30. if (!ok1(ntdb_expand(ntdb, 1) == 0)) {
  31. failtest_suppress = true;
  32. ntdb_close(ntdb);
  33. break;
  34. }
  35. failtest_suppress = true;
  36. ok1(ntdb->file->map_size >= val + 1 * NTDB_EXTENSION_FACTOR);
  37. ok1(ntdb_unlock_hash(ntdb, 0, F_WRLCK) == 0);
  38. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  39. val = ntdb->file->map_size;
  40. ok1(ntdb_lock_hash(ntdb, 0, F_WRLCK) == 0);
  41. failtest_suppress = false;
  42. if (!ok1(ntdb_expand(ntdb, 1024) == 0)) {
  43. failtest_suppress = true;
  44. ntdb_close(ntdb);
  45. break;
  46. }
  47. failtest_suppress = true;
  48. ok1(ntdb_unlock_hash(ntdb, 0, F_WRLCK) == 0);
  49. ok1(ntdb->file->map_size >= val + 1024 * NTDB_EXTENSION_FACTOR);
  50. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  51. ntdb_close(ntdb);
  52. }
  53. ok1(tap_log_messages == 0);
  54. failtest_exit(exit_status());
  55. /*
  56. * We will never reach this but the compiler complains if we do not
  57. * return in this function.
  58. */
  59. return EFAULT;
  60. }