blob: ccd1c6cd60bfd442311a9c28e7ceb2143908bbab [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
vapierd13d74b2006-02-11 07:24:00 +000019 * TEST IDENTIFIER : prctl01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
vapierd13d74b2006-02-11 07:24:00 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
vapierd13d74b2006-02-11 07:24:00 +000023 * TEST TITLE : Basic test for prctl(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 2
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
vapierd13d74b2006-02-11 07:24:00 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
vapierd13d74b2006-02-11 07:24:00 +000029 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * This is a Phase I test for the prctl(2) system call.
35 * It is intended to provide a limited exposure of the system call.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
vapierd13d74b2006-02-11 07:24:00 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
vapierd13d74b2006-02-11 07:24:00 +000041 * Test:
42 * Loop if the proper options are given.
43 * fork a child
44 *
45 * CHILD:
46 * call prctl() with proper arguments
47 * If call succeeds,
48 * exit with 0
49 * else
50 * exit with 1
51 * PARENT:
52 * wait() for child.
53 * If child exits with exit value 0,
54 * Test passed
55 * else
56 * Test Failed
Garrett Cooper2c282152010-12-16 00:55:50 -080057 *
vapierd13d74b2006-02-11 07:24:00 +000058 * Cleanup:
59 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000060 *
vapierd13d74b2006-02-11 07:24:00 +000061 * USAGE: <for command-line>
62 * prctl01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
63 * where, -c n : Run n copies concurrently.
64 * -e : Turn on errno logging.
65 * -h : Show help screen
66 * -f : Turn off functional testing
67 * -i n : Execute test n times.
68 * -I x : Execute test for x seconds.
69 * -p : Pause for SIGUSR1 before starting
70 * -P x : Pause for x seconds between iterations.
71 * -t : Turn on syscall timing.
72 *
73 ****************************************************************/
74
75#include <errno.h>
76#include <signal.h>
77#include <sys/prctl.h>
78#include <sys/wait.h>
79
80#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000081
82static void setup(void);
83static void cleanup(void);
84
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020085char *TCID = "prctl01";
vapierd13d74b2006-02-11 07:24:00 +000086
87int option[2] = { PR_GET_PDEATHSIG, PR_SET_PDEATHSIG };
Wanlong Gao354ebb42012-12-07 10:10:04 +080088
vapierd13d74b2006-02-11 07:24:00 +000089int TST_TOTAL = 2;
90
subrata_modak56207ce2009-03-23 13:35:39 +000091int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +000092{
93
Cyril Hrubis89af32a2012-10-24 16:39:11 +020094 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020095 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000096 pid_t child_pid;
97 int status, sig;
98
Garrett Coopera9e49f12010-12-16 10:54:03 -080099 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800100 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000101
vapierd13d74b2006-02-11 07:24:00 +0000102 setup();
103
vapierd13d74b2006-02-11 07:24:00 +0000104 for (lc = 0; TEST_LOOPING(lc); lc++) {
105
Caspar Zhangd59a6592013-03-07 14:59:12 +0800106 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +0000107
108 for (i = 0; i < TST_TOTAL; ++i) {
109
mridgeed06ca62006-02-14 16:55:09 +0000110 switch (child_pid = FORK_OR_VFORK()) {
vapierd13d74b2006-02-11 07:24:00 +0000111
112 case -1:
113 /* fork() failed */
114 tst_resm(TFAIL, "fork() failed");
115 continue;
116
117 case 0:
118 /* Child */
119 if (i == 1) {
120 sig = SIGUSR2;
121 TEST(prctl(option[i], sig));
subrata_modak56207ce2009-03-23 13:35:39 +0000122 } else {
vapierd13d74b2006-02-11 07:24:00 +0000123 TEST(prctl(option[i], &sig));
124 }
125
126 if (TEST_RETURN == 0) {
127 exit(0);
128 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800129 tst_resm(TWARN | TTERRNO,
130 "prctl() returned %ld",
subrata_modak923b23f2009-11-02 13:57:16 +0000131 TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +0000132 exit(1);
133 }
134
135 default:
136 /* Parent */
137 if ((waitpid(child_pid, &status, 0)) < 0) {
138 tst_resm(TFAIL, "waitpid() failed");
139 continue;
140 }
141
142 if ((WIFEXITED(status)) &&
143 (WEXITSTATUS(status) == 0)) {
144 tst_resm(TPASS, "Test Passed");
145 } else {
146 tst_resm(TFAIL, "Test Failed");
147 }
148
149 }
150 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800151 }
vapierd13d74b2006-02-11 07:24:00 +0000152
153 /* cleanup and exit */
154 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800155 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000156
Garrett Cooper2c282152010-12-16 00:55:50 -0800157}
vapierd13d74b2006-02-11 07:24:00 +0000158
159/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400160void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000161{
162
vapierd13d74b2006-02-11 07:24:00 +0000163 tst_sig(FORK, DEF_HANDLER, cleanup);
164
vapierd13d74b2006-02-11 07:24:00 +0000165 TEST_PAUSE;
166
Garrett Cooper2c282152010-12-16 00:55:50 -0800167}
vapierd13d74b2006-02-11 07:24:00 +0000168
169/*
170 *cleanup() - performs all ONE TIME cleanup for this test at
171 * completion or premature exit.
172 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400173void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000174{
175
Chris Dearmanec6edca2012-10-17 19:54:01 -0700176}