blob: f7d84c3fa165fe65a3a9e24fe87589c14cb1db60 [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 */
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040015/* along with this program; if not, write to the Free Software Foundation, */
16/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
subrata_modak2a6db062009-05-21 18:24:15 +000017/* */
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040018/* History: Porting from Crackerjack to LTP is done by */
19/* Manas Kumar Nayak maknayak@in.ibm.com> */
subrata_modak2a6db062009-05-21 18:24:15 +000020/******************************************************************************/
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040021
subrata_modak2a6db062009-05-21 18:24:15 +000022/******************************************************************************/
subrata_modak2a6db062009-05-21 18:24:15 +000023/* 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. */
subrata_modak2a6db062009-05-21 18:24:15 +000052/******************************************************************************/
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040053
subrata_modak2a6db062009-05-21 18:24:15 +000054#include <stdio.h>
55#include <signal.h>
56#include <errno.h>
57
subrata_modak2a6db062009-05-21 18:24:15 +000058#include "test.h"
subrata_modak2a6db062009-05-21 18:24:15 +000059#include "linux_syscall_numbers.h"
yaberauneya250cc8e2009-11-26 12:04:59 +000060#include "ltp_signal.h"
subrata_modak2a6db062009-05-21 18:24:15 +000061
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020062char *TCID = "rt_sigprocmask02";
63int TST_TOTAL = 2;
subrata_modak2a6db062009-05-21 18:24:15 +000064
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040065static void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080066{
yaberauneya250cc8e2009-11-26 12:04:59 +000067 tst_rmdir();
subrata_modak2a6db062009-05-21 18:24:15 +000068}
69
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040070static void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080071{
yaberauneya250cc8e2009-11-26 12:04:59 +000072 TEST_PAUSE;
73 tst_tmpdir();
subrata_modak2a6db062009-05-21 18:24:15 +000074}
75
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040076static sigset_t set;
subrata_modak2a6db062009-05-21 18:24:15 +000077
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040078static struct test_case_t {
yaberauneya250cc8e2009-11-26 12:04:59 +000079 sigset_t *ss;
80 int sssize;
81 int exp_errno;
subrata_modak2a6db062009-05-21 18:24:15 +000082} test_cases[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +080083 {
84 &set, 1, EINVAL}, {
85 (sigset_t *) - 1, SIGSETSIZE, EFAULT}
subrata_modak2a6db062009-05-21 18:24:15 +000086};
87
88int test_count = sizeof(test_cases) / sizeof(struct test_case_t);
89
Wanlong Gao354ebb42012-12-07 10:10:04 +080090int main(int ac, char **av)
91{
yaberauneya250cc8e2009-11-26 12:04:59 +000092 int i;
93 sigset_t s;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020094 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -080095
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040096 msg = parse_opts(ac, av, NULL, NULL);
97 if (msg != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080098 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modak2a6db062009-05-21 18:24:15 +000099
yaberauneya250cc8e2009-11-26 12:04:59 +0000100 setup();
subrata_modak2a6db062009-05-21 18:24:15 +0000101
Caspar Zhangd59a6592013-03-07 14:59:12 +0800102 tst_count = 0;
subrata_modak2a6db062009-05-21 18:24:15 +0000103
yaberauneya250cc8e2009-11-26 12:04:59 +0000104 TEST(sigfillset(&s));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400105 if (TEST_RETURN == -1)
106 tst_brkm(TFAIL | TTERRNO, cleanup,
107 "Call to sigfillset() failed.");
subrata_modak2a6db062009-05-21 18:24:15 +0000108
Wanlong Gao354ebb42012-12-07 10:10:04 +0800109 for (i = 0; i < test_count; i++) {
Jan Stancek359980f2013-02-15 10:16:05 +0100110 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800111 &s, test_cases[i].ss, test_cases[i].sssize));
yaberauneya250cc8e2009-11-26 12:04:59 +0000112 if (TEST_RETURN == 0) {
113 tst_resm(TFAIL | TTERRNO,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 "Call to rt_sigprocmask() succeeded, "
115 "but should failed");
yaberauneya250cc8e2009-11-26 12:04:59 +0000116 } else if (TEST_ERRNO == test_cases[i].exp_errno) {
117 tst_resm(TPASS | TTERRNO, "Got expected errno");
118 } else {
119 tst_resm(TFAIL | TTERRNO, "Got unexpected errno");
120 }
subrata_modak2a6db062009-05-21 18:24:15 +0000121
yaberauneya250cc8e2009-11-26 12:04:59 +0000122 }
123
124 cleanup();
125 tst_exit();
Chris Dearmanec6edca2012-10-17 19:54:01 -0700126}