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