blob: 24f2bb20d499784155e3ef4eabffe856f1d0ac15 [file] [log] [blame]
subrata_modak1da30732009-05-21 18:47:14 +00001/******************************************************************************/
Garrett Cooperc5ed3e92010-11-22 15:13:01 -08002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
subrata_modak1da30732009-05-21 18:47:14 +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 Cooperc5ed3e92010-11-22 15:13:01 -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 Cooperc5ed3e92010-11-22 15:13:01 -080017/* */
subrata_modak1da30732009-05-21 18:47:14 +000018/******************************************************************************/
19/******************************************************************************/
Garrett Cooperc5ed3e92010-11-22 15:13:01 -080020/* */
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_modak1da30732009-05-21 18:47:14 +000039/******************************************************************************/
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_modak1da30732009-05-21 18:47:14 +000048#include "test.h"
subrata_modak1da30732009-05-21 18:47:14 +000049#include "linux_syscall_numbers.h"
50
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020051char *TCID = "tkill02";
Wanlong Gao354ebb42012-12-07 10:10:04 +080052int testno;
subrata_modak1da30732009-05-21 18:47:14 +000053
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040054static pid_t inval_tid = -1;
55static pid_t unused_tid;
56
57
subrata_modak1da30732009-05-21 18:47:14 +000058/* Extern Global Functions */
59/******************************************************************************/
Garrett Cooperc5ed3e92010-11-22 15:13:01 -080060/* */
61/* Function: cleanup */
62/* */
subrata_modak1da30732009-05-21 18:47:14 +000063/* Description: Performs all one time clean up for this test on successful */
Garrett Cooperc5ed3e92010-11-22 15:13:01 -080064/* completion, premature exit or failure. Closes all temporary */
65/* files, removes all temporary directories exits the test with */
66/* appropriate return code by calling tst_exit() function. */
67/* */
68/* Input: None. */
69/* */
70/* Output: None. */
71/* */
subrata_modak1da30732009-05-21 18:47:14 +000072/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
Garrett Cooperc5ed3e92010-11-22 15:13:01 -080073/* On success - Exits calling tst_exit(). With '0' return code. */
74/* */
subrata_modak1da30732009-05-21 18:47:14 +000075/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -040076void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080077{
Garrett Cooper2c282152010-12-16 00:55:50 -080078
Garrett Cooperc5ed3e92010-11-22 15:13:01 -080079 tst_rmdir();
subrata_modak1da30732009-05-21 18:47:14 +000080}
81
82/* Local Functions */
83/******************************************************************************/
Garrett Cooperc5ed3e92010-11-22 15:13:01 -080084/* */
85/* Function: setup */
86/* */
subrata_modak1da30732009-05-21 18:47:14 +000087/* Description: Performs all one time setup for this test. This function is */
Garrett Cooperc5ed3e92010-11-22 15:13:01 -080088/* typically used to capture signals, create temporary dirs */
89/* and temporary files that may be used in the course of this */
90/* test. */
91/* */
92/* Input: None. */
93/* */
94/* Output: None. */
95/* */
96/* Return: On failure - Exits by calling cleanup(). */
97/* On success - returns 0. */
98/* */
subrata_modak1da30732009-05-21 18:47:14 +000099/******************************************************************************/
Mike Frysingerc57fba52014-04-09 18:56:30 -0400100void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800101{
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800102 /* Capture signals if any */
103 /* Create temporary directories */
104 TEST_PAUSE;
105 tst_tmpdir();
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400106
107 unused_tid = tst_get_unused_pid(cleanup);
subrata_modak1da30732009-05-21 18:47:14 +0000108}
109
110struct test_case_t {
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400111 int *tid;
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800112 int exp_errno;
subrata_modak1da30732009-05-21 18:47:14 +0000113} test_cases[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 {
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400115 &inval_tid, EINVAL}, {
116 &unused_tid, ESRCH}
subrata_modak1da30732009-05-21 18:47:14 +0000117};
118
Garrett Cooper53740502010-12-16 00:04:01 -0800119int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
120
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121int main(int ac, char **av)
122{
Garrett Cooper53740502010-12-16 00:04:01 -0800123 int i;
subrata_modak1da30732009-05-21 18:47:14 +0000124
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800125 setup();
subrata_modak1da30732009-05-21 18:47:14 +0000126
Garrett Cooper53740502010-12-16 00:04:01 -0800127 for (i = 0; i < TST_TOTAL; i++) {
subrata_modak1da30732009-05-21 18:47:14 +0000128
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400129 TEST(ltp_syscall(__NR_tkill, *(test_cases[i].tid), SIGUSR1));
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800130
Garrett Cooper53740502010-12-16 00:04:01 -0800131 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800132 if (TEST_ERRNO == test_cases[i].exp_errno) {
133 tst_resm(TPASS | TTERRNO,
134 "tkill(%d, SIGUSR1) failed as expected",
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400135 *(test_cases[i].tid));
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800136 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800137 tst_brkm(TFAIL | TTERRNO, cleanup,
138 "tkill(%d, SIGUSR1) failed unexpectedly",
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400139 *(test_cases[i].tid));
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800140 }
Garrett Cooper53740502010-12-16 00:04:01 -0800141 } else {
142 tst_brkm(TFAIL, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800143 "tkill(%d) succeeded unexpectedly",
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400144 *(test_cases[i].tid));
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800145 }
146 }
subrata_modak1da30732009-05-21 18:47:14 +0000147 cleanup();
Garrett Cooperc5ed3e92010-11-22 15:13:01 -0800148 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700149}