t_sigtimedwait.c revision 1.2.4.2 1 1.2.4.2 tls /* $NetBSD: t_sigtimedwait.c,v 1.2.4.2 2013/06/23 06:28:56 tls Exp $ */
2 1.2.4.2 tls
3 1.2.4.2 tls /*-
4 1.2.4.2 tls * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 1.2.4.2 tls * All rights reserved.
6 1.2.4.2 tls *
7 1.2.4.2 tls * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 tls * modification, are permitted provided that the following conditions
9 1.2.4.2 tls * are met:
10 1.2.4.2 tls * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 tls * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 tls * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 tls * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 tls * documentation and/or other materials provided with the distribution.
15 1.2.4.2 tls *
16 1.2.4.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 1.2.4.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 1.2.4.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.2.4.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 1.2.4.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.2.4.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.2.4.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.2.4.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.2.4.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.2.4.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.2.4.2 tls * POSSIBILITY OF SUCH DAMAGE.
27 1.2.4.2 tls */
28 1.2.4.2 tls
29 1.2.4.2 tls #include <sys/cdefs.h>
30 1.2.4.2 tls __RCSID("$NetBSD: t_sigtimedwait.c,v 1.2.4.2 2013/06/23 06:28:56 tls Exp $");
31 1.2.4.2 tls
32 1.2.4.2 tls #include <sys/time.h>
33 1.2.4.2 tls #include <errno.h>
34 1.2.4.2 tls #include <signal.h>
35 1.2.4.2 tls #include <stdio.h>
36 1.2.4.2 tls #include <string.h>
37 1.2.4.2 tls #include <atf-c.h>
38 1.2.4.2 tls
39 1.2.4.2 tls
40 1.2.4.2 tls ATF_TC(sigtimedwait_all0timeout);
41 1.2.4.2 tls
42 1.2.4.2 tls ATF_TC_HEAD(sigtimedwait_all0timeout, tc)
43 1.2.4.2 tls {
44 1.2.4.2 tls atf_tc_set_md_var(tc, "timeout", "10");
45 1.2.4.2 tls atf_tc_set_md_var(tc, "descr", "Test for PR kern/47625: sigtimedwait"
46 1.2.4.2 tls " with a timeout value of all zero should return imediately");
47 1.2.4.2 tls }
48 1.2.4.2 tls
49 1.2.4.2 tls ATF_TC_BODY(sigtimedwait_all0timeout, tc)
50 1.2.4.2 tls {
51 1.2.4.2 tls sigset_t block;
52 1.2.4.2 tls struct timespec ts, before, after, len;
53 1.2.4.2 tls siginfo_t info;
54 1.2.4.2 tls int r;
55 1.2.4.2 tls
56 1.2.4.2 tls sigemptyset(&block);
57 1.2.4.2 tls ts.tv_sec = 0;
58 1.2.4.2 tls ts.tv_nsec = 0;
59 1.2.4.2 tls clock_gettime(CLOCK_MONOTONIC, &before);
60 1.2.4.2 tls r = sigtimedwait(&block, &info, &ts);
61 1.2.4.2 tls clock_gettime(CLOCK_MONOTONIC, &after);
62 1.2.4.2 tls ATF_REQUIRE(r == -1);
63 1.2.4.2 tls ATF_REQUIRE_ERRNO(EAGAIN, errno);
64 1.2.4.2 tls timespecsub(&after, &before, &len);
65 1.2.4.2 tls ATF_REQUIRE(len.tv_sec < 1);
66 1.2.4.2 tls }
67 1.2.4.2 tls
68 1.2.4.2 tls ATF_TC(sigtimedwait_NULL_timeout);
69 1.2.4.2 tls
70 1.2.4.2 tls ATF_TC_HEAD(sigtimedwait_NULL_timeout, tc)
71 1.2.4.2 tls {
72 1.2.4.2 tls atf_tc_set_md_var(tc, "timeout", "10");
73 1.2.4.2 tls atf_tc_set_md_var(tc, "descr", "Test sigtimedwait() without timeout");
74 1.2.4.2 tls }
75 1.2.4.2 tls
76 1.2.4.2 tls ATF_TC_BODY(sigtimedwait_NULL_timeout, tc)
77 1.2.4.2 tls {
78 1.2.4.2 tls sigset_t sig;
79 1.2.4.2 tls siginfo_t info;
80 1.2.4.2 tls struct itimerval it;
81 1.2.4.2 tls int r;
82 1.2.4.2 tls
83 1.2.4.2 tls /* arrange for a SIGALRM signal in a few seconds */
84 1.2.4.2 tls memset(&it, 0, sizeof it);
85 1.2.4.2 tls it.it_value.tv_sec = 5;
86 1.2.4.2 tls ATF_REQUIRE(setitimer(ITIMER_REAL, &it, NULL) == 0);
87 1.2.4.2 tls
88 1.2.4.2 tls /* wait without timeout */
89 1.2.4.2 tls sigemptyset(&sig);
90 1.2.4.2 tls sigaddset(&sig, SIGALRM);
91 1.2.4.2 tls r = sigtimedwait(&sig, &info, NULL);
92 1.2.4.2 tls ATF_REQUIRE(r == SIGALRM);
93 1.2.4.2 tls }
94 1.2.4.2 tls
95 1.2.4.2 tls ATF_TC(sigtimedwait_small_timeout);
96 1.2.4.2 tls
97 1.2.4.2 tls ATF_TC_HEAD(sigtimedwait_small_timeout, tc)
98 1.2.4.2 tls {
99 1.2.4.2 tls atf_tc_set_md_var(tc, "timeout", "15");
100 1.2.4.2 tls atf_tc_set_md_var(tc, "descr", "Test sigtimedwait with a small "
101 1.2.4.2 tls "timeout");
102 1.2.4.2 tls }
103 1.2.4.2 tls
104 1.2.4.2 tls ATF_TC_BODY(sigtimedwait_small_timeout, tc)
105 1.2.4.2 tls {
106 1.2.4.2 tls sigset_t block;
107 1.2.4.2 tls struct timespec ts;
108 1.2.4.2 tls siginfo_t info;
109 1.2.4.2 tls int r;
110 1.2.4.2 tls
111 1.2.4.2 tls sigemptyset(&block);
112 1.2.4.2 tls ts.tv_sec = 5;
113 1.2.4.2 tls ts.tv_nsec = 0;
114 1.2.4.2 tls r = sigtimedwait(&block, &info, &ts);
115 1.2.4.2 tls ATF_REQUIRE(r == -1);
116 1.2.4.2 tls ATF_REQUIRE_ERRNO(EAGAIN, errno);
117 1.2.4.2 tls }
118 1.2.4.2 tls
119 1.2.4.2 tls ATF_TP_ADD_TCS(tp)
120 1.2.4.2 tls {
121 1.2.4.2 tls ATF_TP_ADD_TC(tp, sigtimedwait_all0timeout);
122 1.2.4.2 tls ATF_TP_ADD_TC(tp, sigtimedwait_NULL_timeout);
123 1.2.4.2 tls ATF_TP_ADD_TC(tp, sigtimedwait_small_timeout);
124 1.2.4.2 tls
125 1.2.4.2 tls return atf_no_error();
126 1.2.4.2 tls }
127