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#ifdef __FreeBSD__
53#include <sys/time.h>
54#include <inttypes.h>
55#endif
56
57/*
58 * Timer notes
59 *
60 * Most tests use FUZZ as their initial delay value, but 'sleep'
61 * starts at 1sec (since it cannot handle sub-second intervals).
62 * Subsequent passes double the previous interval, up to MAXSLEEP.
63 *
64 * The current values result in 5 passes for the 'sleep' test (at 1,

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

78 * some timers.
79 */
80
81static volatile int sig;
82
83int sleeptest(int (*)(struct timespec *, struct timespec *), bool, bool);
84int do_nanosleep(struct timespec *, struct timespec *);
85int do_select(struct timespec *, struct timespec *);
86#ifdef __NetBSD__
87int do_poll(struct timespec *, struct timespec *);
88#endif
89int do_sleep(struct timespec *, struct timespec *);
90int do_kevent(struct timespec *, struct timespec *);
91void sigalrm(int);
92
93void
94sigalrm(int s)
95{
96

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

118 TIMESPEC_TO_TIMEVAL(&tv, delay);
119 if (select(0, NULL, NULL, NULL, &tv) == -1)
120 ret = (errno == EINTR ? 0 : errno);
121 else
122 ret = 0;
123 return ret;
124}
125
126#ifdef __NetBSD__
127int
128do_poll(struct timespec *delay, struct timespec *remain)
129{
130 int ret;
131 struct timeval tv;
132
133 TIMESPEC_TO_TIMEVAL(&tv, delay);
134 if (pollts(NULL, 0, delay, NULL) == -1)
135 ret = (errno == EINTR ? 0 : errno);
136 else
137 ret = 0;
138 return ret;
139}
140#endif
141
142int
143do_sleep(struct timespec *delay, struct timespec *remain)
144{
145 struct timeval tv;
146
147 TIMESPEC_TO_TIMEVAL(&tv, delay);
148 remain->tv_sec = sleep(delay->tv_sec);

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

214}
215
216ATF_TC_BODY(select, tc)
217{
218
219 sleeptest(do_select, true, true);
220}
221
222#ifdef __NetBSD__
223ATF_TC(poll);
224ATF_TC_HEAD(poll, tc)
225{
226
227 atf_tc_set_md_var(tc, "descr", "Test poll(2) timing");
228 atf_tc_set_md_var(tc, "timeout", "65");
229}
230
231ATF_TC_BODY(poll, tc)
232{
233
234 sleeptest(do_poll, true, true);
235}
236#endif
237
238ATF_TC(sleep);
239ATF_TC_HEAD(sleep, tc)
240{
241
242 atf_tc_set_md_var(tc, "descr", "Test sleep(3) timing");
243 atf_tc_set_md_var(tc, "timeout", "65");
244}

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

335
336 atf_tc_pass();
337}
338
339ATF_TP_ADD_TCS(tp)
340{
341 ATF_TP_ADD_TC(tp, nanosleep);
342 ATF_TP_ADD_TC(tp, select);
343#ifdef __NetBSD__
344 ATF_TP_ADD_TC(tp, poll);
345#endif
346 ATF_TP_ADD_TC(tp, sleep);
347 ATF_TP_ADD_TC(tp, kevent);
348
349 return atf_no_error();
350}