Home | History | Annotate | Line # | Download | only in sys
t_wait_noproc.c revision 1.4
      1 /* $NetBSD: t_wait_noproc.c,v 1.4 2016/11/09 12:44:29 kre 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.4 2016/11/09 12:44:29 kre 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 	ATF_REQUIRE_ERRNO(ECHILD, waitpid(WAIT_ANY, NULL, TWAIT_OPTION) == -1);
     68 }
     69 
     70 ATF_TC(waitid);
     71 ATF_TC_HEAD(waitid, tc)
     72 {
     73 	atf_tc_set_md_var(tc, "descr",
     74 	    "Test that waitid(2) returns ECHILD for P_ALL and option %s",
     75 	    ___STRING(TWAIT_OPTION));
     76 }
     77 
     78 ATF_TC_BODY(waitid, tc)
     79 {
     80 	ATF_REQUIRE_ERRNO(ECHILD,
     81 	    waitid(P_ALL, 0, NULL, WEXITED | TWAIT_OPTION) == -1);
     82 }
     83 
     84 ATF_TC(wait3);
     85 ATF_TC_HEAD(wait3, tc)
     86 {
     87 	atf_tc_set_md_var(tc, "descr",
     88 	    "Test that wait3(2) returns ECHILD for no child");
     89 }
     90 
     91 ATF_TC_BODY(wait3, tc)
     92 {
     93 	ATF_REQUIRE_ERRNO(ECHILD, wait3(NULL, TWAIT_OPTION, NULL) == -1);
     94 }
     95 
     96 ATF_TC(wait4);
     97 ATF_TC_HEAD(wait4, tc)
     98 {
     99 	atf_tc_set_md_var(tc, "descr",
    100 	    "Test that wait4(2) returns ECHILD for WAIT_ANY and option %s",
    101 	    ___STRING(TWAIT_OPTION));
    102 }
    103 
    104 ATF_TC_BODY(wait4, tc)
    105 {
    106 	ATF_REQUIRE_ERRNO(ECHILD,
    107 	    wait4(WAIT_ANY, NULL, TWAIT_OPTION, NULL) == -1);
    108 }
    109 
    110 ATF_TC(wait6);
    111 ATF_TC_HEAD(wait6, tc)
    112 {
    113 	atf_tc_set_md_var(tc, "descr",
    114 	    "Test that wait6(2) returns ECHILD for P_ALL and option %s",
    115 	    ___STRING(TWAIT_OPTION));
    116 }
    117 
    118 ATF_TC_BODY(wait6, tc)
    119 {
    120 	ATF_REQUIRE_ERRNO(ECHILD,
    121 	    wait6(P_ALL, 0, NULL, WEXITED | TWAIT_OPTION, NULL, NULL) == -1);
    122 }
    123 
    124 ATF_TP_ADD_TCS(tp)
    125 {
    126 
    127 #if TWAIT_OPTION == 0
    128 	ATF_TP_ADD_TC(tp, wait);
    129 #endif
    130 	ATF_TP_ADD_TC(tp, waitpid);
    131 	ATF_TP_ADD_TC(tp, waitid);
    132 	ATF_TP_ADD_TC(tp, wait3);
    133 	ATF_TP_ADD_TC(tp, wait4);
    134 	ATF_TP_ADD_TC(tp, wait6);
    135 
    136 	return atf_no_error();
    137 }
    138