plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * NAME |
| 22 | * kill03.c |
| 23 | * |
| 24 | * DESCRIPTION |
| 25 | * Test case to check that kill fails when given an invalid signal. |
| 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 an invalid signal |
| 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 22 (invalid argument). |
| 37 | * issue a PASS message |
| 38 | * otherwise |
| 39 | * issue a FAIL message |
| 40 | * call cleanup |
| 41 | * |
| 42 | * USAGE |
| 43 | * kill03 [-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 | * none |
| 56 | */ |
| 57 | |
| 58 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 59 | |
| 60 | #include <signal.h> |
| 61 | #include <errno.h> |
| 62 | #include <sys/wait.h> |
| 63 | |
| 64 | void cleanup(void); |
| 65 | void setup(void); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 66 | void do_child(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 68 | char *TCID = "kill03"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 69 | int TST_TOTAL = 1; |
| 70 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | #define TEST_SIG 2000 |
| 72 | |
robbiew | b8360ee | 2003-03-26 22:04:58 +0000 | [diff] [blame] | 73 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 75 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 76 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 77 | pid_t pid; |
robbiew | b8360ee | 2003-03-26 22:04:58 +0000 | [diff] [blame] | 78 | int exno, status; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 80 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 81 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 83 | #ifdef UCLINUX |
| 84 | maybe_run_child(&do_child, ""); |
| 85 | #endif |
| 86 | |
Cyril Hrubis | 605fa33 | 2015-02-04 13:11:20 +0100 | [diff] [blame] | 87 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
| 89 | /* The following loop checks looping state if -i option given */ |
| 90 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 91 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 92 | /* reset tst_count in case we are looping */ |
| 93 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | status = 1; |
| 95 | exno = 1; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 96 | pid = FORK_OR_VFORK(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | if (pid < 0) { |
| 98 | tst_brkm(TBROK, cleanup, "Fork of child failed"); |
| 99 | } else if (pid == 0) { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 100 | #ifdef UCLINUX |
| 101 | if (self_exec(av[0], "") < 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | tst_brkm(TBROK, cleanup, |
| 103 | "self_exec of child failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 104 | } |
| 105 | #else |
| 106 | do_child(); |
| 107 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | } else { |
| 109 | TEST(kill(pid, TEST_SIG)); |
| 110 | kill(pid, SIGKILL); |
| 111 | waitpid(pid, &status, 0); |
| 112 | } |
| 113 | |
| 114 | if (TEST_RETURN != -1) { |
| 115 | tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s " |
vapier | ae54285 | 2009-08-28 13:22:51 +0000 | [diff] [blame] | 116 | "Expected a return value of -1 got %ld", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 117 | TCID, TEST_ERRNO, strerror(TEST_ERRNO), |
| 118 | TEST_RETURN); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 119 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 121 | /* |
| 122 | * Check to see if the errno was set to the expected |
| 123 | * value of 22 : EINVAL. |
| 124 | */ |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 125 | if (TEST_ERRNO == EINVAL) { |
| 126 | tst_resm(TPASS, "errno set to %d : %s, as " |
| 127 | "expected", TEST_ERRNO, |
| 128 | strerror(TEST_ERRNO)); |
| 129 | } else { |
| 130 | tst_resm(TFAIL, "errno set to %d : %s expected " |
| 131 | "%d : %s", TEST_ERRNO, |
| 132 | strerror(TEST_ERRNO), 22, |
| 133 | strerror(22)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 136 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 137 | cleanup(); |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 138 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | } |
| 140 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 141 | /* |
| 142 | * do_child() |
| 143 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 144 | void do_child(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 145 | { |
| 146 | int exno = 1; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 147 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 148 | pause(); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 149 | exit(exno); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 150 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 151 | |
| 152 | /* |
| 153 | * setup() - performs all ONE TIME setup for this test |
| 154 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 155 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 156 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 157 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 158 | TEST_PAUSE; |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 163 | * or premature exit. |
| 164 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 165 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 166 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 167 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 168 | } |