068d79e85e993b081a21450314f4c7fa3b728d74
[platform/upstream/glibc.git] / nptl / tst-sem13.c
1 #include <errno.h>
2 #include <semaphore.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <pthread.h>
6 #include <internaltypes.h>
7
8
9 static int
10 do_test (void)
11 {
12   union
13   {
14     sem_t s;
15     struct new_sem ns;
16   } u;
17
18   if (sem_init (&u.s, 0, 0) != 0)
19     {
20       puts ("sem_init failed");
21       return 1;
22     }
23
24   struct timespec ts = { 0, 1000000001 };       /* Invalid.  */
25   errno = 0;
26   if (sem_timedwait (&u.s, &ts) >= 0)
27     {
28       puts ("sem_timedwait did not fail");
29       return 1;
30     }
31   if (errno != EINVAL)
32     {
33       perror ("sem_timedwait did not fail with EINVAL");
34       return 1;
35     }
36   if (u.ns.nwaiters != 0)
37     {
38       printf ("sem_timedwait modified nwaiters: %ld\n", u.ns.nwaiters);
39       return 1;
40     }
41
42   ts.tv_sec = /* Invalid.  */ -2;
43   ts.tv_nsec = 0;
44   errno = 0;
45   if (sem_timedwait (&u.s, &ts) >= 0)
46     {
47       puts ("2nd sem_timedwait did not fail");
48       return 1;
49     }
50   if (errno != ETIMEDOUT)
51     {
52       perror ("2nd sem_timedwait did not fail with ETIMEDOUT");
53       return 1;
54     }
55   if (u.ns.nwaiters != 0)
56     {
57       printf ("2nd sem_timedwait modified nwaiters: %ld\n", u.ns.nwaiters);
58       return 1;
59     }
60
61   return 0;
62 }
63
64 #define TEST_FUNCTION do_test ()
65 #include "../test-skeleton.c"