Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [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 Foundation, */ |
| 16 | /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 17 | /* */ |
| 18 | /* History: Porting from Crackerjack to LTP is done by */ |
| 19 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
| 20 | /******************************************************************************/ |
| 21 | |
| 22 | /******************************************************************************/ |
| 23 | /* Description: This tests the rt_sigsuspend() syscall. */ |
| 24 | /******************************************************************************/ |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 25 | |
| 26 | #include <stdio.h> |
| 27 | #include <signal.h> |
| 28 | #include <errno.h> |
| 29 | |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 30 | #include "test.h" |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 31 | #include "linux_syscall_numbers.h" |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 32 | #include "lapi/rt_sigaction.h" |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 33 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 34 | char *TCID = "rt_sigsuspend01"; |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 35 | int TST_TOTAL = 1; |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 36 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 37 | static void cleanup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 38 | { |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 39 | tst_rmdir(); |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 42 | static void setup(void) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 43 | { |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 44 | TEST_PAUSE; |
| 45 | tst_tmpdir(); |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 48 | static void sig_handler(int sig) |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 52 | int main(int ac, char **av) |
| 53 | { |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 54 | sigset_t set, set1, set2; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 55 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 56 | const char *msg; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 57 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 58 | msg = parse_opts(ac, av, NULL, NULL); |
| 59 | if (msg != NULL) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 60 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 61 | |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 62 | setup(); |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 63 | |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 64 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 65 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 66 | tst_count = 0; |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 67 | |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 68 | if (sigemptyset(&set) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 69 | tst_brkm(TFAIL | TERRNO, cleanup, "sigemptyset failed"); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 70 | struct sigaction act, oact; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 71 | memset(&act, 0, sizeof(act)); |
| 72 | memset(&oact, 0, sizeof(oact)); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 73 | act.sa_handler = sig_handler; |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 74 | |
Stanislav Kholmanskikh | ea53701 | 2014-06-17 13:08:17 +0400 | [diff] [blame] | 75 | TEST(ltp_rt_sigaction(SIGALRM, &act, &oact, SIGSETSIZE)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 76 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 77 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 78 | "rt_sigaction failed"); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 79 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 80 | TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | &set1, SIGSETSIZE)); |
Stanislav Kholmanskikh | 4d93b88 | 2014-06-17 13:08:16 +0400 | [diff] [blame] | 82 | if (TEST_RETURN == -1) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 83 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 84 | "rt_sigprocmask failed"); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 85 | |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 86 | TEST(alarm(5)); |
| 87 | int result; |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 88 | TEST(result = ltp_syscall(__NR_rt_sigsuspend, &set, |
| 89 | SIGSETSIZE)); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 90 | TEST(alarm(0)); |
| 91 | if (result == -1 && TEST_ERRNO != EINTR) { |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame] | 92 | TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_UNBLOCK, 0, |
| 93 | &set2, SIGSETSIZE)); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 94 | if (TEST_RETURN == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 95 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 96 | "rt_sigprocmask failed"); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 97 | } else if (set1.__val[0] != set2.__val[0]) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 98 | tst_brkm(TFAIL | TTERRNO, cleanup, |
| 99 | "rt_sigsuspend failed to " |
| 100 | "preserve signal mask"); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 101 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 102 | tst_resm(TPASS, "rt_sigsuspend PASSED"); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 103 | } |
| 104 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 105 | tst_resm(TFAIL | TTERRNO, "rt_sigsuspend failed"); |
Garrett Cooper | 135924f | 2010-02-26 19:52:32 -0800 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | } |
| 109 | |
subrata_modak | 7733626 | 2009-05-21 18:28:46 +0000 | [diff] [blame] | 110 | cleanup(); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 111 | |
Garrett Cooper | b0a973a | 2011-01-21 01:15:32 -0800 | [diff] [blame] | 112 | tst_exit(); |
| 113 | } |