blob: ec350b11b3f6606add8fc14d246fcce043c4f4bb [file] [log] [blame]
subrata_modak2a6db062009-05-21 18:24:15 +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_modak2a6db062009-05-21 18:24:15 +000017/* */
18/******************************************************************************/
19/******************************************************************************/
20/* */
21/* File: rt_sigprocmask02.c */
22/* */
23/* Description: This tests the rt_sigprocmask() syscall */
24/* rt_sigprocmask changes the list of currently blocked signals. */
25/* The set value stores the signal mask of the pending signals. */
26/* The previous action on the signal is saved in oact. The value */
27/* of how indicates how the call should behave; its values are */
28/* as follows: */
29/* */
30/* SIG_BLOCK */
Garrett Cooper2c282152010-12-16 00:55:50 -080031/* The set of blocked signals is the union of the current set*/
subrata_modak2a6db062009-05-21 18:24:15 +000032/* and the set argument. */
33/* SIG_UNBLOCK */
34/* The signals in set are removed from the current set of */
35/* blocked signals. It is okay to unblock a signal that is */
36/* not blocked. */
37/* SIG_SETMASK */
38/* The set of blocked signals is set to the set argument. */
39/* sigsetsize should indicate the size of a sigset_t type. */
Garrett Cooper2c282152010-12-16 00:55:50 -080040/* */
subrata_modak2a6db062009-05-21 18:24:15 +000041/* RETURN VALUE:i */
Garrett Cooper2c282152010-12-16 00:55:50 -080042/* rt_sigprocmask returns 0 on success; otherwise, rt_sigprocmask*/
subrata_modak2a6db062009-05-21 18:24:15 +000043/* returns one of the errors listed in the "Errors" section. */
44/* */
45/* Errors: */
Garrett Cooper2c282152010-12-16 00:55:50 -080046/* -EINVAL */
subrata_modak2a6db062009-05-21 18:24:15 +000047/* sigsetsize was not equivalent to the size of a */
48/* sigset_t type or the value specified in how was */
49/* invalid. */
50/* -EFAULT */
51/* An invalid set, act, or oact was specified. */
52/* */
53/* */
54/* Usage: <for command-line> */
55/* rt_sigprocmask02 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
56/* where, -c n : Run n copies concurrently. */
57/* -e : Turn on errno logging. */
58/* -i n : Execute test n times. */
59/* -I x : Execute test for x seconds. */
60/* -P x : Pause for x seconds between iterations. */
61/* -t : Turn on syscall timing. */
62/* */
63/* Total Tests: 1 */
64/* */
65/* Test Name: rt_sigprocmask02 */
66/* History: Porting from Crackerjack to LTP is done by */
67/* Manas Kumar Nayak maknayak@in.ibm.com> */
68/******************************************************************************/
69#include <stdio.h>
70#include <signal.h>
71#include <errno.h>
72
73/* Harness Specific Include Files. */
74#include "test.h"
75#include "usctest.h"
76#include "linux_syscall_numbers.h"
yaberauneya250cc8e2009-11-26 12:04:59 +000077#include "ltp_signal.h"
subrata_modak2a6db062009-05-21 18:24:15 +000078
79/* Extern Global Variables */
subrata_modak2a6db062009-05-21 18:24:15 +000080
81/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080082char *TCID = "rt_sigprocmask02"; /* Test program identifier. */
83int TST_TOTAL = 2; /* total number of tests in this file. */
subrata_modak2a6db062009-05-21 18:24:15 +000084
85/* Extern Global Functions */
86/******************************************************************************/
87/* */
88/* Function: cleanup */
89/* */
90/* Description: Performs all one time clean up for this test on successful */
91/* completion, premature exit or failure. Closes all temporary */
92/* files, removes all temporary directories exits the test with */
93/* appropriate return code by calling tst_exit() function. */
94/* */
95/* Input: None. */
96/* */
97/* Output: None. */
98/* */
99/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
100/* On success - Exits calling tst_exit(). With '0' return code. */
101/* */
102/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800103extern void cleanup()
104{
Garrett Cooper2c282152010-12-16 00:55:50 -0800105
yaberauneya250cc8e2009-11-26 12:04:59 +0000106 TEST_CLEANUP;
107 tst_rmdir();
subrata_modak2a6db062009-05-21 18:24:15 +0000108
subrata_modak2a6db062009-05-21 18:24:15 +0000109}
110
111/* Local Functions */
112/******************************************************************************/
113/* */
114/* Function: setup */
115/* */
116/* Description: Performs all one time setup for this test. This function is */
117/* typically used to capture signals, create temporary dirs */
118/* and temporary files that may be used in the course of this */
119/* test. */
120/* */
121/* Input: None. */
122/* */
123/* Output: None. */
124/* */
125/* Return: On failure - Exits by calling cleanup(). */
126/* On success - returns 0. */
127/* */
128/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129void setup()
130{
yaberauneya250cc8e2009-11-26 12:04:59 +0000131 /* Capture signals if any */
132 /* Create temporary directories */
133 TEST_PAUSE;
134 tst_tmpdir();
subrata_modak2a6db062009-05-21 18:24:15 +0000135}
136
137sigset_t set;
138
139struct test_case_t {
yaberauneya250cc8e2009-11-26 12:04:59 +0000140 sigset_t *ss;
141 int sssize;
142 int exp_errno;
subrata_modak2a6db062009-05-21 18:24:15 +0000143} test_cases[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800144 {
145 &set, 1, EINVAL}, {
146 (sigset_t *) - 1, SIGSETSIZE, EFAULT}
subrata_modak2a6db062009-05-21 18:24:15 +0000147};
148
149int test_count = sizeof(test_cases) / sizeof(struct test_case_t);
150
Wanlong Gao354ebb42012-12-07 10:10:04 +0800151int main(int ac, char **av)
152{
yaberauneya250cc8e2009-11-26 12:04:59 +0000153 int i;
154 sigset_t s;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200155 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);
yaberauneya250cc8e2009-11-26 12:04:59 +0000159 tst_exit();
160 }
subrata_modak2a6db062009-05-21 18:24:15 +0000161
yaberauneya250cc8e2009-11-26 12:04:59 +0000162 setup();
subrata_modak2a6db062009-05-21 18:24:15 +0000163
yaberauneya250cc8e2009-11-26 12:04:59 +0000164 Tst_count = 0;
subrata_modak2a6db062009-05-21 18:24:15 +0000165
yaberauneya250cc8e2009-11-26 12:04:59 +0000166 TEST(sigfillset(&s));
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800167 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800168 tst_resm(TFAIL | TTERRNO, "Call to sigfillset() failed.");
yaberauneya250cc8e2009-11-26 12:04:59 +0000169 cleanup();
170 tst_exit();
171 }
subrata_modak2a6db062009-05-21 18:24:15 +0000172
Wanlong Gao354ebb42012-12-07 10:10:04 +0800173 for (i = 0; i < test_count; i++) {
Jan Stancek359980f2013-02-15 10:16:05 +0100174 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800175 &s, test_cases[i].ss, test_cases[i].sssize));
yaberauneya250cc8e2009-11-26 12:04:59 +0000176 if (TEST_RETURN == 0) {
177 tst_resm(TFAIL | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800178 "Call to rt_sigprocmask() succeeded, "
179 "but should failed");
yaberauneya250cc8e2009-11-26 12:04:59 +0000180 } else if (TEST_ERRNO == test_cases[i].exp_errno) {
181 tst_resm(TPASS | TTERRNO, "Got expected errno");
182 } else {
183 tst_resm(TFAIL | TTERRNO, "Got unexpected errno");
184 }
subrata_modak2a6db062009-05-21 18:24:15 +0000185
yaberauneya250cc8e2009-11-26 12:04:59 +0000186 }
187
188 cleanup();
189 tst_exit();
190
Chris Dearmanec6edca2012-10-17 19:54:01 -0700191}