1 /* $NetBSD: t_sigtimedwait.c,v 1.2 2013/03/08 23:18:00 martin Exp $ */
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __RCSID("$NetBSD: t_sigtimedwait.c,v 1.2 2013/03/08 23:18:00 martin Exp $");
40 ATF_TC(sigtimedwait_all0timeout
);
42 ATF_TC_HEAD(sigtimedwait_all0timeout
, tc
)
44 atf_tc_set_md_var(tc
, "timeout", "10");
45 atf_tc_set_md_var(tc
, "descr", "Test for PR kern/47625: sigtimedwait"
46 " with a timeout value of all zero should return imediately");
49 ATF_TC_BODY(sigtimedwait_all0timeout
, tc
)
52 struct timespec ts
, before
, after
, len
;
59 clock_gettime(CLOCK_MONOTONIC
, &before
);
60 r
= sigtimedwait(&block
, &info
, &ts
);
61 clock_gettime(CLOCK_MONOTONIC
, &after
);
63 ATF_REQUIRE_ERRNO(EAGAIN
, errno
);
64 timespecsub(&after
, &before
, &len
);
65 ATF_REQUIRE(len
.tv_sec
< 1);
68 ATF_TC(sigtimedwait_NULL_timeout
);
70 ATF_TC_HEAD(sigtimedwait_NULL_timeout
, tc
)
72 atf_tc_set_md_var(tc
, "timeout", "10");
73 atf_tc_set_md_var(tc
, "descr", "Test sigtimedwait() without timeout");
76 ATF_TC_BODY(sigtimedwait_NULL_timeout
, tc
)
83 /* arrange for a SIGALRM signal in a few seconds */
84 memset(&it
, 0, sizeof it
);
85 it
.it_value
.tv_sec
= 5;
86 ATF_REQUIRE(setitimer(ITIMER_REAL
, &it
, NULL
) == 0);
88 /* wait without timeout */
90 sigaddset(&sig
, SIGALRM
);
91 r
= sigtimedwait(&sig
, &info
, NULL
);
92 ATF_REQUIRE(r
== SIGALRM
);
95 ATF_TC(sigtimedwait_small_timeout
);
97 ATF_TC_HEAD(sigtimedwait_small_timeout
, tc
)
99 atf_tc_set_md_var(tc
, "timeout", "15");
100 atf_tc_set_md_var(tc
, "descr", "Test sigtimedwait with a small "
104 ATF_TC_BODY(sigtimedwait_small_timeout
, tc
)
114 r
= sigtimedwait(&block
, &info
, &ts
);
115 ATF_REQUIRE(r
== -1);
116 ATF_REQUIRE_ERRNO(EAGAIN
, errno
);
121 ATF_TP_ADD_TC(tp
, sigtimedwait_all0timeout
);
122 ATF_TP_ADD_TC(tp
, sigtimedwait_NULL_timeout
);
123 ATF_TP_ADD_TC(tp
, sigtimedwait_small_timeout
);
125 return atf_no_error();