blob: 3b2dfbb8e97acc7380070efde30286a9927c5749 [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 */
15/* along with this program; if not, write to the Free Software */
Garrett Cooper85a17552010-02-26 20:10:07 -080016/* Foundation, Inc., 59 Temple Place, Suite TEST_SIG0, Boston, MA 02111-1307 USA */
yaberauneya5833cc62010-01-26 08:24:52 +000017/* */
subrata_modakb2644322009-05-21 18:23:00 +000018/******************************************************************************/
19/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +000020/* */
21/* File: rt_sigprocmask01.c */
22/* */
23/* 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*/
subrata_modakb2644322009-05-21 18:23:00 +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. */
yaberauneya5833cc62010-01-26 08:24:52 +000040/* */
41/* Usage: <for command-line> */
42/* rt_sigprocmask01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */
43/* where, -c n : Run n copies concurrently. */
44/* -e : Turn on errno logging. */
45/* -i n : Execute test n times. */
46/* -I x : Execute test for x seconds. */
47/* -P x : Pause for x seconds between iterations. */
48/* -t : Turn on syscall timing. */
49/* */
50/* Total Tests: 1 */
51/* */
52/* Test Name: rt_sigprocmask01 */
53/* History: Porting from Crackerjack to LTP is done by */
Garrett Cooper85a17552010-02-26 20:10:07 -080054/* Manas Kumar Nayak <maknayak@in.ibm.com> */
subrata_modakb2644322009-05-21 18:23:00 +000055/******************************************************************************/
56#include <stdio.h>
yaberauneya5833cc62010-01-26 08:24:52 +000057#include <signal.h>
subrata_modakb2644322009-05-21 18:23:00 +000058#include <errno.h>
59
60/* Harness Specific Include Files. */
61#include "test.h"
62#include "usctest.h"
63#include "linux_syscall_numbers.h"
Garrett Cooper85a17552010-02-26 20:10:07 -080064#define LTP_RT_SIG_TEST
65#include "ltp_signal.h"
subrata_modakb2644322009-05-21 18:23:00 +000066
67/* Extern Global Variables */
subrata_modakb2644322009-05-21 18:23:00 +000068
69/* Global Variables */
Wanlong Gao354ebb42012-12-07 10:10:04 +080070char *TCID = "rt_sigprocmask01"; /* Test program identifier. */
71int testno;
72int TST_TOTAL = 8; /* total number of tests in this file. */
subrata_modakb2644322009-05-21 18:23:00 +000073
Garrett Cooper85a17552010-02-26 20:10:07 -080074#define TEST_SIG SIGRTMIN+1
75
subrata_modakb2644322009-05-21 18:23:00 +000076/* Extern Global Functions */
77/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +000078/* */
79/* Function: cleanup */
80/* */
subrata_modakb2644322009-05-21 18:23:00 +000081/* Description: Performs all one time clean up for this test on successful */
yaberauneya5833cc62010-01-26 08:24:52 +000082/* completion, premature exit or failure. Closes all temporary */
83/* files, removes all temporary directories exits the test with */
84/* appropriate return code by calling tst_exit() function. */
85/* */
86/* Input: None. */
87/* */
88/* Output: None. */
89/* */
subrata_modakb2644322009-05-21 18:23:00 +000090/* Return: On failure - Exits calling tst_exit(). Non '0' return code. */
yaberauneya5833cc62010-01-26 08:24:52 +000091/* On success - Exits calling tst_exit(). With '0' return code. */
92/* */
subrata_modakb2644322009-05-21 18:23:00 +000093/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +080094void cleanup()
95{
Garrett Cooper2c282152010-12-16 00:55:50 -080096
Garrett Cooper85a17552010-02-26 20:10:07 -080097 TEST_CLEANUP;
98 tst_rmdir();
Garrett Cooper2c282152010-12-16 00:55:50 -080099
subrata_modakb2644322009-05-21 18:23:00 +0000100}
101
102/* Local Functions */
103/******************************************************************************/
yaberauneya5833cc62010-01-26 08:24:52 +0000104/* */
105/* Function: setup */
106/* */
subrata_modakb2644322009-05-21 18:23:00 +0000107/* Description: Performs all one time setup for this test. This function is */
yaberauneya5833cc62010-01-26 08:24:52 +0000108/* typically used to capture signals, create temporary dirs */
109/* and temporary files that may be used in the course of this */
110/* test. */
111/* */
112/* Input: None. */
113/* */
114/* Output: None. */
115/* */
116/* Return: On failure - Exits by calling cleanup(). */
117/* On success - returns 0. */
118/* */
subrata_modakb2644322009-05-21 18:23:00 +0000119/******************************************************************************/
Wanlong Gao354ebb42012-12-07 10:10:04 +0800120void setup()
121{
Garrett Cooper85a17552010-02-26 20:10:07 -0800122 /* Capture signals if any */
123 /* Create temporary directories */
124 TEST_PAUSE;
125 tst_tmpdir();
subrata_modakb2644322009-05-21 18:23:00 +0000126}
127
128int sig_count = 0;
129
130void sig_handler(int sig)
131{
Garrett Cooper85a17552010-02-26 20:10:07 -0800132 sig_count++;
subrata_modakb2644322009-05-21 18:23:00 +0000133}
134
Wanlong Gao354ebb42012-12-07 10:10:04 +0800135int main(int ac, char **av)
136{
Garrett Cooper85a17552010-02-26 20:10:07 -0800137#if __x86_64
138 struct kernel_sigaction act, oact;
139 sig_initial(TEST_SIG);
140 act.sa_flags |= SA_RESTORER;
141 act.sa_restorer = restore_rt;
142 act.k_sa_handler = sig_handler;
143#else
subrata_modakb2644322009-05-21 18:23:00 +0000144 struct sigaction act, oact;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800145 memset(&act, 0, sizeof(act));
146 memset(&oact, 0, sizeof(oact));
Garrett Cooper85a17552010-02-26 20:10:07 -0800147 act.sa_handler = sig_handler;
148#endif
149 sigset_t set, oset;
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200150 int lc;
151 char *msg;
Garrett Cooper2c282152010-12-16 00:55:50 -0800152
Garrett Cooperdf3eb162010-11-28 22:44:32 -0800153 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800154 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Garrett Cooper85a17552010-02-26 20:10:07 -0800155 }
subrata_modakb2644322009-05-21 18:23:00 +0000156
Garrett Cooper85a17552010-02-26 20:10:07 -0800157 setup();
subrata_modakb2644322009-05-21 18:23:00 +0000158
Garrett Cooper85a17552010-02-26 20:10:07 -0800159 for (lc = 0; TEST_LOOPING(lc); ++lc) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800160 Tst_count = 0;
161 for (testno = 0; testno < TST_TOTAL; ++testno) {
Garrett Cooper85a17552010-02-26 20:10:07 -0800162
163 if (sigemptyset(&set) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800164 tst_brkm(TFAIL | TERRNO, cleanup,
165 "sigemptyset call failed");
yaberauneya5833cc62010-01-26 08:24:52 +0000166 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800167 if (sigaddset(&set, TEST_SIG) < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800168 tst_brkm(TFAIL | TERRNO, cleanup,
169 "sigaddset call failed");
yaberauneya5833cc62010-01-26 08:24:52 +0000170 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800171
yaberauneya5833cc62010-01-26 08:24:52 +0000172 /* call rt_sigaction() */
Jan Stancek359980f2013-02-15 10:16:05 +0100173 TEST(ltp_syscall(__NR_rt_sigaction, TEST_SIG, &act,
174 &oact, SIGSETSIZE));
Garrett Cooper85a17552010-02-26 20:10:07 -0800175 if (TEST_RETURN < 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800176 tst_brkm(TFAIL | TTERRNO, cleanup,
177 "rt_sigaction call failed");
yaberauneya5833cc62010-01-26 08:24:52 +0000178 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800179 /* call rt_sigprocmask() to block signal#TEST_SIG */
Jan Stancek359980f2013-02-15 10:16:05 +0100180 TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, &set,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800181 &oset, SIGSETSIZE));
Garrett Cooper85a17552010-02-26 20:10:07 -0800182 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800183 tst_brkm(TFAIL | TTERRNO, cleanup,
184 "rt_sigprocmask call failed");
yaberauneya5833cc62010-01-26 08:24:52 +0000185 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800186 /* Make sure that the masked process is indeed
187 * masked. */
188 if (kill(getpid(), TEST_SIG) < 0) {
189 tst_brkm(TFAIL | TERRNO, cleanup,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800190 "call to kill() failed");
Garrett Cooper85a17552010-02-26 20:10:07 -0800191 }
192 if (sig_count) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800193 tst_brkm(TFAIL | TERRNO, cleanup,
194 "rt_sigprocmask() failed to change "
195 "the process's signal mask");
Garrett Cooper85a17552010-02-26 20:10:07 -0800196 } else {
197 /* call rt_sigpending() */
Jan Stancek359980f2013-02-15 10:16:05 +0100198 TEST(ltp_syscall(__NR_rt_sigpending, &oset,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800199 SIGSETSIZE));
Garrett Cooper85a17552010-02-26 20:10:07 -0800200 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800201 tst_brkm(TFAIL | TTERRNO, cleanup,
202 "rt_sigpending call failed");
yaberauneya5833cc62010-01-26 08:24:52 +0000203 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800204 TEST(sigismember(&oset, TEST_SIG));
205 if (TEST_RETURN == 0) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800206 tst_brkm(TFAIL | TTERRNO,
207 cleanup,
208 "sigismember call failed");
yaberauneya5833cc62010-01-26 08:24:52 +0000209 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800210 /* call rt_sigprocmask() to unblock
211 * signal#TEST_SIG */
Jan Stancek359980f2013-02-15 10:16:05 +0100212 TEST(ltp_syscall(__NR_rt_sigprocmask,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800213 SIG_UNBLOCK, &set, &oset,
214 SIGSETSIZE));
Garrett Cooper85a17552010-02-26 20:10:07 -0800215 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800216 tst_brkm(TFAIL | TTERRNO,
217 cleanup,
218 "rt_sigprocmask call failed");
Garrett Cooper85a17552010-02-26 20:10:07 -0800219 }
220 if (sig_count) {
221 tst_resm(TPASS,
Wanlong Gao354ebb42012-12-07 10:10:04 +0800222 "rt_sigprocmask "
223 "functionality passed");
Garrett Cooper85a17552010-02-26 20:10:07 -0800224 break;
225 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800226 tst_brkm(TFAIL | TERRNO,
227 cleanup,
228 "rt_sigprocmask "
229 "functionality failed");
Garrett Cooper85a17552010-02-26 20:10:07 -0800230 }
subrata_modakb2644322009-05-21 18:23:00 +0000231
yaberauneya5833cc62010-01-26 08:24:52 +0000232 }
subrata_modakb2644322009-05-21 18:23:00 +0000233
Wanlong Gao354ebb42012-12-07 10:10:04 +0800234 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800235
236 Tst_count++;
237
Garrett Cooper2c282152010-12-16 00:55:50 -0800238 }
Garrett Cooper85a17552010-02-26 20:10:07 -0800239
240 cleanup();
Garrett Cooper2e3781d2011-01-20 01:05:22 -0800241 tst_exit();
242}