testcases: Attempt to integrate POSIX IPC tests to dfregress(8)
[dragonfly.git] / test / testcases / posixipc / timedwait_unlocked / timedwait_unlocked.c
1 #include <common.h>
2
3 int
4 main(void) {
5         sem_t id;
6         u_int elapsed;
7
8         if (sem_init(&id, 0, 1) < 0) {
9                 perror("sem_init");
10                 return 1;
11         }
12
13         /* This should succeed right away and set the value to 0. */
14         if (timedwait(&id, 5000, &elapsed, 0) < 0) {
15                 sem_destroy(&id);
16                 return 1;
17         }
18         if (!ELAPSED(elapsed, 0)) {
19                 fprintf(stderr, "sem_timedwait() of unlocked sem took %ums",
20                     elapsed);
21                 sem_destroy(&id);
22                 return 1;
23         }
24         if (checkvalue(&id, 0) < 0) {
25                 sem_destroy(&id);
26                 return 1;
27         }
28
29         if (sem_destroy(&id) < 0) {
30                 perror("sem_destroy");
31                 return 1;
32         }
33         return 0;
34 }