]> git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/tst-sem13.c
nptl: Convert tst-sem5 & tst-sem13 to use libsupport
[thirdparty/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 #include <support/check.h>
8
9
10 static int
11 do_test (void)
12 {
13 union
14 {
15 sem_t s;
16 struct new_sem ns;
17 } u;
18
19 TEST_COMPARE (sem_init (&u.s, 0, 0), 0);
20
21 struct timespec ts = { 0, 1000000001 }; /* Invalid. */
22 errno = 0;
23 TEST_VERIFY_EXIT (sem_timedwait (&u.s, &ts) < 0);
24 TEST_COMPARE (errno, EINVAL);
25
26 #if __HAVE_64B_ATOMICS
27 unsigned int nwaiters = (u.ns.data >> SEM_NWAITERS_SHIFT);
28 #else
29 unsigned int nwaiters = u.ns.nwaiters;
30 #endif
31 TEST_COMPARE (nwaiters, 0);
32
33 ts.tv_sec = /* Invalid. */ -2;
34 ts.tv_nsec = 0;
35 errno = 0;
36 TEST_VERIFY_EXIT (sem_timedwait (&u.s, &ts) < 0);
37 TEST_COMPARE (errno, ETIMEDOUT);
38 #if __HAVE_64B_ATOMICS
39 nwaiters = (u.ns.data >> SEM_NWAITERS_SHIFT);
40 #else
41 nwaiters = u.ns.nwaiters;
42 #endif
43 TEST_COMPARE (nwaiters, 0);
44
45 return 0;
46 }
47
48 #include <support/test-driver.c>