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 Foundation, *
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
17 * *
18 ******************************************************************************/
19 /*
20 * File: tkill02.c
21 *
22 * Description: This tests the tkill() syscall
23 *
24 * History: Porting from Crackerjack to LTP is done by
25 * Manas Kumar Nayak maknayak@in.ibm.com>
26 */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <errno.h>
31 #include <unistd.h>
32 #include <signal.h>
33 #include <sys/syscall.h>
34
35 #include "test.h"
36 #include "lapi/syscalls.h"
37
38 char *TCID = "tkill02";
39 int testno;
40
41 static pid_t inval_tid = -1;
42 static pid_t unused_tid;
43
cleanup(void)44 void cleanup(void)
45 {
46 tst_rmdir();
47 }
48
setup(void)49 void setup(void)
50 {
51 TEST_PAUSE;
52 tst_tmpdir();
53
54 unused_tid = tst_get_unused_pid(cleanup);
55 }
56
57 struct test_case_t {
58 int *tid;
59 int exp_errno;
60 } test_cases[] = {
61 {&inval_tid, EINVAL},
62 {&unused_tid, ESRCH}
63 };
64
65 int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
66
main(int ac,char ** av)67 int main(int ac, char **av)
68 {
69 int i;
70
71 setup();
72
73 tst_parse_opts(ac, av, NULL, NULL);
74
75 for (i = 0; i < TST_TOTAL; i++) {
76
77 TEST(ltp_syscall(__NR_tkill, *(test_cases[i].tid), SIGUSR1));
78
79 if (TEST_RETURN == -1) {
80 if (TEST_ERRNO == test_cases[i].exp_errno) {
81 tst_resm(TPASS | TTERRNO,
82 "tkill(%d, SIGUSR1) failed as expected",
83 *(test_cases[i].tid));
84 } else {
85 tst_brkm(TFAIL | TTERRNO, cleanup,
86 "tkill(%d, SIGUSR1) failed unexpectedly",
87 *(test_cases[i].tid));
88 }
89 } else {
90 tst_brkm(TFAIL, cleanup,
91 "tkill(%d) succeeded unexpectedly",
92 *(test_cases[i].tid));
93 }
94 }
95 cleanup();
96 tst_exit();
97 }
98