Home | History | Annotate | Download | only in waitpid
      1 /*
      2  *
      3  *   Copyright (c) International Business Machines  Corp., 2001
      4  *
      5  *   This program is free software;  you can redistribute it and/or modify
      6  *   it under the terms of the GNU General Public License as published by
      7  *   the Free Software Foundation; either version 2 of the License, or
      8  *   (at your option) any later version.
      9  *
     10  *   This program is distributed in the hope that it will be useful,
     11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     13  *   the GNU General Public License for more details.
     14  *
     15  *   You should have received a copy of the GNU General Public License
     16  *   along with this program;  if not, write to the Free Software
     17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     18  */
     19 
     20 /*
     21  * NAME
     22  *	waitpid04.c
     23  *
     24  * DESCRIPTION
     25  *	test to check the error conditions in waitpid sys call
     26  *
     27  * USAGE:  <for command-line>
     28  *      waitpid04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
     29  *      where,  -c n : Run n copies concurrently.
     30  *              -e   : Turn on errno logging.
     31  *              -i n : Execute test n times.
     32  *              -I x : Execute test for x seconds.
     33  *              -P x : Pause for x seconds between iterations.
     34  *              -t   : Turn on syscall timing.
     35  *
     36  * History
     37  *	07/2001 John George
     38  *		-Ported
     39  *
     40  * Restrictions
     41  *	NONE
     42  */
     43 
     44 #include <sys/signal.h>
     45 #include <sys/types.h>
     46 #include <sys/wait.h>
     47 #include <errno.h>
     48 #include "test.h"
     49 
     50 static void setup(void);
     51 static void cleanup(void);
     52 
     53 char *TCID = "waitpid04";
     54 int TST_TOTAL = 1;
     55 
     56 #define INVAL_FLAG	-1
     57 
     58 static int flag, condition_number;
     59 
     60 int main(int ac, char **av)
     61 {
     62 	int pid, status, ret;
     63 
     64 	int lc;
     65 
     66 	tst_parse_opts(ac, av, NULL, NULL);
     67 
     68 	setup();
     69 
     70 	/* check for looping state if -i option is given */
     71 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     72 		/* reset tst_count in case we are looping */
     73 		tst_count = 0;
     74 
     75 		ret = waitpid(pid, &status, WNOHANG);
     76 		flag = 0;
     77 		condition_number = 1;
     78 		if (ret != -1) {
     79 			tst_resm(TFAIL, "condition %d test failed",
     80 				 condition_number);
     81 		} else {
     82 			if (errno != ECHILD) {
     83 				tst_resm(TFAIL, "waitpid() set invalid "
     84 					 "errno, expected ECHILD, got: %d",
     85 					 errno);
     86 			} else {
     87 				tst_resm(TPASS, "condition %d test passed",
     88 					 condition_number);
     89 			}
     90 		}
     91 		condition_number++;
     92 
     93 		if (FORK_OR_VFORK() == 0)
     94 			exit(0);
     95 
     96 		pid = 1;
     97 		ret = waitpid(pid, &status, WUNTRACED);
     98 		flag = 0;
     99 		if (ret != -1) {
    100 			tst_resm(TFAIL, "condition %d test failed",
    101 				 condition_number);
    102 		} else {
    103 			if (errno != ECHILD) {
    104 				tst_resm(TFAIL, "waitpid() set invalid "
    105 					 "errno, expected ECHILD, got: %d",
    106 					 errno);
    107 			} else {
    108 				tst_resm(TPASS, "condition %d test passed",
    109 					 condition_number);
    110 			}
    111 		}
    112 		condition_number++;
    113 
    114 		/* Option is Inval = INVAL_FLAG */
    115 		ret = waitpid(pid, &status, INVAL_FLAG);
    116 		flag = 0;
    117 		if (ret != -1) {
    118 			tst_resm(TFAIL, "condition %d test failed",
    119 				 condition_number);
    120 		} else {
    121 			if (errno != EINVAL) {
    122 				tst_resm(TFAIL, "waitpid() set invalid "
    123 					 "errno, expected EINVAL, got: %d",
    124 					 errno);
    125 			} else {
    126 				tst_resm(TPASS, "condition %d test passed",
    127 					 condition_number);
    128 			}
    129 		}
    130 		condition_number++;
    131 	}
    132 
    133 	cleanup();
    134 	tst_exit();
    135 }
    136 
    137 static void setup(void)
    138 {
    139 	TEST_PAUSE;
    140 }
    141 
    142 static void cleanup(void)
    143 {
    144 }
    145