summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/sys/t_getitimer.c
diff options
context:
space:
mode:
authorbluhm <>2019-11-19 19:57:04 +0000
committerbluhm <>2019-11-19 19:57:04 +0000
commit9185f840eda265016178aeb0dcdba964f8f6f3e2 (patch)
treeda100b3712514c566fe948116f7926ad7f725401 /src/regress/lib/libc/sys/t_getitimer.c
parent6a6fe688152b422f3d65c970dad56e7d9d28b1ee (diff)
downloadopenbsd-9185f840eda265016178aeb0dcdba964f8f6f3e2.tar.gz
openbsd-9185f840eda265016178aeb0dcdba964f8f6f3e2.tar.bz2
openbsd-9185f840eda265016178aeb0dcdba964f8f6f3e2.zip
Import NetBSD system call regression tests. They were written with
ATF (Automated Testing Framework), so we use a small wrapper to map it to our bsd.regress.mk framework. Only half of the 80 NetBSD tests have been taken, the others need more work to adapt. Of them 34 syscall tests pass. Moritz Buhl ported the tests to OpenBSD.
Diffstat (limited to 'src/regress/lib/libc/sys/t_getitimer.c')
-rw-r--r--src/regress/lib/libc/sys/t_getitimer.c215
1 files changed, 215 insertions, 0 deletions
diff --git a/src/regress/lib/libc/sys/t_getitimer.c b/src/regress/lib/libc/sys/t_getitimer.c
new file mode 100644
index 0000000000..b6cc4102bb
--- /dev/null
+++ b/src/regress/lib/libc/sys/t_getitimer.c
@@ -0,0 +1,215 @@
1/* $OpenBSD: t_getitimer.c,v 1.1.1.1 2019/11/19 19:57:03 bluhm Exp $ */
2/* $NetBSD: t_getitimer.c,v 1.2 2012/03/22 18:20:46 christos Exp $ */
3
4/*-
5 * Copyright (c) 2011 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Jukka Ruohonen.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include "macros.h"
34
35#include <sys/cdefs.h>
36__RCSID("$NetBSD: t_getitimer.c,v 1.2 2012/03/22 18:20:46 christos Exp $");
37
38#include <sys/time.h>
39
40#include "atf-c.h"
41#include <errno.h>
42#include <limits.h>
43#include <signal.h>
44#include <string.h>
45#include <unistd.h>
46
47static bool fail;
48static void sighandler(int);
49
50static void
51sighandler(int signo)
52{
53
54 if (signo == SIGALRM || signo == SIGVTALRM)
55 fail = false;
56}
57
58ATF_TC(getitimer_empty);
59ATF_TC_HEAD(getitimer_empty, tc)
60{
61 atf_tc_set_md_var(tc, "descr", "getitimer(2) before setitimer(2)");
62}
63
64ATF_TC_BODY(getitimer_empty, tc)
65{
66 struct itimerval it;
67
68 /*
69 * Verify that the passed structure remains
70 * empty after calling getitimer(2) but before
71 * actually arming the timer with setitimer(2).
72 */
73 (void)memset(&it, 0, sizeof(struct itimerval));
74
75 ATF_REQUIRE(getitimer(ITIMER_REAL, &it) == 0);
76
77 if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
78 goto fail;
79
80 ATF_REQUIRE(getitimer(ITIMER_VIRTUAL, &it) == 0);
81
82 if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
83 goto fail;
84
85 ATF_REQUIRE(getitimer(ITIMER_PROF, &it) == 0);
86
87 if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
88 goto fail;
89
90 return;
91
92fail:
93 atf_tc_fail("getitimer(2) modfied the timer before it was armed");
94}
95
96ATF_TC(getitimer_err);
97ATF_TC_HEAD(getitimer_err, tc)
98{
99 atf_tc_set_md_var(tc, "descr", "Test errors from getitimer(2)");
100}
101
102ATF_TC_BODY(getitimer_err, tc)
103{
104 struct itimerval it;
105
106 errno = 0;
107 ATF_REQUIRE_ERRNO(EINVAL, getitimer(-1, &it) == -1);
108
109 errno = 0;
110 ATF_REQUIRE_ERRNO(EINVAL, getitimer(INT_MAX, &it) == -1);
111
112 errno = 0;
113 ATF_REQUIRE_ERRNO(EFAULT, getitimer(ITIMER_REAL, (void *)-1) == -1);
114}
115
116ATF_TC(setitimer_basic);
117ATF_TC_HEAD(setitimer_basic, tc)
118{
119 atf_tc_set_md_var(tc, "descr", "A basic test of setitimer(2)");
120}
121
122ATF_TC_BODY(setitimer_basic, tc)
123{
124 struct itimerval it;
125
126 it.it_value.tv_sec = 0;
127 it.it_value.tv_usec = 100;
128
129 it.it_interval.tv_sec = 0;
130 it.it_interval.tv_usec = 0;
131
132 fail = true;
133
134 ATF_REQUIRE(signal(SIGALRM, sighandler) != SIG_ERR);
135 ATF_REQUIRE(setitimer(ITIMER_REAL, &it, NULL) == 0);
136
137 /*
138 * Although the interaction between
139 * setitimer(2) and sleep(3) can be
140 * unspecified, it is assumed that one
141 * second suspension will be enough for
142 * the timer to fire.
143 */
144 (void)sleep(1);
145
146 if (fail != false)
147 atf_tc_fail("timer did not fire");
148}
149
150ATF_TC(setitimer_err);
151ATF_TC_HEAD(setitimer_err, tc)
152{
153 atf_tc_set_md_var(tc, "descr", "Test errors from setitimer(2)"
154 " (PR standards/44927)");
155}
156
157ATF_TC_BODY(setitimer_err, tc)
158{
159 struct itimerval it, ot;
160
161 errno = 0;
162 ATF_REQUIRE_ERRNO(EINVAL, setitimer(-1, &it, &ot) == -1);
163
164 errno = 0;
165 ATF_REQUIRE_ERRNO(EINVAL, setitimer(INT_MAX, &it, &ot) == -1);
166
167 errno = 0;
168 ATF_REQUIRE_ERRNO(EFAULT, setitimer(ITIMER_REAL,(void*)-1, &ot) == -1);
169}
170
171ATF_TC(setitimer_old);
172ATF_TC_HEAD(setitimer_old, tc)
173{
174 atf_tc_set_md_var(tc, "descr", "Test old values from setitimer(2)");
175}
176
177ATF_TC_BODY(setitimer_old, tc)
178{
179 struct itimerval it, ot;
180
181 /*
182 * Make two calls; the second one
183 * should store the old values.
184 */
185 it.it_value.tv_sec = 4;
186 it.it_value.tv_usec = 3;
187
188 it.it_interval.tv_sec = 0;
189 it.it_interval.tv_usec = 0;
190
191 ATF_REQUIRE(setitimer(ITIMER_REAL, &it, &ot) == 0);
192
193 it.it_value.tv_sec = 2;
194 it.it_value.tv_usec = 1;
195
196 it.it_interval.tv_sec = 0;
197 it.it_interval.tv_usec = 0;
198
199 ATF_REQUIRE(setitimer(ITIMER_REAL, &it, &ot) == 0);
200
201 if (ot.it_value.tv_sec != 4 || ot.it_value.tv_usec != 3)
202 atf_tc_fail("setitimer(2) did not store old values");
203}
204
205ATF_TP_ADD_TCS(tp)
206{
207
208 ATF_TP_ADD_TC(tp, getitimer_empty);
209 ATF_TP_ADD_TC(tp, getitimer_err);
210 ATF_TP_ADD_TC(tp, setitimer_basic);
211 ATF_TP_ADD_TC(tp, setitimer_err);
212 ATF_TP_ADD_TC(tp, setitimer_old);
213
214 return atf_no_error();
215}