blob: 6e21ba0363548ca535e233eb0efa17238b2bc61c [file] [log] [blame]
subrata_modakf2badb62009-05-21 18:45:51 +00001/******************************************************************************/
Garrett Cooperddc4c0d2010-11-22 15:05:35 -08002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
subrata_modakf2badb62009-05-21 18:45:51 +00004/* 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 Cooperddc4c0d2010-11-22 15:05:35 -08006/* 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 Gao4548c6c2012-10-19 18:03:36 +080016/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080017/* */
subrata_modakf2badb62009-05-21 18:45:51 +000018/******************************************************************************/
19/******************************************************************************/
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080020/* */
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_modakf2badb62009-05-21 18:45:51 +000039/******************************************************************************/
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_modakf2badb62009-05-21 18:45:51 +000051#include "test.h"
subrata_modakf2badb62009-05-21 18:45:51 +000052#include "linux_syscall_numbers.h"
53
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020054char *TCID = "tkill01";
Wanlong Gao354ebb42012-12-07 10:10:04 +080055int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020056int TST_TOTAL = 2;
subrata_modakf2badb62009-05-21 18:45:51 +000057
Mike Frysingerc57fba52014-04-09 18:56:30 -040058void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080059{
Garrett Cooper2c282152010-12-16 00:55:50 -080060
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080061 tst_rmdir();
subrata_modakf2badb62009-05-21 18:45:51 +000062}
63
Mike Frysingerc57fba52014-04-09 18:56:30 -040064void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080065{
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080066 TEST_PAUSE;
67 tst_tmpdir();
subrata_modakf2badb62009-05-21 18:45:51 +000068}
69
70int sig_count = 0;
71
72void sig_action(int sig)
73{
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080074 sig_count = 1;
subrata_modakf2badb62009-05-21 18:45:51 +000075}
76
Wanlong Gao354ebb42012-12-07 10:10:04 +080077int main(int ac, char **av)
78{
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080079 int tid;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020080 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020081 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -080082
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080083 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
84 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modakf2badb62009-05-21 18:45:51 +000085
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080086 setup();
subrata_modakf2badb62009-05-21 18:45:51 +000087
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080088 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080089 tst_count = 0;
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080090 for (testno = 0; testno < TST_TOTAL; ++testno) {
Garrett Coopera6b32772010-12-19 08:16:45 -080091 if (signal(SIGUSR1, &sig_action) == SIG_ERR)
Wanlong Gao354ebb42012-12-07 10:10:04 +080092 tst_brkm(TBROK | TERRNO, cleanup,
93 "signal(SIGUSR1, ..) failed");
Jan Stancek359980f2013-02-15 10:16:05 +010094 TEST(tid = ltp_syscall(__NR_gettid));
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080095 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +080096 tst_resm(TFAIL | TTERRNO, "tkill failed");
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080097 }
Jan Stancek359980f2013-02-15 10:16:05 +010098 TEST(ltp_syscall(__NR_tkill, tid, SIGUSR1));
Garrett Cooperddc4c0d2010-11-22 15:05:35 -080099 if (TEST_RETURN == 0) {
100 tst_resm(TPASS, "tkill call succeeded");
101 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800102 tst_resm(TFAIL | TTERRNO, "tkill failed");
Garrett Cooperddc4c0d2010-11-22 15:05:35 -0800103 }
104 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800105 }
subrata_modakf2badb62009-05-21 18:45:51 +0000106 cleanup();
Garrett Cooperddc4c0d2010-11-22 15:05:35 -0800107 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700108}