blob: b0830cd23afdd92febfaa8c12548b351bb09e754 [file] [log] [blame]
subrata_modak654da392009-05-21 18:20:58 +00001/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +00002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
subrata_modak654da392009-05-21 18:20:58 +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 */
yaberauneya5833cc62010-01-26 08:24:52 +00006/* 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 */
yaberauneya5833cc62010-01-26 08:24:52 +000017/* */
subrata_modak654da392009-05-21 18:20:58 +000018/******************************************************************************/
19/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +000020/* */
21/* File: rt_sigaction01.c */
22/* */
23/* Description: This tests the rt_sigaction() syscall */
subrata_modak654da392009-05-21 18:20:58 +000024/* rt_sigaction alters an action taken by a process on receipt */
yaberauneya5833cc62010-01-26 08:24:52 +000025/* of a particular signal. The action is specified by the */
subrata_modak654da392009-05-21 18:20:58 +000026/* sigaction structure. The previous action on the signal is */
yaberauneya5833cc62010-01-26 08:24:52 +000027/* saved in oact.sigsetsize should indicate the size of a */
28/* sigset_t type. */
29/* */
30/* Usage: <for command-line> */
31/* rt_sigaction01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
32/* where, -c n : Run n copies concurrently. */
33/* -e : Turn on errno logging. */
34/* -i n : Execute test n times. */
35/* -I x : Execute test for x seconds. */
36/* -P x : Pause for x seconds between iterations. */
37/* -t : Turn on syscall timing. */
38/* */
39/* Total Tests: 1 */
40/* */
41/* Test Name: rt_sigaction01 */
42/* History: Porting from Crackerjack to LTP is done by */
43/* Manas Kumar Nayak maknayak@in.ibm.com> */
subrata_modak654da392009-05-21 18:20:58 +000044/******************************************************************************/
45#include <stdio.h>
46#include <stdlib.h>
47#include <unistd.h>
yaberauneya5833cc62010-01-26 08:24:52 +000048#include <signal.h>
subrata_modak654da392009-05-21 18:20:58 +000049#include <errno.h>
yaberauneya5833cc62010-01-26 08:24:52 +000050#include <sys/syscall.h>
subrata_modak654da392009-05-21 18:20:58 +000051#include <string.h>
52
53/* Harness Specific Include Files. */
Garrett Cooper64fd9672010-02-26 05:12:13 -080054#define LTP_RT_SIG_TEST
subrata_modak654da392009-05-21 18:20:58 +000055#include "test.h"
56#include "usctest.h"
57#include "linux_syscall_numbers.h"
Garrett Cooper64fd9672010-02-26 05:12:13 -080058#include "ltp_signal.h"
subrata_modakbb190cd2009-07-06 15:24:06 +000059
subrata_modak654da392009-05-21 18:20:58 +000060/* Extern Global Variables */
subrata_modak654da392009-05-21 18:20:58 +000061
62/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080063char *TCID = "rt_sigaction01"; /* Test program identifier. */
64int testno;
65int TST_TOTAL = 1; /* total number of tests in this file. */
yaberauneya402ec1f2009-11-30 20:38:48 +000066
subrata_modak654da392009-05-21 18:20:58 +000067/* Extern Global Functions */
68/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +000069/* */
70/* Function: cleanup */
71/* */
subrata_modak654da392009-05-21 18:20:58 +000072/* Description: Performs all one time clean up for this test on successful */
yaberauneya5833cc62010-01-26 08:24:52 +000073/* completion, premature exit or failure. Closes all temporary */
74/* files, removes all temporary directories exits the test with */
75/* appropriate return code by calling tst_exit() function. */
76/* */
77/* Input: None. */
78/* */
79/* Output: None. */
80/* */
subrata_modak654da392009-05-21 18:20:58 +000081/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
yaberauneya5833cc62010-01-26 08:24:52 +000082/* On success - Exits calling tst_exit(). With '0' return code. */
83/* */
subrata_modak654da392009-05-21 18:20:58 +000084/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080085void cleanup()
86{
Garrett Cooper2c282152010-12-16 00:55:50 -080087
Garrett Cooper64fd9672010-02-26 05:12:13 -080088 TEST_CLEANUP;
89 tst_rmdir();
yaberauneya5833cc62010-01-26 08:24:52 +000090
subrata_modak654da392009-05-21 18:20:58 +000091}
92
93/* Local Functions */
94/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +000095/* */
96/* Function: setup */
97/* */
subrata_modak654da392009-05-21 18:20:58 +000098/* Description: Performs all one time setup for this test. This function is */
yaberauneya5833cc62010-01-26 08:24:52 +000099/* typically used to capture signals, create temporary dirs */
100/* and temporary files that may be used in the course of this */
101/* test. */
102/* */
103/* Input: None. */
104/* */
105/* Output: None. */
106/* */
107/* Return: On failure - Exits by calling cleanup(). */
108/* On success - returns 0. */
109/* */
subrata_modak654da392009-05-21 18:20:58 +0000110/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800111void setup()
112{
Garrett Cooper64fd9672010-02-26 05:12:13 -0800113 /* Capture signals if any */
114 /* Create temporary directories */
115 TEST_PAUSE;
116 tst_tmpdir();
subrata_modak654da392009-05-21 18:20:58 +0000117}
118
Wanlong Gao354ebb42012-12-07 10:10:04 +0800119int test_flags[] =
120 { SA_RESETHAND | SA_SIGINFO, SA_RESETHAND, SA_RESETHAND | SA_SIGINFO,
121SA_RESETHAND | SA_SIGINFO, SA_NOMASK };
122char *test_flags_list[] =
123 { "SA_RESETHAND|SA_SIGINFO", "SA_RESETHAND", "SA_RESETHAND|SA_SIGINFO",
124"SA_RESETHAND|SA_SIGINFO", "SA_NOMASK" };
yaberauneya5833cc62010-01-26 08:24:52 +0000125
Wanlong Gao354ebb42012-12-07 10:10:04 +0800126void handler(int sig)
subrata_modak654da392009-05-21 18:20:58 +0000127{
Garrett Cooper64fd9672010-02-26 05:12:13 -0800128 tst_resm(TINFO, "Signal Handler Called with signal number %d\n", sig);
129 return;
subrata_modak654da392009-05-21 18:20:58 +0000130}
131
Wanlong Gao354ebb42012-12-07 10:10:04 +0800132int set_handler(int sig, int sig_to_mask, int mask_flags)
subrata_modak654da392009-05-21 18:20:58 +0000133{
Garrett Cooper64fd9672010-02-26 05:12:13 -0800134#ifdef __x86_64__
135 struct kernel_sigaction sa, oldaction;
136 mask_flags |= SA_RESTORER;
137 sa.sa_restorer = restore_rt;
138 sa.k_sa_handler = (void *)handler;
139#else
140 struct sigaction sa, oldaction;
141 sa.sa_handler = (void *)handler;
142#endif
143 sa.sa_flags = mask_flags;
144 sigemptyset(&sa.sa_mask);
145 sigaddset(&sa.sa_mask, sig);
subrata_modak654da392009-05-21 18:20:58 +0000146
Jan Stancek359980f2013-02-15 10:16:05 +0100147 return ltp_syscall(__NR_rt_sigaction, sig, &sa, &oldaction, SIGSETSIZE);
Garrett Cooper64fd9672010-02-26 05:12:13 -0800148
subrata_modak654da392009-05-21 18:20:58 +0000149}
150
Wanlong Gao354ebb42012-12-07 10:10:04 +0800151int main(int ac, char **av)
152{
yaberauneya5833cc62010-01-26 08:24:52 +0000153 int signal, flag;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200154 int lc;
155 char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800156
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800157 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -0800158 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper64fd9672010-02-26 05:12:13 -0800159 }
yaberauneya1979ba32009-11-26 14:30:42 +0000160
Garrett Cooper64fd9672010-02-26 05:12:13 -0800161 setup();
yaberauneya1979ba32009-11-26 14:30:42 +0000162
Garrett Cooper64fd9672010-02-26 05:12:13 -0800163 for (lc = 0; TEST_LOOPING(lc); ++lc) {
164
165 Tst_count = 0;
166
167 for (testno = 0; testno < TST_TOTAL; ++testno) {
168
Wanlong Gao354ebb42012-12-07 10:10:04 +0800169 for (signal = SIGRTMIN; signal <= (SIGRTMAX); signal++) { //signal for 34 to 65
Garrett Cooper64fd9672010-02-26 05:12:13 -0800170
171#ifdef __x86_64__
172 sig_initial(signal);
173#endif
174
Wanlong Gao354ebb42012-12-07 10:10:04 +0800175 for (flag = 0;
176 flag <
177 (sizeof(test_flags) /
178 sizeof(test_flags[0])); flag++) {
Garrett Cooper64fd9672010-02-26 05:12:13 -0800179
Wanlong Gao354ebb42012-12-07 10:10:04 +0800180 TEST(set_handler
181 (signal, 0, test_flags[flag]));
Garrett Cooper64fd9672010-02-26 05:12:13 -0800182
183 if (TEST_RETURN == 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800184 tst_resm(TINFO, "signal: %d ",
185 signal);
186 tst_resm(TPASS,
187 "rt_sigaction call succeeded: result = %ld ",
188 TEST_RETURN);
189 tst_resm(TINFO,
190 "sa.sa_flags = %s ",
191 test_flags_list[flag]);
192 kill(getpid(), signal);
Garrett Cooper64fd9672010-02-26 05:12:13 -0800193 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800194 tst_resm(TFAIL | TTERRNO,
195 "rt_sigaction call "
196 "failed");
197 }
yaberauneya1979ba32009-11-26 14:30:42 +0000198
Wanlong Gao354ebb42012-12-07 10:10:04 +0800199 }
yaberauneya402ec1f2009-11-30 20:38:48 +0000200
Garrett Cooper64fd9672010-02-26 05:12:13 -0800201 }
yaberauneya402ec1f2009-11-30 20:38:48 +0000202
Wanlong Gao354ebb42012-12-07 10:10:04 +0800203 }
Garrett Cooper64fd9672010-02-26 05:12:13 -0800204
Garrett Cooper2c282152010-12-16 00:55:50 -0800205 }
subrata_modakbb190cd2009-07-06 15:24:06 +0000206 cleanup();
Garrett Cooper2c282152010-12-16 00:55:50 -0800207 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700208}