subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +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 | ddc4c0d | 2010-11-22 15:05:35 -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 | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 17 | /* */ |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 20 | /* */ |
| 21 | /* File: tkill01.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the tkill() syscall */ |
| 24 | /* */ |
| 25 | /* Usage: <for command-line> */ |
| 26 | /* tkill01 [-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: tkill01 */ |
| 37 | /* History: Porting from Crackerjack to LTP is done by */ |
| 38 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 39 | /******************************************************************************/ |
| 40 | |
| 41 | #include <stdio.h> |
| 42 | #include <stdlib.h> |
| 43 | #include <errno.h> |
| 44 | #include <unistd.h> |
| 45 | |
| 46 | #include <signal.h> |
| 47 | #include <sys/syscall.h> |
| 48 | #include <linux/unistd.h> |
| 49 | #include <sys/types.h> |
| 50 | |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 51 | #include "test.h" |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 52 | #include "linux_syscall_numbers.h" |
| 53 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 54 | char *TCID = "tkill01"; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 55 | int testno; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 56 | int TST_TOTAL = 2; |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 57 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 58 | void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 59 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 60 | |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 61 | tst_rmdir(); |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 64 | void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 65 | { |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 66 | TEST_PAUSE; |
| 67 | tst_tmpdir(); |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | int sig_count = 0; |
| 71 | |
| 72 | void sig_action(int sig) |
| 73 | { |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 74 | sig_count = 1; |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | int main(int ac, char **av) |
| 78 | { |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 79 | int tid; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 80 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 81 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 82 | |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 83 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
| 84 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 85 | |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 86 | setup(); |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 87 | |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 88 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 89 | tst_count = 0; |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 90 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Garrett Cooper | a6b3277 | 2010-12-19 08:16:45 -0800 | [diff] [blame] | 91 | if (signal(SIGUSR1, &sig_action) == SIG_ERR) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 92 | tst_brkm(TBROK | TERRNO, cleanup, |
| 93 | "signal(SIGUSR1, ..) failed"); |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 94 | TEST(tid = ltp_syscall(__NR_gettid)); |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 95 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 96 | tst_resm(TFAIL | TTERRNO, "tkill failed"); |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 97 | } |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 98 | TEST(ltp_syscall(__NR_tkill, tid, SIGUSR1)); |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 99 | if (TEST_RETURN == 0) { |
| 100 | tst_resm(TPASS, "tkill call succeeded"); |
| 101 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 102 | tst_resm(TFAIL | TTERRNO, "tkill failed"); |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 103 | } |
| 104 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 105 | } |
subrata_modak | f2badb6 | 2009-05-21 18:45:51 +0000 | [diff] [blame] | 106 | cleanup(); |
Garrett Cooper | ddc4c0d | 2010-11-22 15:05:35 -0800 | [diff] [blame] | 107 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 108 | } |