1 /******************************************************************************/
2 /* Copyright (c) Crackerjack Project., 2007 */
3 /* */
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 */
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 */
16 /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
17 /* */
18 /******************************************************************************/
19 /******************************************************************************/
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> */
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
51 #include "test.h"
52 #include "lapi/syscalls.h"
53
54 char *TCID = "tkill01";
55 int testno;
56 int TST_TOTAL = 2;
57
cleanup(void)58 void cleanup(void)
59 {
60
61 tst_rmdir();
62 }
63
setup(void)64 void setup(void)
65 {
66 TEST_PAUSE;
67 tst_tmpdir();
68 }
69
70 int sig_count = 0;
71
sig_action(int sig)72 void sig_action(int sig)
73 {
74 sig_count = 1;
75 }
76
main(int ac,char ** av)77 int main(int ac, char **av)
78 {
79 int tid;
80 int lc;
81
82 tst_parse_opts(ac, av, NULL, NULL);
83
84 setup();
85
86 for (lc = 0; TEST_LOOPING(lc); ++lc) {
87 tst_count = 0;
88 for (testno = 0; testno < TST_TOTAL; ++testno) {
89 if (signal(SIGUSR1, &sig_action) == SIG_ERR)
90 tst_brkm(TBROK | TERRNO, cleanup,
91 "signal(SIGUSR1, ..) failed");
92 TEST(tid = ltp_syscall(__NR_gettid));
93 if (TEST_RETURN == -1) {
94 tst_resm(TFAIL | TTERRNO, "tkill failed");
95 }
96 TEST(ltp_syscall(__NR_tkill, tid, SIGUSR1));
97 if (TEST_RETURN == 0) {
98 tst_resm(TPASS, "tkill call succeeded");
99 } else {
100 tst_resm(TFAIL | TTERRNO, "tkill failed");
101 }
102 }
103 }
104 cleanup();
105 tst_exit();
106 }
107