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 : sched_getparam02
20 *
21 * EXECUTED BY : anyone
22 *
23 * TEST TITLE : Get scheduling parametes for parent process
24 *
25 * TEST CASE TOTAL : 1
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 * Verifies functionality of sched_getparam() for a process other than
35 * current process (ie, pid != 0). Here we get the scheduling parameters
36 * for parent process.
37 *
38 * Setup:
39 * Setup signal handling.
40 * Pause for SIGUSR1 if option specified.
41 *
42 * Test:
43 * Loop if the proper options are given.
44 * fork a child
45 *
46 * CHILD:
47 * Gets the scheduling parameters for parent process
48 * If successfull,
49 * TEST passed
50 * else
51 * TEST failed.
52 *
53 * PARENT:
54 * wait for child to finish
55 *
56 * Cleanup:
57 * Print errno log and/or timing stats if options given
58 *
59 * USAGE: <for command-line>
60 * sched_getparam02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
61 * where, -c n : Run n copies concurrently.
62 * -e : Turn on errno logging.
63 * -h : Show help screen
64 * -f : Turn off functional testing
65 * -i n : Execute test n times.
66 * -I x : Execute test for x seconds.
67 * -p : Pause for SIGUSR1 before starting
68 * -P x : Pause for x seconds between iterations.
69 * -t : Turn on syscall timing.
70 *
71 ****************************************************************/
72
73 #include <errno.h>
74 #include <sched.h>
75 #include <sys/wait.h>
76 #include <stdlib.h>
77 #include "test.h"
78
79 static void setup();
80 static void cleanup();
81
82 char *TCID = "sched_getparam02";
83 int TST_TOTAL = 1;
84
85 static struct sched_param param;
86
main(int ac,char ** av)87 int main(int ac, char **av)
88 {
89
90 int lc;
91 int status;
92 pid_t child_pid;
93
94 tst_parse_opts(ac, av, NULL, NULL);
95
96 setup();
97
98 for (lc = 0; TEST_LOOPING(lc); lc++) {
99
100 tst_count = 0;
101
102 switch (child_pid = FORK_OR_VFORK()) {
103
104 case -1:
105 /* fork() failed */
106 tst_resm(TFAIL, "fork() failed");
107 continue;
108
109 case 0:
110 /* Child */
111 param.sched_priority = 100;
112
113 /*
114 * Call sched_getparam(2) with pid = getppid() sothat
115 * it will get the scheduling parameters for parent
116 * process
117 */
118 TEST(sched_getparam(getppid(), ¶m));
119
120 /*
121 * Check return code & priority. For normal process,
122 * scheduling policy is SCHED_OTHER. For this
123 * scheduling policy, only allowed priority value is 0.
124 * So we should get 0 for priority value
125 */
126 if (TEST_RETURN == 0 && param.sched_priority == 0)
127 exit(0);
128 else {
129 tst_resm(TWARN, "sched_getparam()"
130 "returned %ld, errno = %d : %s;"
131 " returned process priority value"
132 " is %d", TEST_RETURN, TEST_ERRNO,
133 strerror(TEST_ERRNO),
134 param.sched_priority);
135 exit(1);
136 }
137
138 default:
139 /* Parent */
140 if ((waitpid(child_pid, &status, 0)) < 0) {
141 tst_resm(TFAIL, "wait() failed");
142 continue;
143 }
144 if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0))
145 tst_resm(TPASS, "Test Passed");
146 else
147 tst_resm(TFAIL, "Test Failed");
148 }
149
150 }
151
152 cleanup();
153 tst_exit();
154 }
155
156 /* setup() - performs all ONE TIME setup for this test */
setup(void)157 void setup(void)
158 {
159
160 tst_sig(FORK, DEF_HANDLER, cleanup);
161
162 TEST_PAUSE;
163
164 }
165
166 /*
167 *cleanup() - performs all ONE TIME cleanup for this test at
168 * completion or premature exit.
169 */
cleanup(void)170 void cleanup(void)
171 {
172 }
173