FreeBSD regtest: remove test for version 13+ syscalls
[valgrind.git] / memcheck / tests / freebsd / eventfd2.c
blob18dfff332f0376db48b11728ef52742f24e77d13
1 /* EFD_SEMAPHORE */
3 #include <sys/eventfd.h>
4 #include <sys/wait.h>
5 #include <inttypes.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <unistd.h>
10 static void xsem_wait(int fd)
12 eventfd_t cntr;
14 if (eventfd_read(fd, &cntr) != 0) {
15 perror("reading eventfd");
16 exit(1);
19 fprintf(stderr, "fd %d wait completed: count=%" PRIu64 "\n",
20 fd, cntr);
23 static void xsem_post(int fd, int count)
25 eventfd_t cntr = count;
27 if (eventfd_write(fd, cntr) != 0) {
28 perror("writing eventfd");
29 exit(1);
33 static void sem_player(int fd1, int fd2)
35 /* these printfs did contain the pid
36 * so "[%u] ... ", getpid()
37 * not good for regresson tests
38 * (also xsem_wait above)
40 fprintf(stderr, "fd %d posting 1\n", fd1);
41 xsem_post(fd1, 1);
43 fprintf(stderr, "fd %d waiting\n", fd2);
44 xsem_wait(fd2);
46 fprintf(stderr, "fd %d posting 1\n", fd1);
47 xsem_post(fd1, 1);
49 fprintf(stderr, "fd %d waiting\n", fd2);
50 xsem_wait(fd2);
52 fprintf(stderr, "fd %d posting 5\n", fd1);
53 xsem_post(fd1, 5);
55 fprintf(stderr, "fd %d waiting 5 times\n", fd2);
56 xsem_wait(fd2);
57 xsem_wait(fd2);
58 xsem_wait(fd2);
59 xsem_wait(fd2);
60 xsem_wait(fd2);
63 static void usage(char const *prg)
65 fprintf(stderr, "use: %s [-h]\n", prg);
68 int main(int argc, char **argv)
70 int c, fd1, fd2, status;
71 pid_t cpid_poster, cpid_waiter;
73 while ((c = getopt(argc, argv, "h")) != -1) {
75 switch (c) {
76 default:
77 usage(argv[0]);
78 return 1;
82 if ((fd1 = eventfd(0, EFD_SEMAPHORE)) == -1 ||
83 (fd2 = eventfd(0, EFD_SEMAPHORE)) == -1) {
84 perror("eventfd");
85 return 1;
87 if ((cpid_poster = fork()) == 0) {
88 sem_player(fd1, fd2);
89 exit(0);
91 sleep(1);
92 if ((cpid_waiter = fork()) == 0) {
93 sem_player(fd2, fd1);
94 exit(0);
96 waitpid(cpid_poster, &status, 0);
97 waitpid(cpid_waiter, &status, 0);
99 exit(0);