1 /* $NetBSD: t_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $ */
4 * Copyright (c) 2016 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_wait_noproc.c,v 1.5 2016/11/09 17:50:19 kamil Exp $");
33 #include <sys/resource.h>
41 #define TWAIT_OPTION 0
48 atf_tc_set_md_var(tc, "descr",
49 "Test that wait(2) returns ECHILD for no child");
54 ATF_REQUIRE_ERRNO(ECHILD, wait(NULL) == -1);
59 ATF_TC_HEAD(waitpid, tc)
61 atf_tc_set_md_var(tc, "descr",
62 "Test that waitpid(2) returns ECHILD for WAIT_ANY and option %s",
63 ___STRING(TWAIT_OPTION));
66 ATF_TC_BODY(waitpid, tc)
68 ATF_REQUIRE_ERRNO(ECHILD, waitpid(WAIT_ANY, NULL, TWAIT_OPTION) == -1);
72 ATF_TC_HEAD(waitid, tc)
74 atf_tc_set_md_var(tc, "descr",
75 "Test that waitid(2) returns ECHILD for P_ALL and option %s",
76 ___STRING(TWAIT_OPTION));
79 ATF_TC_BODY(waitid, tc)
81 ATF_REQUIRE_ERRNO(ECHILD,
82 waitid(P_ALL, 0, NULL,
83 WTRAPPED | WEXITED | TWAIT_OPTION) == -1);
87 ATF_TC_HEAD(wait3, tc)
89 atf_tc_set_md_var(tc, "descr",
90 "Test that wait3(2) returns ECHILD for no child");
93 ATF_TC_BODY(wait3, tc)
95 ATF_REQUIRE_ERRNO(ECHILD, wait3(NULL, TWAIT_OPTION, NULL) == -1);
99 ATF_TC_HEAD(wait4, tc)
101 atf_tc_set_md_var(tc, "descr",
102 "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s",
103 ___STRING(TWAIT_OPTION));
106 ATF_TC_BODY(wait4, tc)
108 ATF_REQUIRE_ERRNO(ECHILD,
109 wait4(WAIT_ANY, NULL, TWAIT_OPTION, NULL) == -1);
113 ATF_TC_HEAD(wait6, tc)
115 atf_tc_set_md_var(tc, "descr",
116 "Test that wait6(2) returns ECHILD for P_ALL and option %s",
117 ___STRING(TWAIT_OPTION));
120 ATF_TC_BODY(wait6, tc)
122 ATF_REQUIRE_ERRNO(ECHILD,
123 wait6(P_ALL, 0, NULL,
124 WTRAPPED | WEXITED | TWAIT_OPTION, NULL, NULL) == -1);
128 * Generator of valid combinations of options
129 * Usage: i = 0; while ((o = get_options_wait6(i++)) != -1) {}
132 get_options6(size_t pos)
138 * waitid(2) must specify at least one of WEXITED, WUNTRACED,
139 * WSTOPPED, WTRAPPED or WCONTINUED. Single option WNOWAIT
143 const int matrix[] = {
144 WNOWAIT, /* First in order to blacklist it easily */
147 WSTOPPED, /* SUS compatibility, equal to WUNTRACED */
152 const size_t M = (1 << __arraycount(matrix)) - 1;
154 /* Skip empty and sole WNOWAIT option */
160 for (n = 0; n < __arraycount(matrix); n++) {
169 * Generator of valid combinations of options
170 * Usage: i = 0; while ((o = get_options_wait4(i++)) != -1) {}
173 get_options4(size_t pos)
178 const int special[] = {
183 __WALL, /* Linux compatibility, equal to WALLSIG */
184 __WCLONE /* Linux compatibility, equal to WALTSIG */
188 const int matrix[] = {
192 WSTOPPED, /* SUS compatibility, equal to WUNTRACED */
197 const size_t M = (1 << __arraycount(special)) - 1;
199 if (pos < __arraycount(special))
202 pos -= __arraycount(special);
204 ++pos; /* Don't start with empty mask */
209 for (n = 0; n < __arraycount(special); n++) {
217 ATF_TC(waitpid_options);
218 ATF_TC_HEAD(waitpid_options, tc)
220 atf_tc_set_md_var(tc, "descr",
221 "Test that waitpid(2) returns ECHILD for WAIT_ANY and valid "
222 "combination of options with%s WNOHANG",
223 TWAIT_OPTION == 0 ? "out" : "");
226 ATF_TC_BODY(waitpid_options, tc)
231 while((o = get_options4(i++)) != -1) {
232 printf("Testing waitpid(2) with options %x\n", o);
234 ATF_REQUIRE_ERRNO(ECHILD,
235 waitpid(WAIT_ANY, NULL, o | TWAIT_OPTION) == -1);
239 ATF_TC(waitid_options);
240 ATF_TC_HEAD(waitid_options, tc)
242 atf_tc_set_md_var(tc, "descr",
243 "Test that waitid(2) returns ECHILD for P_ALL and valid "
244 "combination of options with%s WNOHANG",
245 TWAIT_OPTION == 0 ? "out" : "");
248 ATF_TC_BODY(waitid_options, tc)
253 while((o = get_options6(i++)) != -1) {
254 printf("Testing waitid(2) with options %x\n", o);
256 ATF_REQUIRE_ERRNO(ECHILD,
257 waitid(P_ALL, 0, NULL, o | TWAIT_OPTION) == -1);
261 ATF_TC(wait3_options);
262 ATF_TC_HEAD(wait3_options, tc)
264 atf_tc_set_md_var(tc, "descr",
265 "Test that wait3(2) returns ECHILD for no child");
268 ATF_TC_BODY(wait3_options, tc)
273 while((o = get_options4(i++)) != -1) {
274 printf("Testing wait3(2) with options %x\n", o);
276 ATF_REQUIRE_ERRNO(ECHILD,
277 wait3(NULL, o | TWAIT_OPTION, NULL) == -1);
281 ATF_TC(wait4_options);
282 ATF_TC_HEAD(wait4_options, tc)
284 atf_tc_set_md_var(tc, "descr",
285 "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s",
286 ___STRING(TWAIT_OPTION));
289 ATF_TC_BODY(wait4_options, tc)
294 while((o = get_options4(i++)) != -1) {
295 printf("Testing wait4(2) with options %x\n", o);
297 ATF_REQUIRE_ERRNO(ECHILD,
298 wait4(WAIT_ANY, NULL, o | TWAIT_OPTION, NULL) == -1);
302 ATF_TC(wait6_options);
303 ATF_TC_HEAD(wait6_options, tc)
305 atf_tc_set_md_var(tc, "descr",
306 "Test that wait6(2) returns ECHILD for P_ALL and option %s",
307 ___STRING(TWAIT_OPTION));
310 ATF_TC_BODY(wait6_options, tc)
315 while((o = get_options6(i++)) != -1) {
316 printf("Testing wait6(2) with options %x\n", o);
318 ATF_REQUIRE_ERRNO(ECHILD,
319 wait6(P_ALL, 0, NULL, o | TWAIT_OPTION, NULL, NULL) == -1);
326 #if TWAIT_OPTION == 0
327 ATF_TP_ADD_TC(tp, wait);
329 ATF_TP_ADD_TC(tp, waitpid);
330 ATF_TP_ADD_TC(tp, waitid);
331 ATF_TP_ADD_TC(tp, wait3);
332 ATF_TP_ADD_TC(tp, wait4);
333 ATF_TP_ADD_TC(tp, wait6);
335 ATF_TP_ADD_TC(tp, waitpid_options);
336 ATF_TP_ADD_TC(tp, waitid_options);
337 ATF_TP_ADD_TC(tp, wait3_options);
338 ATF_TP_ADD_TC(tp, wait4_options);
339 ATF_TP_ADD_TC(tp, wait6_options);
341 return atf_no_error();