hurd: Fix building libio/tst-memstream3.c
[glibc.git] / nptl / tst-sem13.c
blob1560e91443c9c0d2bb9f25442c277354bc16f9a0
1 #include <errno.h>
2 #include <semaphore.h>
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <pthread.h>
6 #include <internaltypes.h>
9 static int
10 do_test (void)
12 union
14 sem_t s;
15 struct new_sem ns;
16 } u;
18 if (sem_init (&u.s, 0, 0) != 0)
20 puts ("sem_init failed");
21 return 1;
24 struct timespec ts = { 0, 1000000001 }; /* Invalid. */
25 errno = 0;
26 if (sem_timedwait (&u.s, &ts) >= 0)
28 puts ("sem_timedwait did not fail");
29 return 1;
31 if (errno != EINVAL)
33 perror ("sem_timedwait did not fail with EINVAL");
34 return 1;
36 #if __HAVE_64B_ATOMICS
37 unsigned int nwaiters = (u.ns.data >> SEM_NWAITERS_SHIFT);
38 #else
39 unsigned int nwaiters = u.ns.nwaiters;
40 #endif
41 if (nwaiters != 0)
43 printf ("sem_timedwait modified nwaiters: %d\n", nwaiters);
44 return 1;
47 ts.tv_sec = /* Invalid. */ -2;
48 ts.tv_nsec = 0;
49 errno = 0;
50 if (sem_timedwait (&u.s, &ts) >= 0)
52 puts ("2nd sem_timedwait did not fail");
53 return 1;
55 if (errno != ETIMEDOUT)
57 perror ("2nd sem_timedwait did not fail with ETIMEDOUT");
58 return 1;
60 #if __HAVE_64B_ATOMICS
61 nwaiters = (u.ns.data >> SEM_NWAITERS_SHIFT);
62 #else
63 nwaiters = u.ns.nwaiters;
64 #endif
65 if (nwaiters != 0)
67 printf ("2nd sem_timedwait modified nwaiters: %d\n", nwaiters);
68 return 1;
71 return 0;
74 #define TEST_FUNCTION do_test ()
75 #include "../test-skeleton.c"