blob: 721ab935a60f202199fb6054feba6fd9316e19a9 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * signal02.c
23 *
24 * DESCRIPTION
25 * signal02 - Test that we get an error using illegal signals
26 *
27 * ALGORITHM
28 * loop if that option was specified
29 * issue the system call
30 * check the return value
31 * if return value != -1
32 * issue a FAIL message, break remaining tests and cleanup
33 * if we get an EINVAL
34 * issue a PASS message
35 * else
36 * issue a FAIL message, break remaining tests and cleanup
37 * call cleanup
38 *
39 * USAGE: <for command-line>
40 * signal02 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
41 * where, -c n : Run n copies concurrently.
42 * -e : Turn on error logging.
43 * -i n : Execute test n times.
44 * -I x : Execute test for x seconds.
45 * -P x : Pause for x seconds between iterations.
46 * -t : Turn on syscall timing.
47 *
48 * History
49 * 07/2001 John George
50 * -Ported
51 *
52 * Restrictions
53 * none
54 */
55
56#include "test.h"
plars865695b2001-08-27 22:15:12 +000057
58#include <errno.h>
59#include <signal.h>
60
61void cleanup(void);
62void setup(void);
63
subrata_modak56207ce2009-03-23 13:35:39 +000064char *TCID = "signal02";
plars865695b2001-08-27 22:15:12 +000065int TST_TOTAL = 3;
plars865695b2001-08-27 22:15:12 +000066
subrata_modak56207ce2009-03-23 13:35:39 +000067typedef void (*sighandler_t) (int);
plars74948ad2002-11-14 16:16:14 +000068
subrata_modak56207ce2009-03-23 13:35:39 +000069sighandler_t Tret;
70int sigs[] = { _NSIG + 1, SIGKILL, SIGSTOP };
plars865695b2001-08-27 22:15:12 +000071
plars74948ad2002-11-14 16:16:14 +000072int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000073{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020074 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020075 const char *msg;
plars865695b2001-08-27 22:15:12 +000076 int i;
77
Garrett Cooper45e285d2010-11-22 12:19:25 -080078 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080079 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +080080 }
plars865695b2001-08-27 22:15:12 +000081
subrata_modak56207ce2009-03-23 13:35:39 +000082 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000083
84 /* The following loop checks looping state if -i option given */
85
86 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080087 /* reset tst_count in case we are looping */
88 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000089
90 /*
91 * There are three cases where we should get an EINVAL
92 */
subrata_modak56207ce2009-03-23 13:35:39 +000093 for (i = 0; i < TST_TOTAL; i++) {
plars865695b2001-08-27 22:15:12 +000094
subrata_modak56207ce2009-03-23 13:35:39 +000095 errno = 0;
96 Tret = signal(sigs[i], SIG_IGN);
97 TEST_ERRNO = errno;
plars865695b2001-08-27 22:15:12 +000098
plars74948ad2002-11-14 16:16:14 +000099 if (Tret != SIG_ERR) {
plars865695b2001-08-27 22:15:12 +0000100 tst_brkm(TFAIL, cleanup, "%s call failed - "
101 "errno = %d : %s", TCID, TEST_ERRNO,
102 strerror(TEST_ERRNO));
Wanlong Gao354ebb42012-12-07 10:10:04 +0800103 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000104
subrata_modak56207ce2009-03-23 13:35:39 +0000105 switch (TEST_ERRNO) {
plars865695b2001-08-27 22:15:12 +0000106 case EINVAL:
107 tst_resm(TPASS, "expected failure - errno = "
108 "%d - %s", TEST_ERRNO,
109 strerror(TEST_ERRNO));
110 break;
111 default:
112 tst_resm(TFAIL, "call failed to produce "
subrata_modak56207ce2009-03-23 13:35:39 +0000113 "expected error - errno = %d "
114 "- %s", TEST_ERRNO,
115 strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +0000116 }
117 }
Caspar Zhangd59a6592013-03-07 14:59:12 +0800118 tst_count++; /* incr. TEST_LOOP counter */
plars865695b2001-08-27 22:15:12 +0000119 }
120
121 cleanup();
122
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800123 tst_exit();
robbiewfa451a12003-03-27 20:52:36 +0000124
plars865695b2001-08-27 22:15:12 +0000125}
126
127/*
128 * setup() - performs all the ONE TIME setup for this test.
129 */
subrata_modak56207ce2009-03-23 13:35:39 +0000130void setup(void)
plars865695b2001-08-27 22:15:12 +0000131{
Garrett Cooper2c282152010-12-16 00:55:50 -0800132
plars865695b2001-08-27 22:15:12 +0000133 tst_sig(NOFORK, DEF_HANDLER, cleanup);
134
plars865695b2001-08-27 22:15:12 +0000135 TEST_PAUSE;
136}
137
138/*
139 * cleanup() - performs all the ONE TIME cleanup for this test at completion
140 * or premature exit.
141 */
subrata_modak56207ce2009-03-23 13:35:39 +0000142void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000143{
plars865695b2001-08-27 22:15:12 +0000144
Chris Dearmanec6edca2012-10-17 19:54:01 -0700145}