t_sleep.c (272458) | t_sleep.c (273529) |
---|---|
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 | 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 |
|
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 *); | 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__ |
|
81int do_poll(struct timespec *, struct timespec *); | 87int do_poll(struct timespec *, struct timespec *); |
88#endif |
|
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 | 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__ |
|
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} | 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 |
|
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 | 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__ |
|
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} | 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 |
|
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); | 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__ |
|
332 ATF_TP_ADD_TC(tp, poll); | 344 ATF_TP_ADD_TC(tp, poll); |
345#endif |
|
333 ATF_TP_ADD_TC(tp, sleep); 334 ATF_TP_ADD_TC(tp, kevent); 335 336 return atf_no_error(); 337} | 346 ATF_TP_ADD_TC(tp, sleep); 347 ATF_TP_ADD_TC(tp, kevent); 348 349 return atf_no_error(); 350} |