plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * |
| 4 | * Copyright (c) International Business Machines Corp., 2002 |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 14 | * the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | /* |
| 22 | * NAME |
| 23 | * sigpending02.c |
| 24 | * |
| 25 | * DESCRIPTION |
| 26 | * Test to see the the proper errors are returned by sigpending |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 27 | *$ |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 28 | * ALGORITHM |
| 29 | * test 1: |
| 30 | * Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT |
| 31 | * |
| 32 | * USAGE: <for command-line> |
| 33 | * -c n Run n copies concurrently |
| 34 | * -e Turn on errno logging |
| 35 | * -f Turn off functional testing |
| 36 | * -h Show this help screen |
| 37 | * -i n Execute test n times |
| 38 | * -I x Execute test for x seconds |
| 39 | * -p Pause for SIGUSR1 before starting |
| 40 | * -P x Pause for x seconds between iterations |
| 41 | * -t Turn on syscall timing |
| 42 | * |
| 43 | * HISTORY |
| 44 | * 02/2002 Written by Paul Larson |
| 45 | * |
| 46 | * RESTRICTIONS |
| 47 | * None |
| 48 | */ |
| 49 | #include <sys/types.h> |
| 50 | #include <sys/fcntl.h> |
| 51 | #include <sys/stat.h> |
| 52 | #include <errno.h> |
| 53 | #include <string.h> |
| 54 | #include <signal.h> |
| 55 | #include "test.h" |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 56 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 57 | void setup(); |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 58 | void help(); |
| 59 | void cleanup(); |
| 60 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 61 | char *TCID = "sigpending02"; |
| 62 | int TST_TOTAL = 1; |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 63 | |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 64 | /*********************************************************************** |
| 65 | * Main |
| 66 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 67 | int main(int ac, char **av) |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 68 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 69 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 70 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | sigset_t *sigset; |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 72 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 73 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 74 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 75 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 76 | } |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 77 | |
| 78 | /*************************************************************** |
| 79 | * perform global setup for test |
| 80 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 81 | setup(); |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 82 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 83 | /* set sigset to point to an invalid location */ |
| 84 | sigset = (sigset_t *) - 1; |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 85 | |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 86 | /*************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 87 | * check looping state |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 88 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | /* TEST_LOOPING() is a macro that will make sure the test continues |
| 90 | * looping according to the standard command line args. |
| 91 | */ |
| 92 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 93 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 94 | tst_count = 0; |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 95 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 96 | TEST(sigpending(sigset)); |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 97 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | /* check return code */ |
| 99 | if (TEST_RETURN == -1) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 100 | if (TEST_ERRNO != EFAULT) |
| 101 | tst_brkm(TFAIL, cleanup, |
| 102 | "sigpending() Failed with wrong " |
| 103 | "errno, expected errno=%d, got errno=%d : %s", |
| 104 | EFAULT, TEST_ERRNO, |
| 105 | strerror(TEST_ERRNO)); |
| 106 | else |
| 107 | tst_resm(TPASS, |
| 108 | "expected failure - errno = %d : %s", |
| 109 | TEST_ERRNO, strerror(TEST_ERRNO)); |
| 110 | } else { |
| 111 | tst_brkm(TFAIL, cleanup, |
| 112 | "sigpending() Failed, expected " |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 113 | "return value=-1, got %ld", TEST_RETURN); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 114 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 115 | } |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 116 | |
| 117 | /*************************************************************** |
| 118 | * cleanup and exit |
| 119 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 120 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 121 | tst_exit(); |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 122 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 123 | } |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 124 | |
| 125 | /*************************************************************** |
| 126 | * help |
| 127 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 128 | void help(void) |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 129 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 130 | printf("test\n"); |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /*************************************************************** |
| 134 | * setup() - performs all ONE TIME setup for this test. |
| 135 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 136 | void setup(void) |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 137 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | TEST_PAUSE; |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /*************************************************************** |
| 142 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 143 | * completion or premature exit. |
| 144 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 145 | void cleanup(void) |
plars | b6a1d25 | 2002-02-12 16:03:54 +0000 | [diff] [blame] | 146 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 147 | } |