subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 16 | /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 17 | /* */ |
| 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 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 | 2a6db06 | 2009-05-21 18:24:15 +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. */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 40 | /* */ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 41 | /* RETURN VALUE:i */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 42 | /* rt_sigprocmask returns 0 on success; otherwise, rt_sigprocmask*/ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 43 | /* returns one of the errors listed in the "Errors" section. */ |
| 44 | /* */ |
| 45 | /* Errors: */ |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 46 | /* -EINVAL */ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 47 | /* 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" |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 77 | #include "ltp_signal.h" |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 78 | |
| 79 | /* Extern Global Variables */ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 80 | |
| 81 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 82 | char *TCID = "rt_sigprocmask02"; /* Test program identifier. */ |
| 83 | int TST_TOTAL = 2; /* total number of tests in this file. */ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 84 | |
| 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 103 | extern void cleanup() |
| 104 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 105 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 106 | TEST_CLEANUP; |
| 107 | tst_rmdir(); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 108 | |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 109 | } |
| 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 129 | void setup() |
| 130 | { |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 131 | /* Capture signals if any */ |
| 132 | /* Create temporary directories */ |
| 133 | TEST_PAUSE; |
| 134 | tst_tmpdir(); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | sigset_t set; |
| 138 | |
| 139 | struct test_case_t { |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 140 | sigset_t *ss; |
| 141 | int sssize; |
| 142 | int exp_errno; |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 143 | } test_cases[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 144 | { |
| 145 | &set, 1, EINVAL}, { |
| 146 | (sigset_t *) - 1, SIGSETSIZE, EFAULT} |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
| 149 | int test_count = sizeof(test_cases) / sizeof(struct test_case_t); |
| 150 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 151 | int main(int ac, char **av) |
| 152 | { |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 153 | int i; |
| 154 | sigset_t s; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 155 | char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 156 | |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 157 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 158 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 159 | tst_exit(); |
| 160 | } |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 161 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 162 | setup(); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 163 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 164 | Tst_count = 0; |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 165 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 166 | TEST(sigfillset(&s)); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 167 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 168 | tst_resm(TFAIL | TTERRNO, "Call to sigfillset() failed."); |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 169 | cleanup(); |
| 170 | tst_exit(); |
| 171 | } |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 172 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 173 | for (i = 0; i < test_count; i++) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 174 | TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 175 | &s, test_cases[i].ss, test_cases[i].sssize)); |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 176 | if (TEST_RETURN == 0) { |
| 177 | tst_resm(TFAIL | TTERRNO, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 178 | "Call to rt_sigprocmask() succeeded, " |
| 179 | "but should failed"); |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 180 | } 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_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 185 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | cleanup(); |
| 189 | tst_exit(); |
| 190 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 191 | } |