subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 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 */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 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 */ |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 16 | /* Foundation, Inc., 59 Temple Place, Suite TEST_SIG0, Boston, MA 02111-1307 USA */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 17 | /* */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 20 | /* */ |
| 21 | /* File: rt_sigprocmask01.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the rt_sigprocmask() syscall */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 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 Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 31 | /* The set of blocked signals is the union of the current set*/ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 32 | /* 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. */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 40 | /* */ |
| 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 Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 54 | /* Manas Kumar Nayak <maknayak@in.ibm.com> */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 55 | /******************************************************************************/ |
| 56 | #include <stdio.h> |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 57 | #include <signal.h> |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 58 | #include <errno.h> |
| 59 | |
| 60 | /* Harness Specific Include Files. */ |
| 61 | #include "test.h" |
| 62 | #include "usctest.h" |
| 63 | #include "linux_syscall_numbers.h" |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 64 | #define LTP_RT_SIG_TEST |
| 65 | #include "ltp_signal.h" |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 66 | |
| 67 | /* Extern Global Variables */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 68 | |
| 69 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 70 | char *TCID = "rt_sigprocmask01"; /* Test program identifier. */ |
| 71 | int testno; |
| 72 | int TST_TOTAL = 8; /* total number of tests in this file. */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 73 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 74 | #define TEST_SIG SIGRTMIN+1 |
| 75 | |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 76 | /* Extern Global Functions */ |
| 77 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 78 | /* */ |
| 79 | /* Function: cleanup */ |
| 80 | /* */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 81 | /* Description: Performs all one time clean up for this test on successful */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 82 | /* 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_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 90 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 91 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 92 | /* */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 93 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 94 | void cleanup() |
| 95 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 96 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 97 | TEST_CLEANUP; |
| 98 | tst_rmdir(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 99 | |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* Local Functions */ |
| 103 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 104 | /* */ |
| 105 | /* Function: setup */ |
| 106 | /* */ |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 107 | /* Description: Performs all one time setup for this test. This function is */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 108 | /* 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_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 119 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 120 | void setup() |
| 121 | { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 122 | /* Capture signals if any */ |
| 123 | /* Create temporary directories */ |
| 124 | TEST_PAUSE; |
| 125 | tst_tmpdir(); |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | int sig_count = 0; |
| 129 | |
| 130 | void sig_handler(int sig) |
| 131 | { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 132 | sig_count++; |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 135 | int main(int ac, char **av) |
| 136 | { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 137 | #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_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 144 | struct sigaction act, oact; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 145 | memset(&act, 0, sizeof(act)); |
| 146 | memset(&oact, 0, sizeof(oact)); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 147 | act.sa_handler = sig_handler; |
| 148 | #endif |
| 149 | sigset_t set, oset; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 150 | int lc; |
| 151 | char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 152 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 153 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 154 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 155 | } |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 156 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 157 | setup(); |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 158 | |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 159 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 160 | Tst_count = 0; |
| 161 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 162 | |
| 163 | if (sigemptyset(&set) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 164 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 165 | "sigemptyset call failed"); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 166 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 167 | if (sigaddset(&set, TEST_SIG) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 168 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 169 | "sigaddset call failed"); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 170 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 171 | |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 172 | /* call rt_sigaction() */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 173 | TEST(ltp_syscall(__NR_rt_sigaction, TEST_SIG, &act, |
| 174 | &oact, SIGSETSIZE)); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 175 | if (TEST_RETURN < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 176 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 177 | "rt_sigaction call failed"); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 178 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 179 | /* call rt_sigprocmask() to block signal#TEST_SIG */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 180 | TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, &set, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 181 | &oset, SIGSETSIZE)); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 182 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 183 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 184 | "rt_sigprocmask call failed"); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 185 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 186 | /* Make sure that the masked process is indeed |
| 187 | * masked. */ |
| 188 | if (kill(getpid(), TEST_SIG) < 0) { |
| 189 | tst_brkm(TFAIL | TERRNO, cleanup, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 190 | "call to kill() failed"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 191 | } |
| 192 | if (sig_count) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 193 | tst_brkm(TFAIL | TERRNO, cleanup, |
| 194 | "rt_sigprocmask() failed to change " |
| 195 | "the process's signal mask"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 196 | } else { |
| 197 | /* call rt_sigpending() */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 198 | TEST(ltp_syscall(__NR_rt_sigpending, &oset, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 199 | SIGSETSIZE)); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 200 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 201 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 202 | "rt_sigpending call failed"); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 203 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 204 | TEST(sigismember(&oset, TEST_SIG)); |
| 205 | if (TEST_RETURN == 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 206 | tst_brkm(TFAIL | TTERRNO, |
| 207 | cleanup, |
| 208 | "sigismember call failed"); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 209 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 210 | /* call rt_sigprocmask() to unblock |
| 211 | * signal#TEST_SIG */ |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 212 | TEST(ltp_syscall(__NR_rt_sigprocmask, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 213 | SIG_UNBLOCK, &set, &oset, |
| 214 | SIGSETSIZE)); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 215 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 216 | tst_brkm(TFAIL | TTERRNO, |
| 217 | cleanup, |
| 218 | "rt_sigprocmask call failed"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 219 | } |
| 220 | if (sig_count) { |
| 221 | tst_resm(TPASS, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 222 | "rt_sigprocmask " |
| 223 | "functionality passed"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 224 | break; |
| 225 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 226 | tst_brkm(TFAIL | TERRNO, |
| 227 | cleanup, |
| 228 | "rt_sigprocmask " |
| 229 | "functionality failed"); |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 230 | } |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 231 | |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 232 | } |
subrata_modak | b264432 | 2009-05-21 18:23:00 +0000 | [diff] [blame] | 233 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 234 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 235 | |
| 236 | Tst_count++; |
| 237 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 238 | } |
Garrett Cooper | 85a1755 | 2010-02-26 20:10:07 -0800 | [diff] [blame] | 239 | |
| 240 | cleanup(); |
Garrett Cooper | 2e3781d | 2011-01-20 01:05:22 -0800 | [diff] [blame] | 241 | tst_exit(); |
| 242 | } |