blob: 0c74700ecfcac1e82b57ec323423e8c115a117fd [file] [log] [blame]
plarsa8b7bfe2002-12-05 22:00: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
13 * with this program; if not, write the Free Software Foundation, Inc., 59
14 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
15 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
plarsa8b7bfe2002-12-05 22:00:00 +000019 * TEST IDENTIFIER : sched_getparam02
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
plarsa8b7bfe2002-12-05 22:00:00 +000021 * EXECUTED BY : anyone
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
plarsa8b7bfe2002-12-05 22:00:00 +000023 * TEST TITLE : Get scheduling parametes for parent process
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
plarsa8b7bfe2002-12-05 22:00:00 +000025 * TEST CASE TOTAL : 1
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
plarsa8b7bfe2002-12-05 22:00:00 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
plarsa8b7bfe2002-12-05 22:00: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 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000037 *
plarsa8b7bfe2002-12-05 22:00:00 +000038 * Setup:
39 * Setup signal handling.
40 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
plarsa8b7bfe2002-12-05 22:00:00 +000042 * 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
subrata_modak4bb656a2009-02-26 12:02:09 +000055 *
plarsa8b7bfe2002-12-05 22:00:00 +000056 * Cleanup:
57 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000058 *
plarsa8b7bfe2002-12-05 22:00:00 +000059 * 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#include "usctest.h"
79
80static void setup();
81static void cleanup();
82
subrata_modak56207ce2009-03-23 13:35:39 +000083char *TCID = "sched_getparam02"; /* Test program identifier. */
84int TST_TOTAL = 1; /* Total number of test cases. */
85extern int Tst_count; /* Test Case counter for tst_* routines */
plarsa8b7bfe2002-12-05 22:00:00 +000086
87static struct sched_param param;
88
subrata_modak56207ce2009-03-23 13:35:39 +000089int main(int ac, char **av)
plarsa8b7bfe2002-12-05 22:00:00 +000090{
91
subrata_modak56207ce2009-03-23 13:35:39 +000092 int lc; /* loop counter */
93 char *msg; /* message returned from parse_opts */
plarsa8b7bfe2002-12-05 22:00:00 +000094 int status;
95 pid_t child_pid;
96
97 /* parse standard options */
Garrett Cooper45e285d2010-11-22 12:19:25 -080098 if ((msg = parse_opts(ac, av, NULL, NULL))
99 != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -0800100 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plarsa8b7bfe2002-12-05 22:00:00 +0000101 }
102
103 /* perform global setup for test */
104 setup();
105
106 /* check looping state if -i option given */
107 for (lc = 0; TEST_LOOPING(lc); lc++) {
108
109 /* reset Tst_count in case we are looping. */
110 Tst_count = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +0000111
subrata_modak56207ce2009-03-23 13:35:39 +0000112 switch (child_pid = FORK_OR_VFORK()) {
plarsa8b7bfe2002-12-05 22:00:00 +0000113
114 case -1:
115 /* fork() failed */
116 tst_resm(TFAIL, "fork() failed");
117 continue;
118
119 case 0:
120 /* Child */
121 param.sched_priority = 100;
122
subrata_modak4bb656a2009-02-26 12:02:09 +0000123 /*
plarsa8b7bfe2002-12-05 22:00:00 +0000124 * Call sched_getparam(2) with pid = getppid() sothat
125 * it will get the scheduling parameters for parent
126 * process
127 */
128 TEST(sched_getparam(getppid(), &param));
subrata_modakbdbaec52009-02-26 12:14:51 +0000129
plarsa8b7bfe2002-12-05 22:00:00 +0000130 /*
subrata_modak56207ce2009-03-23 13:35:39 +0000131 * Check return code & priority. For normal process,
plarsa8b7bfe2002-12-05 22:00:00 +0000132 * scheduling policy is SCHED_OTHER. For this
133 * scheduling policy, only allowed priority value is 0.
134 * So we should get 0 for priority value
135 */
136 if ((TEST_RETURN == 0) && (param.sched_priority == 0)) {
137 exit(0);
138 } else {
139 tst_resm(TWARN, "sched_getparam()"
subrata_modak923b23f2009-11-02 13:57:16 +0000140 "returned %ld, errno = %d : %s;"
plarsa8b7bfe2002-12-05 22:00:00 +0000141 " returned process priority value"
142 " is %d", TEST_RETURN, TEST_ERRNO,
143 strerror(TEST_ERRNO),
144 param.sched_priority);
145 exit(1);
146 }
147
148 default:
149 /* Parent */
150 if ((waitpid(child_pid, &status, 0)) < 0) {
151 tst_resm(TFAIL, "wait() failed");
152 continue;
153 }
154 if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0)) {
155 tst_resm(TPASS, "Test Passed");
156 } else {
157 tst_resm(TFAIL, "Test Failed");
158 }
159 }
160
subrata_modak56207ce2009-03-23 13:35:39 +0000161 } /* End for TEST_LOOPING */
plarsa8b7bfe2002-12-05 22:00:00 +0000162
163 /* cleanup and exit */
164 cleanup();
165
subrata_modak56207ce2009-03-23 13:35:39 +0000166 /*NOTREACHED*/ return 0;
plarsa8b7bfe2002-12-05 22:00:00 +0000167
subrata_modak56207ce2009-03-23 13:35:39 +0000168} /* End main */
plarsa8b7bfe2002-12-05 22:00:00 +0000169
170/* setup() - performs all ONE TIME setup for this test */
subrata_modak56207ce2009-03-23 13:35:39 +0000171void setup()
plarsa8b7bfe2002-12-05 22:00:00 +0000172{
173 /* capture signals */
174 tst_sig(FORK, DEF_HANDLER, cleanup);
175
176 /* Pause if that option was specified */
177 TEST_PAUSE;
178
subrata_modak56207ce2009-03-23 13:35:39 +0000179} /* End setup() */
plarsa8b7bfe2002-12-05 22:00:00 +0000180
181/*
182 *cleanup() - performs all ONE TIME cleanup for this test at
183 * completion or premature exit.
184 */
subrata_modak56207ce2009-03-23 13:35:39 +0000185void cleanup()
plarsa8b7bfe2002-12-05 22:00:00 +0000186{
187
188 /*
189 * print timing stats if that option was specified.
190 * print errno log if that option was specified.
191 */
192 TEST_CLEANUP;
193
194 /* exit with return code appropriate for results */
195 tst_exit();
subrata_modak56207ce2009-03-23 13:35:39 +0000196} /* End cleanup() */