1 /* unnamed semaphore sanity check */
9 #define T(f) if(f) t_error(#f" failed: %s\n", strerror(errno))
10 #define T2(r,f) if((r=(f))) t_error(#f" failed: %s\n", strerror(r))
12 static void *start(void *arg)
16 T(clock_gettime(CLOCK_REALTIME, &ts));
19 T(sem_timedwait(s+1, &ts));
23 static void many_waiters()
31 T(sem_init(s+1, 0, 0));
32 T2(r,pthread_create(t, 0, start, s));
33 T2(r,pthread_create(t+1, 0, start, s));
34 T2(r,pthread_create(t+2, 0, start, s));
38 T(sem_getvalue(s, &r));
40 t_error("sem value should be 0, got %d\n", r);
44 T2(r,pthread_join(t[0],&p));
45 T2(r,pthread_join(t[1],&p));
46 T2(r,pthread_join(t[2],&p));
47 T(sem_getvalue(s+1, &r));
49 t_error("sem value should be 0, got %d\n", r);
54 static void single_thread()
60 T(sem_init(&s, 0, 1));
62 T(sem_getvalue(&s, &r));
64 t_error("sem value should be 0, got %d\n", r);
65 if (sem_trywait(&s) != -1 || errno != EAGAIN)
66 t_error("sem_trywait should fail with EAGAIN, got %s\n", strerror(errno));
68 T(clock_gettime(CLOCK_REALTIME, &ts));
69 if (sem_timedwait(&s, &ts)!=-1 || errno != ETIMEDOUT)
70 t_error("sem_timedwait should fail with ETIMEDOUT, got %s\n", strerror(errno));