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 */ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 15 | /* 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_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 17 | /* */ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 18 | /* History: Porting from Crackerjack to LTP is done by */ |
| 19 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 20 | /******************************************************************************/ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 21 | |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 22 | /******************************************************************************/ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 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. */ |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 52 | /******************************************************************************/ |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 53 | |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 54 | #include <stdio.h> |
| 55 | #include <signal.h> |
| 56 | #include <errno.h> |
| 57 | |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 58 | #include "test.h" |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 59 | #include "linux_syscall_numbers.h" |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 60 | #include "ltp_signal.h" |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 61 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 62 | char *TCID = "rt_sigprocmask02"; |
| 63 | int TST_TOTAL = 2; |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 64 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 65 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 66 | { |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 67 | tst_rmdir(); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 70 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 71 | { |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 72 | TEST_PAUSE; |
| 73 | tst_tmpdir(); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 76 | static sigset_t set; |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 77 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 78 | static struct test_case_t { |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 79 | sigset_t *ss; |
| 80 | int sssize; |
| 81 | int exp_errno; |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 82 | } test_cases[] = { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 83 | { |
| 84 | &set, 1, EINVAL}, { |
| 85 | (sigset_t *) - 1, SIGSETSIZE, EFAULT} |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | int test_count = sizeof(test_cases) / sizeof(struct test_case_t); |
| 89 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 90 | int main(int ac, char **av) |
| 91 | { |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 92 | int i; |
| 93 | sigset_t s; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 94 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 95 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 96 | msg = parse_opts(ac, av, NULL, NULL); |
| 97 | if (msg != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 98 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 99 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 100 | setup(); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 101 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 102 | tst_count = 0; |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 103 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 104 | TEST(sigfillset(&s)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 105 | if (TEST_RETURN == -1) |
| 106 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 107 | "Call to sigfillset() failed."); |
subrata_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 108 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 109 | for (i = 0; i < test_count; i++) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 110 | TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 111 | &s, test_cases[i].ss, test_cases[i].sssize)); |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 112 | if (TEST_RETURN == 0) { |
| 113 | tst_resm(TFAIL | TTERRNO, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 114 | "Call to rt_sigprocmask() succeeded, " |
| 115 | "but should failed"); |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 116 | } 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_modak | 2a6db06 | 2009-05-21 18:24:15 +0000 | [diff] [blame] | 121 | |
yaberauneya | 250cc8e | 2009-11-26 12:04:59 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | cleanup(); |
| 125 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 126 | } |