run-seed.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "ntdb-source.h"
  2. #include "tap-interface.h"
  3. #include "logging.h"
  4. #include "helprun-external-agent.h"
  5. static int log_count = 0;
  6. /* Normally we get a log when setting random seed. */
  7. static void my_log_fn(struct ntdb_context *ntdb,
  8. enum ntdb_log_level level,
  9. enum NTDB_ERROR ecode,
  10. const char *message, void *priv)
  11. {
  12. log_count++;
  13. }
  14. static union ntdb_attribute log_attr = {
  15. .log = { .base = { .attr = NTDB_ATTRIBUTE_LOG },
  16. .fn = my_log_fn }
  17. };
  18. int main(int argc, char *argv[])
  19. {
  20. unsigned int i;
  21. struct ntdb_context *ntdb;
  22. union ntdb_attribute attr;
  23. int flags[] = { NTDB_INTERNAL, NTDB_DEFAULT, NTDB_NOMMAP,
  24. NTDB_INTERNAL|NTDB_CONVERT, NTDB_CONVERT,
  25. NTDB_NOMMAP|NTDB_CONVERT };
  26. attr.seed.base.attr = NTDB_ATTRIBUTE_SEED;
  27. attr.seed.base.next = &log_attr;
  28. attr.seed.seed = 42;
  29. plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 4 * 3);
  30. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  31. struct ntdb_header hdr;
  32. int fd;
  33. ntdb = ntdb_open("run-seed.ntdb", flags[i]|MAYBE_NOSYNC,
  34. O_RDWR|O_CREAT|O_TRUNC, 0600, &attr);
  35. ok1(ntdb);
  36. if (!ntdb)
  37. continue;
  38. ok1(ntdb_check(ntdb, NULL, NULL) == 0);
  39. ok1(ntdb->hash_seed == 42);
  40. ok1(log_count == 0);
  41. ntdb_close(ntdb);
  42. if (flags[i] & NTDB_INTERNAL)
  43. continue;
  44. fd = open("run-seed.ntdb", O_RDONLY);
  45. ok1(fd >= 0);
  46. ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
  47. if (flags[i] & NTDB_CONVERT)
  48. ok1(bswap_64(hdr.hash_seed) == 42);
  49. else
  50. ok1(hdr.hash_seed == 42);
  51. close(fd);
  52. }
  53. return exit_status();
  54. }