Deleted Added
sdiff udiff text old ( 272458 ) new ( 273529 )
full compact
1/* $NetBSD: t_sleep.c,v 1.8 2014/07/15 14:56:34 gson Exp $ */
2
3/*-
4 * Copyright (c) 2006 Frank Kardel
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 35 unchanged lines hidden (view full) ---

44#define BILLION 1000000000LL /* nano-seconds per second */
45#define MILLION 1000000LL /* nano-seconds per milli-second */
46
47#define ALARM 6 /* SIGALRM after this many seconds */
48#define MAXSLEEP 22 /* Maximum delay in seconds */
49#define KEVNT_TIMEOUT 10300 /* measured in milli-seconds */
50#define FUZZ (40 * MILLION) /* scheduling fuzz accepted - 40 ms */
51
52/*
53 * Timer notes
54 *
55 * Most tests use FUZZ as their initial delay value, but 'sleep'
56 * starts at 1sec (since it cannot handle sub-second intervals).
57 * Subsequent passes double the previous interval, up to MAXSLEEP.
58 *
59 * The current values result in 5 passes for the 'sleep' test (at 1,

--- 13 unchanged lines hidden (view full) ---

73 * some timers.
74 */
75
76static volatile int sig;
77
78int sleeptest(int (*)(struct timespec *, struct timespec *), bool, bool);
79int do_nanosleep(struct timespec *, struct timespec *);
80int do_select(struct timespec *, struct timespec *);
81int do_poll(struct timespec *, struct timespec *);
82int do_sleep(struct timespec *, struct timespec *);
83int do_kevent(struct timespec *, struct timespec *);
84void sigalrm(int);
85
86void
87sigalrm(int s)
88{
89

--- 21 unchanged lines hidden (view full) ---

111 TIMESPEC_TO_TIMEVAL(&tv, delay);
112 if (select(0, NULL, NULL, NULL, &tv) == -1)
113 ret = (errno == EINTR ? 0 : errno);
114 else
115 ret = 0;
116 return ret;
117}
118
119int
120do_poll(struct timespec *delay, struct timespec *remain)
121{
122 int ret;
123 struct timeval tv;
124
125 TIMESPEC_TO_TIMEVAL(&tv, delay);
126 if (pollts(NULL, 0, delay, NULL) == -1)
127 ret = (errno == EINTR ? 0 : errno);
128 else
129 ret = 0;
130 return ret;
131}
132
133int
134do_sleep(struct timespec *delay, struct timespec *remain)
135{
136 struct timeval tv;
137
138 TIMESPEC_TO_TIMEVAL(&tv, delay);
139 remain->tv_sec = sleep(delay->tv_sec);

--- 65 unchanged lines hidden (view full) ---

205}
206
207ATF_TC_BODY(select, tc)
208{
209
210 sleeptest(do_select, true, true);
211}
212
213ATF_TC(poll);
214ATF_TC_HEAD(poll, tc)
215{
216
217 atf_tc_set_md_var(tc, "descr", "Test poll(2) timing");
218 atf_tc_set_md_var(tc, "timeout", "65");
219}
220
221ATF_TC_BODY(poll, tc)
222{
223
224 sleeptest(do_poll, true, true);
225}
226
227ATF_TC(sleep);
228ATF_TC_HEAD(sleep, tc)
229{
230
231 atf_tc_set_md_var(tc, "descr", "Test sleep(3) timing");
232 atf_tc_set_md_var(tc, "timeout", "65");
233}

--- 90 unchanged lines hidden (view full) ---

324
325 atf_tc_pass();
326}
327
328ATF_TP_ADD_TCS(tp)
329{
330 ATF_TP_ADD_TC(tp, nanosleep);
331 ATF_TP_ADD_TC(tp, select);
332 ATF_TP_ADD_TC(tp, poll);
333 ATF_TP_ADD_TC(tp, sleep);
334 ATF_TP_ADD_TC(tp, kevent);
335
336 return atf_no_error();
337}