run-access-count.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. int main(int argc, char *argv[])
  8. {
  9. struct jmap *map;
  10. unsigned long *value;
  11. int status;
  12. plan_tests(9);
  13. map = jmap_new();
  14. ok1(jmap_error(map) == NULL);
  15. ok1(jmap_add(map, 0, 1));
  16. /* add while holding value. */
  17. value = jmap_getval(map, 0);
  18. ok1(value);
  19. if (!fork()) {
  20. jmap_add(map, 1, 2);
  21. exit(0);
  22. } else {
  23. wait(&status);
  24. ok1(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT);
  25. }
  26. jmap_putval(map, &value);
  27. /* del while holding value. */
  28. value = jmap_getval(map, 0);
  29. ok1(value);
  30. if (!fork()) {
  31. jmap_del(map, 0);
  32. exit(0);
  33. } else {
  34. wait(&status);
  35. ok1(WIFSIGNALED(status) && WTERMSIG(status) == SIGABRT);
  36. }
  37. jmap_putval(map, &value);
  38. ok1(jmap_add(map, 0, 1));
  39. /* set while holding value ok. */
  40. value = jmap_getval(map, 0);
  41. ok1(value);
  42. if (!fork()) {
  43. jmap_set(map, 0, 2);
  44. exit(0);
  45. } else {
  46. wait(&status);
  47. ok1(WIFEXITED(status) && WEXITSTATUS(status) == 0);
  48. }
  49. jmap_putval(map, &value);
  50. /* FIXME: test jmap_nthval, jmap_firstval etc. */
  51. jmap_free(map);
  52. return exit_status();
  53. }