1 /*
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
13 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 */
17 /**********************************************************
18 *
19 * TEST IDENTIFIER : prctl01
20 *
21 * EXECUTED BY : anyone
22 *
23 * TEST TITLE : Basic test for prctl(2)
24 *
25 * TEST CASE TOTAL : 2
26 *
27 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
28 *
29 * 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.
36 *
37 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
40 *
41 * 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
57 *
58 * Cleanup:
59 * Print errno log and/or timing stats if options given
60 *
61 * 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"
81
82 static void setup(void);
83 static void cleanup(void);
84
85 char *TCID = "prctl01";
86
87 int option[2] = { PR_GET_PDEATHSIG, PR_SET_PDEATHSIG };
88
89 int TST_TOTAL = 2;
90
main(int ac,char ** av)91 int main(int ac, char **av)
92 {
93
94 int lc, i;
95 pid_t child_pid;
96 int status, sig;
97
98 tst_parse_opts(ac, av, NULL, NULL);
99
100 setup();
101
102 for (lc = 0; TEST_LOOPING(lc); lc++) {
103
104 tst_count = 0;
105
106 for (i = 0; i < TST_TOTAL; ++i) {
107
108 switch (child_pid = FORK_OR_VFORK()) {
109
110 case -1:
111 /* fork() failed */
112 tst_resm(TFAIL, "fork() failed");
113 continue;
114
115 case 0:
116 /* Child */
117 if (i == 1) {
118 sig = SIGUSR2;
119 TEST(prctl(option[i], sig));
120 } else {
121 TEST(prctl(option[i], &sig));
122 }
123
124 if (TEST_RETURN == 0) {
125 exit(0);
126 } else {
127 tst_resm(TWARN | TTERRNO,
128 "prctl() returned %ld",
129 TEST_RETURN);
130 exit(1);
131 }
132
133 default:
134 /* Parent */
135 if ((waitpid(child_pid, &status, 0)) < 0) {
136 tst_resm(TFAIL, "waitpid() failed");
137 continue;
138 }
139
140 if ((WIFEXITED(status)) &&
141 (WEXITSTATUS(status) == 0)) {
142 tst_resm(TPASS, "Test Passed");
143 } else {
144 tst_resm(TFAIL, "Test Failed");
145 }
146
147 }
148 }
149 }
150
151 /* cleanup and exit */
152 cleanup();
153 tst_exit();
154
155 }
156
157 /* setup() - performs all ONE TIME setup for this test */
setup(void)158 void setup(void)
159 {
160
161 tst_sig(FORK, DEF_HANDLER, cleanup);
162
163 TEST_PAUSE;
164
165 }
166
167 /*
168 *cleanup() - performs all ONE TIME cleanup for this test at
169 * completion or premature exit.
170 */
cleanup(void)171 void cleanup(void)
172 {
173
174 }
175