blob: d6224d87e7c5701fb6b810aabfea79b08f28132b [file] [log] [blame]
subrata_modakb2644322009-05-21 18:23:00 +00001/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +00002/* Copyright (c) Crackerjack Project., 2007 */
3/* */
subrata_modakb2644322009-05-21 18:23:00 +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 */
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040015/* along with this program; if not, write to the Free Software Foundation, */
16/* Inc., 59 Temple Place, Suite TEST_SIG0, Boston, MA 02111-1307 USA */
yaberauneya5833cc62010-01-26 08:24:52 +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_modakb2644322009-05-21 18:23:00 +000020/******************************************************************************/
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040021
subrata_modakb2644322009-05-21 18:23:00 +000022/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +000023/* Description: This tests the rt_sigprocmask() syscall */
subrata_modakb2644322009-05-21 18:23:00 +000024/* 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*/
Cyril Hrubis22f069f2014-06-26 16:31:05 +020032/* and the set argument. */
subrata_modakb2644322009-05-21 18:23:00 +000033/* 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 */
Cyril Hrubis22f069f2014-06-26 16:31:05 +020036/* not blocked. */
subrata_modakb2644322009-05-21 18:23:00 +000037/* 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. */
subrata_modakb2644322009-05-21 18:23:00 +000040/******************************************************************************/
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040041
subrata_modakb2644322009-05-21 18:23:00 +000042#include <stdio.h>
yaberauneya5833cc62010-01-26 08:24:52 +000043#include <signal.h>
subrata_modakb2644322009-05-21 18:23:00 +000044#include <errno.h>
45
subrata_modakb2644322009-05-21 18:23:00 +000046#include "test.h"
subrata_modakb2644322009-05-21 18:23:00 +000047#include "linux_syscall_numbers.h"
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +040048#include "lapi/rt_sigaction.h"
subrata_modakb2644322009-05-21 18:23:00 +000049
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020050char *TCID = "rt_sigprocmask01";
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040051static int testno;
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020052int TST_TOTAL = 8;
subrata_modakb2644322009-05-21 18:23:00 +000053
Cyril Hrubis22f069f2014-06-26 16:31:05 +020054static volatile sig_atomic_t sig_count;
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040055
Garrett Cooper85a17552010-02-26 20:10:07 -080056#define TEST_SIG SIGRTMIN+1
57
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040058static void cleanup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080059{
Garrett Cooper85a17552010-02-26 20:10:07 -080060 tst_rmdir();
subrata_modakb2644322009-05-21 18:23:00 +000061}
62
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040063static void setup(void)
Wanlong Gao354ebb42012-12-07 10:10:04 +080064{
Garrett Cooper85a17552010-02-26 20:10:07 -080065 TEST_PAUSE;
66 tst_tmpdir();
subrata_modakb2644322009-05-21 18:23:00 +000067}
68
subrata_modakb2644322009-05-21 18:23:00 +000069void sig_handler(int sig)
70{
Garrett Cooper85a17552010-02-26 20:10:07 -080071 sig_count++;
subrata_modakb2644322009-05-21 18:23:00 +000072}
73
Wanlong Gao354ebb42012-12-07 10:10:04 +080074int main(int ac, char **av)
75{
subrata_modakb2644322009-05-21 18:23:00 +000076 struct sigaction act, oact;
Wanlong Gao354ebb42012-12-07 10:10:04 +080077 memset(&act, 0, sizeof(act));
78 memset(&oact, 0, sizeof(oact));
Garrett Cooper85a17552010-02-26 20:10:07 -080079 act.sa_handler = sig_handler;
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +040080
Garrett Cooper85a17552010-02-26 20:10:07 -080081 sigset_t set, oset;
Cyril Hrubis89af32a2012-10-24 16:39:11 +020082 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020083 const char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -080084
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040085 msg = parse_opts(ac, av, NULL, NULL);
86 if (msg != NULL)
Wanlong Gao354ebb42012-12-07 10:10:04 +080087 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
subrata_modakb2644322009-05-21 18:23:00 +000088
Garrett Cooper85a17552010-02-26 20:10:07 -080089 setup();
subrata_modakb2644322009-05-21 18:23:00 +000090
Garrett Cooper85a17552010-02-26 20:10:07 -080091 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080092 tst_count = 0;
Wanlong Gao354ebb42012-12-07 10:10:04 +080093 for (testno = 0; testno < TST_TOTAL; ++testno) {
Garrett Cooper85a17552010-02-26 20:10:07 -080094
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040095 if (sigemptyset(&set) < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +080096 tst_brkm(TFAIL | TERRNO, cleanup,
97 "sigemptyset call failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +040098
99 if (sigaddset(&set, TEST_SIG) < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100 tst_brkm(TFAIL | TERRNO, cleanup,
101 "sigaddset call failed");
Garrett Cooper85a17552010-02-26 20:10:07 -0800102
yaberauneya5833cc62010-01-26 08:24:52 +0000103 /* call rt_sigaction() */
Stanislav Kholmanskikhea537012014-06-17 13:08:17 +0400104 TEST(ltp_rt_sigaction(TEST_SIG, &act, &oact,
105 SIGSETSIZE));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400106 if (TEST_RETURN < 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107 tst_brkm(TFAIL | TTERRNO, cleanup,
108 "rt_sigaction call failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400109
Garrett Cooper85a17552010-02-26 20:10:07 -0800110 /* call rt_sigprocmask() to block signal#TEST_SIG */
Jan Stancek359980f2013-02-15 10:16:05 +0100111 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, &set,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800112 &oset, SIGSETSIZE));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400113 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800114 tst_brkm(TFAIL | TTERRNO, cleanup,
115 "rt_sigprocmask call failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400116
Garrett Cooper85a17552010-02-26 20:10:07 -0800117 /* Make sure that the masked process is indeed
118 * masked. */
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400119 if (kill(getpid(), TEST_SIG) < 0)
Garrett Cooper85a17552010-02-26 20:10:07 -0800120 tst_brkm(TFAIL | TERRNO, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800121 "call to kill() failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400122
Garrett Cooper85a17552010-02-26 20:10:07 -0800123 if (sig_count) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800124 tst_brkm(TFAIL | TERRNO, cleanup,
125 "rt_sigprocmask() failed to change "
126 "the process's signal mask");
Garrett Cooper85a17552010-02-26 20:10:07 -0800127 } else {
128 /* call rt_sigpending() */
Jan Stancek359980f2013-02-15 10:16:05 +0100129 TEST(ltp_syscall(__NR_rt_sigpending, &oset,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800130 SIGSETSIZE));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400131 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800132 tst_brkm(TFAIL | TTERRNO, cleanup,
133 "rt_sigpending call failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400134
Garrett Cooper85a17552010-02-26 20:10:07 -0800135 TEST(sigismember(&oset, TEST_SIG));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400136 if (TEST_RETURN == 0)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800137 tst_brkm(TFAIL | TTERRNO,
138 cleanup,
139 "sigismember call failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400140
Garrett Cooper85a17552010-02-26 20:10:07 -0800141 /* call rt_sigprocmask() to unblock
142 * signal#TEST_SIG */
Jan Stancek359980f2013-02-15 10:16:05 +0100143 TEST(ltp_syscall(__NR_rt_sigprocmask,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800144 SIG_UNBLOCK, &set, &oset,
145 SIGSETSIZE));
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400146 if (TEST_RETURN == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800147 tst_brkm(TFAIL | TTERRNO,
148 cleanup,
149 "rt_sigprocmask call failed");
Stanislav Kholmanskikh4d93b882014-06-17 13:08:16 +0400150
Garrett Cooper85a17552010-02-26 20:10:07 -0800151 if (sig_count) {
152 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800153 "rt_sigprocmask "
154 "functionality passed");
Garrett Cooper85a17552010-02-26 20:10:07 -0800155 break;
156 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800157 tst_brkm(TFAIL | TERRNO,
158 cleanup,
159 "rt_sigprocmask "
160 "functionality failed");
Garrett Cooper85a17552010-02-26 20:10:07 -0800161 }
yaberauneya5833cc62010-01-26 08:24:52 +0000162 }
subrata_modakb2644322009-05-21 18:23:00 +0000163
Wanlong Gao354ebb42012-12-07 10:10:04 +0800164 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800165
Caspar Zhangd59a6592013-03-07 14:59:12 +0800166 tst_count++;
Garrett Cooper85a17552010-02-26 20:10:07 -0800167
Garrett Cooper2c282152010-12-16 00:55:50 -0800168 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800169
170 cleanup();
Garrett Cooper2e3781d2011-01-20 01:05:22 -0800171 tst_exit();
172}