]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-sem13.c
S390: Increase function alignment to 16 bytes.
[thirdparty/glibc.git] / nptl / tst-sem13.c
CommitLineData
fa214705
UD
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
9static int
10do_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 {
48aff776 33 perror ("sem_timedwait did not fail with EINVAL");
fa214705
UD
34 return 1;
35 }
042e1521
CD
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)
fa214705 42 {
042e1521 43 printf ("sem_timedwait modified nwaiters: %d\n", nwaiters);
48aff776
TS
44 return 1;
45 }
46
47 ts.tv_sec = /* Invalid. */ -2;
48 ts.tv_nsec = 0;
49 errno = 0;
50 if (sem_timedwait (&u.s, &ts) >= 0)
51 {
52 puts ("2nd sem_timedwait did not fail");
53 return 1;
54 }
55 if (errno != ETIMEDOUT)
56 {
57 perror ("2nd sem_timedwait did not fail with ETIMEDOUT");
58 return 1;
59 }
042e1521
CD
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)
48aff776 66 {
042e1521 67 printf ("2nd sem_timedwait modified nwaiters: %d\n", nwaiters);
fa214705
UD
68 return 1;
69 }
70
71 return 0;
72}
73
74#define TEST_FUNCTION do_test ()
75#include "../test-skeleton.c"