]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-sem13.c
x86: Add seperate non-temporal tunable for memset
[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>
7a773abf 7#include <support/check.h>
fa214705 8
6615f779
MC
9/* A bogus clock value that tells run_test to use sem_timedwait rather than
10 sem_clockwait. */
11#define CLOCK_USE_TIMEDWAIT (-1)
fa214705 12
6615f779
MC
13typedef int (*waitfn_t)(sem_t *, struct timespec *);
14
15static void
16do_test_wait (waitfn_t waitfn, const char *fnname)
fa214705
UD
17{
18 union
19 {
20 sem_t s;
21 struct new_sem ns;
22 } u;
23
6615f779
MC
24 printf ("do_test_wait: %s\n", fnname);
25
7a773abf 26 TEST_COMPARE (sem_init (&u.s, 0, 0), 0);
fa214705
UD
27
28 struct timespec ts = { 0, 1000000001 }; /* Invalid. */
29 errno = 0;
6615f779 30 TEST_VERIFY_EXIT (waitfn (&u.s, &ts) < 0);
7a773abf
MC
31 TEST_COMPARE (errno, EINVAL);
32
042e1521
CD
33#if __HAVE_64B_ATOMICS
34 unsigned int nwaiters = (u.ns.data >> SEM_NWAITERS_SHIFT);
35#else
36 unsigned int nwaiters = u.ns.nwaiters;
37#endif
7a773abf 38 TEST_COMPARE (nwaiters, 0);
48aff776
TS
39
40 ts.tv_sec = /* Invalid. */ -2;
41 ts.tv_nsec = 0;
42 errno = 0;
6615f779 43 TEST_VERIFY_EXIT (waitfn (&u.s, &ts) < 0);
7a773abf 44 TEST_COMPARE (errno, ETIMEDOUT);
042e1521
CD
45#if __HAVE_64B_ATOMICS
46 nwaiters = (u.ns.data >> SEM_NWAITERS_SHIFT);
47#else
48 nwaiters = u.ns.nwaiters;
49#endif
7a773abf 50 TEST_COMPARE (nwaiters, 0);
6615f779 51}
fa214705 52
6615f779
MC
53int test_sem_timedwait (sem_t *sem, struct timespec *ts)
54{
55 return sem_timedwait (sem, ts);
56}
57
58int test_sem_clockwait_monotonic (sem_t *sem, struct timespec *ts)
59{
60 return sem_clockwait (sem, CLOCK_MONOTONIC, ts);
61}
62
63int test_sem_clockwait_realtime (sem_t *sem, struct timespec *ts)
64{
65 return sem_clockwait (sem, CLOCK_REALTIME, ts);
66}
67
68static int do_test (void)
69{
70 do_test_wait (&test_sem_timedwait,
71 "sem_timedwait");
72 do_test_wait (&test_sem_clockwait_monotonic,
73 "sem_clockwait(monotonic)");
74 do_test_wait (&test_sem_clockwait_realtime,
75 "sem_clockwait(realtime)");
fa214705
UD
76 return 0;
77}
78
7a773abf 79#include <support/test-driver.c>