run-35-convert.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "../private.h"
  2. #include <ccan/failtest/failtest_override.h>
  3. #include "ntdb-source.h"
  4. #include "tap-interface.h"
  5. #include <ccan/failtest/failtest.h>
  6. #include "logging.h"
  7. #include "failtest_helper.h"
  8. #include "helprun-external-agent.h"
  9. int main(int argc, char *argv[])
  10. {
  11. unsigned int i, messages = 0;
  12. struct ntdb_context *ntdb;
  13. int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
  14. NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
  15. failtest_init(argc, argv);
  16. failtest_hook = block_repeat_failures;
  17. failtest_exit_check = exit_check_log;
  18. plan_tests(sizeof(flags) / sizeof(flags[0]) * 4);
  19. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  20. ntdb = ntdb_open("run-35-convert.ntdb", flags[i]|MAYBE_NOSYNC,
  21. O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
  22. if (!ok1(ntdb))
  23. failtest_exit(exit_status());
  24. ntdb_close(ntdb);
  25. /* We can fail in log message formatting or open. That's OK */
  26. if (failtest_has_failed()) {
  27. failtest_exit(exit_status());
  28. }
  29. /* If we say NTDB_CONVERT, it must be converted */
  30. ntdb = ntdb_open("run-35-convert.ntdb",
  31. flags[i]|NTDB_CONVERT|MAYBE_NOSYNC,
  32. O_RDWR, 0600, &tap_log_attr);
  33. if (flags[i] & NTDB_CONVERT) {
  34. if (!ntdb)
  35. failtest_exit(exit_status());
  36. ok1(ntdb_get_flags(ntdb) & NTDB_CONVERT);
  37. ntdb_close(ntdb);
  38. } else {
  39. if (!ok1(!ntdb && errno == EIO))
  40. failtest_exit(exit_status());
  41. ok1(tap_log_messages == ++messages);
  42. if (!ok1(log_last && strstr(log_last, "NTDB_CONVERT")))
  43. failtest_exit(exit_status());
  44. }
  45. /* If don't say NTDB_CONVERT, it *may* be converted */
  46. ntdb = ntdb_open("run-35-convert.ntdb",
  47. (flags[i] & ~NTDB_CONVERT)|MAYBE_NOSYNC,
  48. O_RDWR, 0600, &tap_log_attr);
  49. if (!ntdb)
  50. failtest_exit(exit_status());
  51. ok1(ntdb_get_flags(ntdb) == (flags[i]|MAYBE_NOSYNC));
  52. ntdb_close(ntdb);
  53. }
  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. }