run-features.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "ntdb-source.h"
  2. #include "tap-interface.h"
  3. #include "logging.h"
  4. #include "helprun-external-agent.h"
  5. int main(int argc, char *argv[])
  6. {
  7. unsigned int i, j;
  8. struct ntdb_context *ntdb;
  9. int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
  10. NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
  11. NTDB_DATA key = { (unsigned char *)&j, sizeof(j) };
  12. NTDB_DATA data = { (unsigned char *)&j, sizeof(j) };
  13. plan_tests(sizeof(flags) / sizeof(flags[0]) * 8 + 1);
  14. for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
  15. uint64_t features;
  16. ntdb = ntdb_open("run-features.ntdb", flags[i]|MAYBE_NOSYNC,
  17. O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
  18. ok1(ntdb);
  19. if (!ntdb)
  20. continue;
  21. /* Put some stuff in there. */
  22. for (j = 0; j < 100; j++) {
  23. if (ntdb_store(ntdb, key, data, NTDB_REPLACE) != 0)
  24. fail("Storing in ntdb");
  25. }
  26. /* Mess with features fields in hdr. */
  27. features = (~NTDB_FEATURE_MASK ^ 1);
  28. ok1(ntdb_write_convert(ntdb, offsetof(struct ntdb_header,
  29. features_used),
  30. &features, sizeof(features)) == 0);
  31. ok1(ntdb_write_convert(ntdb, offsetof(struct ntdb_header,
  32. features_offered),
  33. &features, sizeof(features)) == 0);
  34. ntdb_close(ntdb);
  35. ntdb = ntdb_open("run-features.ntdb", flags[i]|MAYBE_NOSYNC,
  36. O_RDWR, 0, &tap_log_attr);
  37. ok1(ntdb);
  38. if (!ntdb)
  39. continue;
  40. /* Should not have changed features offered. */
  41. ok1(ntdb_read_convert(ntdb, offsetof(struct ntdb_header,
  42. features_offered),
  43. &features, sizeof(features)) == 0);
  44. ok1(features == (~NTDB_FEATURE_MASK ^ 1));
  45. /* Should have cleared unknown bits in features_used. */
  46. ok1(ntdb_read_convert(ntdb, offsetof(struct ntdb_header,
  47. features_used),
  48. &features, sizeof(features)) == 0);
  49. ok1(features == (1 & NTDB_FEATURE_MASK));
  50. ntdb_close(ntdb);
  51. }
  52. ok1(tap_log_messages == 0);
  53. return exit_status();
  54. }