subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 1 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 2 | /* Copyright (c) Crackerjack Project., 2007 */ |
| 3 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +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 */ |
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 */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 17 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 18 | /******************************************************************************/ |
| 19 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 20 | /* */ |
| 21 | /* File: rt_sigaction01.c */ |
| 22 | /* */ |
| 23 | /* Description: This tests the rt_sigaction() syscall */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 24 | /* rt_sigaction alters an action taken by a process on receipt */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 25 | /* of a particular signal. The action is specified by the */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 26 | /* sigaction structure. The previous action on the signal is */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 27 | /* saved in oact.sigsetsize should indicate the size of a */ |
| 28 | /* sigset_t type. */ |
| 29 | /* */ |
| 30 | /* Usage: <for command-line> */ |
| 31 | /* rt_sigaction01 [-c n] [-e][-i n] [-I x] [-p x] [-t] */ |
| 32 | /* where, -c n : Run n copies concurrently. */ |
| 33 | /* -e : Turn on errno logging. */ |
| 34 | /* -i n : Execute test n times. */ |
| 35 | /* -I x : Execute test for x seconds. */ |
| 36 | /* -P x : Pause for x seconds between iterations. */ |
| 37 | /* -t : Turn on syscall timing. */ |
| 38 | /* */ |
| 39 | /* Total Tests: 1 */ |
| 40 | /* */ |
| 41 | /* Test Name: rt_sigaction01 */ |
| 42 | /* History: Porting from Crackerjack to LTP is done by */ |
| 43 | /* Manas Kumar Nayak maknayak@in.ibm.com> */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 44 | /******************************************************************************/ |
| 45 | #include <stdio.h> |
| 46 | #include <stdlib.h> |
| 47 | #include <unistd.h> |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 48 | #include <signal.h> |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 49 | #include <errno.h> |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 50 | #include <sys/syscall.h> |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 51 | #include <string.h> |
| 52 | |
| 53 | /* Harness Specific Include Files. */ |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 54 | #define LTP_RT_SIG_TEST |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 55 | #include "test.h" |
| 56 | #include "usctest.h" |
| 57 | #include "linux_syscall_numbers.h" |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 58 | #include "ltp_signal.h" |
subrata_modak | bb190cd | 2009-07-06 15:24:06 +0000 | [diff] [blame] | 59 | |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 60 | /* Extern Global Variables */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 61 | |
| 62 | /* Global Variables */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 63 | char *TCID = "rt_sigaction01"; /* Test program identifier. */ |
| 64 | int testno; |
| 65 | int TST_TOTAL = 1; /* total number of tests in this file. */ |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 66 | |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 67 | /* Extern Global Functions */ |
| 68 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 69 | /* */ |
| 70 | /* Function: cleanup */ |
| 71 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 72 | /* Description: Performs all one time clean up for this test on successful */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 73 | /* completion, premature exit or failure. Closes all temporary */ |
| 74 | /* files, removes all temporary directories exits the test with */ |
| 75 | /* appropriate return code by calling tst_exit() function. */ |
| 76 | /* */ |
| 77 | /* Input: None. */ |
| 78 | /* */ |
| 79 | /* Output: None. */ |
| 80 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 81 | /* Return: On failure - Exits calling tst_exit(). Non '0' return code. */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 82 | /* On success - Exits calling tst_exit(). With '0' return code. */ |
| 83 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 84 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | void cleanup() |
| 86 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 87 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 88 | TEST_CLEANUP; |
| 89 | tst_rmdir(); |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 90 | |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /* Local Functions */ |
| 94 | /******************************************************************************/ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 95 | /* */ |
| 96 | /* Function: setup */ |
| 97 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 98 | /* Description: Performs all one time setup for this test. This function is */ |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 99 | /* typically used to capture signals, create temporary dirs */ |
| 100 | /* and temporary files that may be used in the course of this */ |
| 101 | /* test. */ |
| 102 | /* */ |
| 103 | /* Input: None. */ |
| 104 | /* */ |
| 105 | /* Output: None. */ |
| 106 | /* */ |
| 107 | /* Return: On failure - Exits by calling cleanup(). */ |
| 108 | /* On success - returns 0. */ |
| 109 | /* */ |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 110 | /******************************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 111 | void setup() |
| 112 | { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 113 | /* Capture signals if any */ |
| 114 | /* Create temporary directories */ |
| 115 | TEST_PAUSE; |
| 116 | tst_tmpdir(); |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 119 | int test_flags[] = |
| 120 | { SA_RESETHAND | SA_SIGINFO, SA_RESETHAND, SA_RESETHAND | SA_SIGINFO, |
| 121 | SA_RESETHAND | SA_SIGINFO, SA_NOMASK }; |
| 122 | char *test_flags_list[] = |
| 123 | { "SA_RESETHAND|SA_SIGINFO", "SA_RESETHAND", "SA_RESETHAND|SA_SIGINFO", |
| 124 | "SA_RESETHAND|SA_SIGINFO", "SA_NOMASK" }; |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 125 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 126 | void handler(int sig) |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 127 | { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 128 | tst_resm(TINFO, "Signal Handler Called with signal number %d\n", sig); |
| 129 | return; |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 132 | int set_handler(int sig, int sig_to_mask, int mask_flags) |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 133 | { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 134 | #ifdef __x86_64__ |
| 135 | struct kernel_sigaction sa, oldaction; |
| 136 | mask_flags |= SA_RESTORER; |
| 137 | sa.sa_restorer = restore_rt; |
| 138 | sa.k_sa_handler = (void *)handler; |
| 139 | #else |
| 140 | struct sigaction sa, oldaction; |
| 141 | sa.sa_handler = (void *)handler; |
| 142 | #endif |
| 143 | sa.sa_flags = mask_flags; |
| 144 | sigemptyset(&sa.sa_mask); |
| 145 | sigaddset(&sa.sa_mask, sig); |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 146 | |
Jan Stancek | 359980f | 2013-02-15 10:16:05 +0100 | [diff] [blame^] | 147 | return ltp_syscall(__NR_rt_sigaction, sig, &sa, &oldaction, SIGSETSIZE); |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 148 | |
subrata_modak | 654da39 | 2009-05-21 18:20:58 +0000 | [diff] [blame] | 149 | } |
| 150 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 151 | int main(int ac, char **av) |
| 152 | { |
yaberauneya | 5833cc6 | 2010-01-26 08:24:52 +0000 | [diff] [blame] | 153 | int signal, flag; |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 154 | int lc; |
| 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); |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 159 | } |
yaberauneya | 1979ba3 | 2009-11-26 14:30:42 +0000 | [diff] [blame] | 160 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 161 | setup(); |
yaberauneya | 1979ba3 | 2009-11-26 14:30:42 +0000 | [diff] [blame] | 162 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 163 | for (lc = 0; TEST_LOOPING(lc); ++lc) { |
| 164 | |
| 165 | Tst_count = 0; |
| 166 | |
| 167 | for (testno = 0; testno < TST_TOTAL; ++testno) { |
| 168 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 169 | for (signal = SIGRTMIN; signal <= (SIGRTMAX); signal++) { //signal for 34 to 65 |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 170 | |
| 171 | #ifdef __x86_64__ |
| 172 | sig_initial(signal); |
| 173 | #endif |
| 174 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 175 | for (flag = 0; |
| 176 | flag < |
| 177 | (sizeof(test_flags) / |
| 178 | sizeof(test_flags[0])); flag++) { |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 179 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 180 | TEST(set_handler |
| 181 | (signal, 0, test_flags[flag])); |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 182 | |
| 183 | if (TEST_RETURN == 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 184 | tst_resm(TINFO, "signal: %d ", |
| 185 | signal); |
| 186 | tst_resm(TPASS, |
| 187 | "rt_sigaction call succeeded: result = %ld ", |
| 188 | TEST_RETURN); |
| 189 | tst_resm(TINFO, |
| 190 | "sa.sa_flags = %s ", |
| 191 | test_flags_list[flag]); |
| 192 | kill(getpid(), signal); |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 193 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 194 | tst_resm(TFAIL | TTERRNO, |
| 195 | "rt_sigaction call " |
| 196 | "failed"); |
| 197 | } |
yaberauneya | 1979ba3 | 2009-11-26 14:30:42 +0000 | [diff] [blame] | 198 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 199 | } |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 200 | |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 201 | } |
yaberauneya | 402ec1f | 2009-11-30 20:38:48 +0000 | [diff] [blame] | 202 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 203 | } |
Garrett Cooper | 64fd967 | 2010-02-26 05:12:13 -0800 | [diff] [blame] | 204 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 205 | } |
subrata_modak | bb190cd | 2009-07-06 15:24:06 +0000 | [diff] [blame] | 206 | cleanup(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 207 | tst_exit(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 208 | } |