blob: 345c38989715285a0a4c6e3ef55ed09b0855c417 [file] [log] [blame]
subrata_modakbb190cd2009-07-06 15:24:06 +00001/******************************************************************************/
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 */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080016/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modakbb190cd2009-07-06 15:24:06 +000017/* */
18/******************************************************************************/
19/******************************************************************************/
20/* */
21/* File: rt_sigaction03.c */
22/* */
23/* Description: This tests the rt_sigaction() syscall */
24/* rt_sigaction Expected EINVAL error check */
25/* */
26/* Usage: <for command-line> */
27/* rt_sigaction03 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
28/* where, -c n : Run n copies concurrently. */
29/* -e : Turn on errno logging. */
30/* -i n : Execute test n times. */
31/* -I x : Execute test for x seconds. */
32/* -P x : Pause for x seconds between iterations. */
33/* -t : Turn on syscall timing. */
34/* */
35/* Total Tests: 1 */
36/* */
37/* Test Name: rt_sigaction03 */
38/* History: Porting from Crackerjack to LTP is done by */
39/* Manas Kumar Nayak maknayak@in.ibm.com> */
40/******************************************************************************/
41#include <stdio.h>
42#include <stdlib.h>
43#include <unistd.h>
44#include <signal.h>
45#include <errno.h>
46#include <sys/syscall.h>
47#include <string.h>
48
49/* Harness Specific Include Files. */
50#include "test.h"
51#include "usctest.h"
52#include "linux_syscall_numbers.h"
53
54#define INVAL_SIGSETSIZE -1
55
56/* Extern Global Variables */
subrata_modakbb190cd2009-07-06 15:24:06 +000057
58/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080059char *TCID = "rt_sigaction03"; /* Test program identifier. */
60int testno;
61int TST_TOTAL = 1; /* total number of tests in this file. */
subrata_modakbb190cd2009-07-06 15:24:06 +000062
63/* Extern Global Functions */
64/******************************************************************************/
65/* */
66/* Function: cleanup */
67/* */
68/* Description: Performs all one time clean up for this test on successful */
69/* completion, premature exit or failure. Closes all temporary */
70/* files, removes all temporary directories exits the test with */
71/* appropriate return code by calling tst_exit() function. */
72/* */
73/* Input: None. */
74/* */
75/* Output: None. */
76/* */
77/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
78/* On success - Exits calling tst_exit(). With '0' return code. */
79/* */
80/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080081extern void cleanup()
82{
Garrett Cooper2c282152010-12-16 00:55:50 -080083
Wanlong Gao354ebb42012-12-07 10:10:04 +080084 TEST_CLEANUP;
85 tst_rmdir();
subrata_modakbb190cd2009-07-06 15:24:06 +000086
Wanlong Gao354ebb42012-12-07 10:10:04 +080087 tst_exit();
subrata_modakbb190cd2009-07-06 15:24:06 +000088}
89
90/* Local Functions */
91/******************************************************************************/
92/* */
93/* Function: setup */
94/* */
95/* Description: Performs all one time setup for this test. This function is */
96/* typically used to capture signals, create temporary dirs */
97/* and temporary files that may be used in the course of this */
98/* test. */
99/* */
100/* Input: None. */
101/* */
102/* Output: None. */
103/* */
104/* Return: On failure - Exits by calling cleanup(). */
105/* On success - returns 0. */
106/* */
107/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800108void setup()
109{
110 /* Capture signals if any */
111 /* Create temporary directories */
112 TEST_PAUSE;
113 tst_tmpdir();
subrata_modakbb190cd2009-07-06 15:24:06 +0000114}
115
Wanlong Gao354ebb42012-12-07 10:10:04 +0800116int test_flags[] =
117 { SA_RESETHAND | SA_SIGINFO, SA_RESETHAND, SA_RESETHAND | SA_SIGINFO,
118SA_RESETHAND | SA_SIGINFO, SA_NOMASK };
119char *test_flags_list[] =
120 { "SA_RESETHAND|SA_SIGINFO", "SA_RESETHAND", "SA_RESETHAND|SA_SIGINFO",
121"SA_RESETHAND|SA_SIGINFO", "SA_NOMASK" };
subrata_modakbb190cd2009-07-06 15:24:06 +0000122
subrata_modakbb190cd2009-07-06 15:24:06 +0000123struct test_case_t {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124 int exp_errno;
125 char *errdesc;
subrata_modakbb190cd2009-07-06 15:24:06 +0000126} test_cases[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800127 {
128 EINVAL, "EINVAL"}
subrata_modakbb190cd2009-07-06 15:24:06 +0000129};
130
Wanlong Gao354ebb42012-12-07 10:10:04 +0800131void handler(int sig)
subrata_modakbb190cd2009-07-06 15:24:06 +0000132{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800133 tst_resm(TINFO, "Signal Handler Called with signal number %d\n", sig);
134 return;
subrata_modakbb190cd2009-07-06 15:24:06 +0000135}
136
Wanlong Gao354ebb42012-12-07 10:10:04 +0800137int set_handler(int sig, int sig_to_mask, int mask_flags)
subrata_modakbb190cd2009-07-06 15:24:06 +0000138{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800139 struct sigaction sa, oldaction;
subrata_modakbb190cd2009-07-06 15:24:06 +0000140
Wanlong Gao354ebb42012-12-07 10:10:04 +0800141 sa.sa_sigaction = (void *)handler;
142 sa.sa_flags = mask_flags;
143 sigemptyset(&sa.sa_mask);
144 sigaddset(&sa.sa_mask, sig_to_mask);
subrata_modakbb190cd2009-07-06 15:24:06 +0000145
Wanlong Gao354ebb42012-12-07 10:10:04 +0800146 /* *
147 * long sys_rt_sigaction (int sig, const struct sigaction *act, *
148 * truct sigaction *oact, size_t sigsetsize); *
149 * EINVAL: *
150 * sigsetsize was not equivalent to the size of a sigset_t type *
151 */
subrata_modakbb190cd2009-07-06 15:24:06 +0000152
Jan Stancek359980f2013-02-15 10:16:05 +0100153 TEST(ltp_syscall
Wanlong Gao354ebb42012-12-07 10:10:04 +0800154 (__NR_rt_sigaction, sig, &sa, &oldaction, INVAL_SIGSETSIZE));
155 if (TEST_RETURN == 0) {
156 return 0;
157 } else {
158 return TEST_RETURN;
159 }
subrata_modakbb190cd2009-07-06 15:24:06 +0000160}
161
Wanlong Gao354ebb42012-12-07 10:10:04 +0800162int main(int ac, char **av)
163{
subrata_modakbb190cd2009-07-06 15:24:06 +0000164 int signal, flag;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200165 int lc;
166 char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800167
Wanlong Gao354ebb42012-12-07 10:10:04 +0800168 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
169 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
170 tst_exit();
171 }
subrata_modakbb190cd2009-07-06 15:24:06 +0000172
Wanlong Gao354ebb42012-12-07 10:10:04 +0800173 setup();
subrata_modakbb190cd2009-07-06 15:24:06 +0000174
Wanlong Gao354ebb42012-12-07 10:10:04 +0800175 for (lc = 0; TEST_LOOPING(lc); ++lc) {
176 Tst_count = 0;
177 for (testno = 0; testno < TST_TOTAL; ++testno) {
Garrett Cooper2c282152010-12-16 00:55:50 -0800178
Wanlong Gao354ebb42012-12-07 10:10:04 +0800179 for (signal = SIGRTMIN; signal <= (SIGRTMAX); signal++) { //signal for 34 to 65
180 for (flag = 0; flag < 5; flag++) {
181 TEST(set_handler
182 (signal, 0, test_flags[flag]));
183 if ((TEST_RETURN == -1)
184 && (TEST_ERRNO ==
185 test_cases[0].exp_errno)) {
186 tst_resm(TINFO,
187 "sa.sa_flags = %s ",
188 test_flags_list[flag]);
189 tst_resm(TPASS,
190 "%s failure with sig: %d as expected errno = %s : %s",
191 TCID, signal,
192 test_cases[0].errdesc,
193 strerror(TEST_ERRNO));
194 } else {
195 tst_resm(TFAIL,
196 "rt_sigaction call succeeded: result = %ld got error %d:but expected %d",
197 TEST_RETURN,
198 TEST_ERRNO,
199 test_cases[0].
200 exp_errno);
201 tst_resm(TINFO,
202 "sa.sa_flags = %s ",
203 test_flags_list[flag]);
204 }
205 }
206 printf("\n");
207 }
subrata_modakbb190cd2009-07-06 15:24:06 +0000208
Wanlong Gao354ebb42012-12-07 10:10:04 +0800209 }
210 }
subrata_modakbb190cd2009-07-06 15:24:06 +0000211 cleanup();
Wanlong Gao354ebb42012-12-07 10:10:04 +0800212 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700213}