6 #include <internaltypes.h>
7 #include <support/check.h>
9 /* A bogus clock value that tells run_test to use sem_timedwait rather than
11 #define CLOCK_USE_TIMEDWAIT (-1)
13 typedef int (*waitfn_t
)(sem_t
*, struct timespec
*);
16 do_test_wait (waitfn_t waitfn
, const char *fnname
)
24 printf ("do_test_wait: %s\n", fnname
);
26 TEST_COMPARE (sem_init (&u
.s
, 0, 0), 0);
28 struct timespec ts
= { 0, 1000000001 }; /* Invalid. */
30 TEST_VERIFY_EXIT (waitfn (&u
.s
, &ts
) < 0);
31 TEST_COMPARE (errno
, EINVAL
);
33 #if __HAVE_64B_ATOMICS
34 unsigned int nwaiters
= (u
.ns
.data
>> SEM_NWAITERS_SHIFT
);
36 unsigned int nwaiters
= u
.ns
.nwaiters
;
38 TEST_COMPARE (nwaiters
, 0);
40 ts
.tv_sec
= /* Invalid. */ -2;
43 TEST_VERIFY_EXIT (waitfn (&u
.s
, &ts
) < 0);
44 TEST_COMPARE (errno
, ETIMEDOUT
);
45 #if __HAVE_64B_ATOMICS
46 nwaiters
= (u
.ns
.data
>> SEM_NWAITERS_SHIFT
);
48 nwaiters
= u
.ns
.nwaiters
;
50 TEST_COMPARE (nwaiters
, 0);
53 int test_sem_timedwait (sem_t
*sem
, struct timespec
*ts
)
55 return sem_timedwait (sem
, ts
);
58 int test_sem_clockwait_monotonic (sem_t
*sem
, struct timespec
*ts
)
60 return sem_clockwait (sem
, CLOCK_MONOTONIC
, ts
);
63 int test_sem_clockwait_realtime (sem_t
*sem
, struct timespec
*ts
)
65 return sem_clockwait (sem
, CLOCK_REALTIME
, ts
);
68 static int do_test (void)
70 do_test_wait (&test_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)");
79 #include <support/test-driver.c>