subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 4 | /* This program is free software; you can redistribute it and/or modify */ |
| 5 | /* it under the terms of the GNU General Public License as published by */ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 6 | /* the Free Software Foundation; either version 2 of the License, or */ |
| 7 | /* (at your option) any later version. */ |
| 8 | /* */ |
| 9 | /* This program is distributed in the hope that it will be useful, */ |
| 10 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 11 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */ |
| 12 | /* the GNU General Public License for more details. */ |
| 13 | /* */ |
| 14 | /* You should have received a copy of the GNU General Public License */ |
| 15 | /* along with this program; if not, write to the Free Software */ |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 17 | /* */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 20 | /* */ |
| 21 | /* File: tkill02.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the tkill() syscall */ |
| 24 | /* */ |
| 25 | /* Usage: <for command-line> */ |
| 26 | /* tkill02 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 27 | /* where, -c n : Run n copies concurrently. */ |
| 28 | /* -e : Turn on errno logging. */ |
| 29 | /* -i n : Execute test n times. */ |
| 30 | /* -I x : Execute test for x seconds. */ |
| 31 | /* -P x : Pause for x seconds between iterations. */ |
| 32 | /* -t : Turn on syscall timing. */ |
| 33 | /* */ |
| 34 | /* Total Tests: 1 */ |
| 35 | /* */ |
| 36 | /* Test Name: tkill02 */ |
| 37 | /* History: Porting from Crackerjack to LTP is done by */ |
| 38 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 39 | /******************************************************************************/ |
| 40 | |
| 41 | #include <stdio.h> |
| 42 | #include <stdlib.h> |
| 43 | #include <errno.h> |
| 44 | #include <unistd.h> |
| 45 | #include <signal.h> |
| 46 | #include <sys/syscall.h> |
| 47 | |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 48 | /* Harness Specific Include Files. */ |
| 49 | #include "test.h" |
| 50 | #include "usctest.h" |
| 51 | #include "linux_syscall_numbers.h" |
| 52 | |
| 53 | /* Extern Global Variables */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 54 | |
| 55 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 56 | char *TCID = "tkill02"; /* Test program identifier. */ |
| 57 | int testno; |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 58 | |
| 59 | /* Extern Global Functions */ |
| 60 | /******************************************************************************/ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 61 | /* */ |
| 62 | /* Function: cleanup */ |
| 63 | /* */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 64 | /* Description: Performs all one time clean up for this test on successful */ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 65 | /* completion, premature exit or failure. Closes all temporary */ |
| 66 | /* files, removes all temporary directories exits the test with */ |
| 67 | /* appropriate return code by calling tst_exit() function. */ |
| 68 | /* */ |
| 69 | /* Input: None. */ |
| 70 | /* */ |
| 71 | /* Output: None. */ |
| 72 | /* */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 73 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 74 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 75 | /* */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 76 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | extern void cleanup() |
| 78 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 79 | |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 80 | TEST_CLEANUP; |
| 81 | tst_rmdir(); |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /* Local Functions */ |
| 85 | /******************************************************************************/ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 86 | /* */ |
| 87 | /* Function: setup */ |
| 88 | /* */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 89 | /* Description: Performs all one time setup for this test. This function is */ |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 90 | /* typically used to capture signals, create temporary dirs */ |
| 91 | /* and temporary files that may be used in the course of this */ |
| 92 | /* test. */ |
| 93 | /* */ |
| 94 | /* Input: None. */ |
| 95 | /* */ |
| 96 | /* Output: None. */ |
| 97 | /* */ |
| 98 | /* Return: On failure - Exits by calling cleanup(). */ |
| 99 | /* On success - returns 0. */ |
| 100 | /* */ |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 101 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 102 | void setup() |
| 103 | { |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 104 | /* Capture signals if any */ |
| 105 | /* Create temporary directories */ |
| 106 | TEST_PAUSE; |
| 107 | tst_tmpdir(); |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | struct test_case_t { |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 111 | int tid; |
| 112 | int exp_errno; |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 113 | } test_cases[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 114 | { |
| 115 | -1, EINVAL}, { |
| 116 | 99999, ESRCH} |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 117 | }; |
| 118 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 119 | int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); |
| 120 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 121 | int main(int ac, char **av) |
| 122 | { |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 123 | int i; |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 124 | |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 125 | setup(); |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 126 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 127 | for (i = 0; i < TST_TOTAL; i++) { |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 128 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 129 | TEST(ltp_syscall(__NR_tkill, test_cases[i].tid, SIGUSR1)); |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 130 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 131 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 132 | if (TEST_ERRNO == test_cases[i].exp_errno) { |
| 133 | tst_resm(TPASS | TTERRNO, |
| 134 | "tkill(%d, SIGUSR1) failed as expected", |
| 135 | test_cases[i].tid); |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 136 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 137 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 138 | "tkill(%d, SIGUSR1) failed unexpectedly", |
| 139 | test_cases[i].tid); |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 140 | } |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 141 | } else { |
| 142 | tst_brkm(TFAIL, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 143 | "tkill(%d) succeeded unexpectedly", |
| 144 | test_cases[i].tid); |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 145 | } |
| 146 | } |
subrata_modak | 1da3073 | 2009-05-21 18:47:14 +0000 | [diff] [blame] | 147 | cleanup(); |
Garrett Cooper | c5ed3e9 | 2010-11-22 15:13:01 -0800 | [diff] [blame] | 148 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 149 | } |