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 * kill04.c 23 * 24 * DESCRIPTION 25 * Test case to check that kill() fails when passed a non-existant pid. 26 * 27 * ALGORITHM 28 * call setup 29 * loop if the -i option was given 30 * fork a child 31 * execute the kill system call with a non-existant PID 32 * check the return value 33 * if return value is not -1 34 * issue a FAIL message, break remaining tests and cleanup 35 * if we are doing functional testing 36 * if the errno was set to 3 (No such proccess) 37 * issue a PASS message 38 * otherwise 39 * issue a FAIL message 40 * call cleanup 41 * 42 * USAGE 43 * kill04 [-c n] [-f] [-i n] [-I x] [-P x] [-t] 44 * where, -c n : Run n copies concurrently. 45 * -f : Turn off functionality Testing. 46 * -i n : Execute test n times. 47 * -I x : Execute test for x seconds. 48 * -P x : Pause for x seconds between iterations. 49 * -t : Turn on syscall timing. 50 * 51 * HISTORY 52 * 07/2001 Ported by Wayne Boyer 53 * 54 * RESTRICTIONS 55 * This test should be run by a non-root user 56 */ 57 58 #include "test.h" 59 60 #include <signal.h> 61 #include <errno.h> 62 #include <sys/wait.h> 63 64 void cleanup(void); 65 void setup(void); 66 void do_child(void); 67 68 char *TCID = "kill04"; 69 int TST_TOTAL = 1; 70 71 #define TEST_SIG SIGKILL 72 73 int main(int ac, char **av) 74 { 75 int lc; 76 pid_t fake_pid; 77 78 tst_parse_opts(ac, av, NULL, NULL); 79 80 setup(); 81 82 /* The following loop checks looping state if -i option given */ 83 for (lc = 0; TEST_LOOPING(lc); lc++) { 84 85 /* reset tst_count in case we are looping */ 86 tst_count = 0; 87 88 fake_pid = tst_get_unused_pid(cleanup); 89 TEST(kill(fake_pid, TEST_SIG)); 90 91 if (TEST_RETURN != -1) { 92 tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s " 93 "Expected a return value of -1 got %ld", 94 TCID, TEST_ERRNO, strerror(TEST_ERRNO), 95 TEST_RETURN); 96 } 97 98 /* 99 * Check to see if the errno was set to the expected 100 * value of 3 : ESRCH 101 */ 102 if (TEST_ERRNO == ESRCH) { 103 tst_resm(TPASS, "errno set to %d : %s, as " 104 "expected", TEST_ERRNO, 105 strerror(TEST_ERRNO)); 106 } else { 107 tst_resm(TFAIL, "errno set to %d : %s expected " 108 "%d : %s", TEST_ERRNO, 109 strerror(TEST_ERRNO), 3, strerror(3)); 110 } 111 } 112 113 cleanup(); 114 tst_exit(); 115 } 116 117 /* 118 * setup() - performs all ONE TIME setup for this test 119 */ 120 void setup(void) 121 { 122 123 TEST_PAUSE; 124 } 125 126 /* 127 * cleanup() - performs all the ONE TIME cleanup for this test at completion 128 * or premature exit. 129 */ 130 void cleanup(void) 131 { 132 133 } 134