run-access-count.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Test our access counting failures. */
  2. #include <ccan/jmap/jmap.c>
  3. #include <ccan/tap/tap.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6. #include <unistd.h>
  7. struct map {
  8. JMAP_MEMBERS(unsigned long, unsigned long);
  9. };
  10. int main(int argc, char *argv[])
  11. {
  12. struct map *map;
  13. unsigned long *value;
  14. int status;
  15. plan_tests(9);
  16. map = jmap_new(struct map);
  17. ok1(jmap_error(map) == NULL);
  18. ok1(jmap_add(map, 0, 1));
  19. /* add while holding value. */
  20. value = jmap_getval(map, 0);
  21. ok1(value);
  22. if (!fork()) {
  23. jmap_add(map, 1, 2);
  24. exit(0);
  25. } else {
  26. wait(&status);
  27. ok1(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT);
  28. }
  29. jmap_putval(map, &value);
  30. /* del while holding value. */
  31. value = jmap_getval(map, 0);
  32. ok1(value);
  33. if (!fork()) {
  34. jmap_del(map, 0);
  35. exit(0);
  36. } else {
  37. wait(&status);
  38. ok1(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT);
  39. }
  40. jmap_putval(map, &value);
  41. ok1(jmap_add(map, 0, 1));
  42. /* set while holding value ok. */
  43. value = jmap_getval(map, 0);
  44. ok1(value);
  45. if (!fork()) {
  46. jmap_set(map, 0, 2);
  47. exit(0);
  48. } else {
  49. wait(&status);
  50. ok1(WIFEXITED(status) && WEXITSTATUS(status) == 0);
  51. }
  52. jmap_putval(map, &value);
  53. /* FIXME: test jmap_nthval, jmap_firstval etc. */
  54. jmap_free(map);
  55. return exit_status();
  56. }