Home | History | Annotate | Line # | Download | only in sys
t_wait_noproc.c revision 1.3
      1 /* $NetBSD: t_wait_noproc.c,v 1.3 2016/11/08 15:21:34 kamil Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2016 The NetBSD Foundation, Inc.
      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
      9  * are met:
     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.
     15  *
     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.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __RCSID("$NetBSD: t_wait_noproc.c,v 1.3 2016/11/08 15:21:34 kamil Exp $");
     31 
     32 #include <sys/wait.h>
     33 #include <sys/resource.h>
     34 
     35 #include <errno.h>
     36 
     37 #include <atf-c.h>
     38 
     39 #ifndef TWAIT_OPTION
     40 #define TWAIT_OPTION 0
     41 #endif
     42 
     43 #if TWAIT_OPTION == 0
     44 ATF_TC(wait);
     45 ATF_TC_HEAD(wait, tc)
     46 {
     47 	atf_tc_set_md_var(tc, "descr",
     48 	    "Test that wait(2) returns ECHILD for no child");
     49 }
     50 
     51 ATF_TC_BODY(wait, tc)
     52 {
     53 	ATF_REQUIRE_ERRNO(ECHILD, wait(NULL) == -1);
     54 }
     55 #endif
     56 
     57 ATF_TC(waitpid);
     58 ATF_TC_HEAD(waitpid, tc)
     59 {
     60 	atf_tc_set_md_var(tc, "descr",
     61 	    "Test that waitpid(2) returns ECHILD for WAIT_ANY and option %s",
     62 	    ___STRING(TWAIT_OPTION));
     63 }
     64 
     65 ATF_TC_BODY(waitpid, tc)
     66 {
     67 #if TWAIT_OPTION
     68 	/* wait4() (and friends) with WNOHANG and no children does not error */
     69 	atf_tc_expect_fail("PR standards/51606");
     70 #endif
     71 	ATF_REQUIRE_ERRNO(ECHILD, waitpid(WAIT_ANY, NULL, TWAIT_OPTION) == -1);
     72 }
     73 
     74 ATF_TC(waitid);
     75 ATF_TC_HEAD(waitid, tc)
     76 {
     77 	atf_tc_set_md_var(tc, "descr",
     78 	    "Test that waitid(2) returns ECHILD for P_ALL and option %s",
     79 	    ___STRING(TWAIT_OPTION));
     80 }
     81 
     82 ATF_TC_BODY(waitid, tc)
     83 {
     84 #if TWAIT_OPTION
     85 	/* wait4() (and friends) with WNOHANG and no children does not error */
     86 	atf_tc_expect_fail("PR standards/51606");
     87 #endif
     88 	ATF_REQUIRE_ERRNO(ECHILD,
     89 	    waitid(P_ALL, 0, NULL, WEXITED | TWAIT_OPTION) == -1);
     90 }
     91 
     92 ATF_TC(wait3);
     93 ATF_TC_HEAD(wait3, tc)
     94 {
     95 	atf_tc_set_md_var(tc, "descr",
     96 	    "Test that wait3(2) returns ECHILD for no child");
     97 }
     98 
     99 ATF_TC_BODY(wait3, tc)
    100 {
    101 #if TWAIT_OPTION
    102 	/* wait4() (and friends) with WNOHANG and no children does not error */
    103 	atf_tc_expect_fail("PR standards/51606");
    104 #endif
    105 	ATF_REQUIRE_ERRNO(ECHILD, wait3(NULL, TWAIT_OPTION, NULL) == -1);
    106 }
    107 
    108 ATF_TC(wait4);
    109 ATF_TC_HEAD(wait4, tc)
    110 {
    111 	atf_tc_set_md_var(tc, "descr",
    112 	    "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s",
    113 	    ___STRING(TWAIT_OPTION));
    114 }
    115 
    116 ATF_TC_BODY(wait4, tc)
    117 {
    118 #if TWAIT_OPTION
    119 	/* wait4() (and friends) with WNOHANG and no children does not error */
    120 	atf_tc_expect_fail("PR standards/51606");
    121 #endif
    122 	ATF_REQUIRE_ERRNO(ECHILD,
    123 	    wait4(WAIT_ANY, NULL, TWAIT_OPTION, NULL) == -1);
    124 }
    125 
    126 ATF_TC(wait6);
    127 ATF_TC_HEAD(wait6, tc)
    128 {
    129 	atf_tc_set_md_var(tc, "descr",
    130 	    "Test that wait6(2) returns ECHILD for P_ALL and option %s",
    131 	    ___STRING(TWAIT_OPTION));
    132 }
    133 
    134 ATF_TC_BODY(wait6, tc)
    135 {
    136 #if TWAIT_OPTION
    137 	/* wait4() (and friends) with WNOHANG and no children does not error */
    138 	atf_tc_expect_fail("PR standards/51606");
    139 #endif
    140 	ATF_REQUIRE_ERRNO(ECHILD,
    141 	    wait6(P_ALL, 0, NULL, WEXITED | TWAIT_OPTION, NULL, NULL) == -1);
    142 }
    143 
    144 ATF_TP_ADD_TCS(tp)
    145 {
    146 
    147 #if TWAIT_OPTION == 0
    148 	ATF_TP_ADD_TC(tp, wait);
    149 #endif
    150 	ATF_TP_ADD_TC(tp, waitpid);
    151 	ATF_TP_ADD_TC(tp, waitid);
    152 	ATF_TP_ADD_TC(tp, wait3);
    153 	ATF_TP_ADD_TC(tp, wait4);
    154 	ATF_TP_ADD_TC(tp, wait6);
    155 
    156 	return atf_no_error();
    157 }
    158