blob: b9898dccc09967d1c47bf198a6664667eb044816 [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
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.
plarsa8b7bfe2002-12-05 22:00:00 +000015 *
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"
plarsa8b7bfe2002-12-05 22:00:00 +000078
79static void setup();
80static void cleanup();
81
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020082char *TCID = "sched_getparam02";
83int TST_TOTAL = 1;
plarsa8b7bfe2002-12-05 22:00:00 +000084
85static struct sched_param param;
86
subrata_modak56207ce2009-03-23 13:35:39 +000087int main(int ac, char **av)
plarsa8b7bfe2002-12-05 22:00:00 +000088{
89
Cyril Hrubis89af32a2012-10-24 16:39:11 +020090 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020091 const char *msg;
plarsa8b7bfe2002-12-05 22:00:00 +000092 int status;
93 pid_t child_pid;
94
Garrett Cooper0ae003b2010-12-19 10:36:32 -080095 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080096 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plarsa8b7bfe2002-12-05 22:00:00 +000097
plarsa8b7bfe2002-12-05 22:00:00 +000098 setup();
99
plarsa8b7bfe2002-12-05 22:00:00 +0000100 for (lc = 0; TEST_LOOPING(lc); lc++) {
101
Caspar Zhangd59a6592013-03-07 14:59:12 +0800102 tst_count = 0;
subrata_modakbdbaec52009-02-26 12:14:51 +0000103
subrata_modak56207ce2009-03-23 13:35:39 +0000104 switch (child_pid = FORK_OR_VFORK()) {
plarsa8b7bfe2002-12-05 22:00:00 +0000105
106 case -1:
107 /* fork() failed */
108 tst_resm(TFAIL, "fork() failed");
109 continue;
110
111 case 0:
112 /* Child */
113 param.sched_priority = 100;
114
subrata_modak4bb656a2009-02-26 12:02:09 +0000115 /*
plarsa8b7bfe2002-12-05 22:00:00 +0000116 * Call sched_getparam(2) with pid = getppid() sothat
117 * it will get the scheduling parameters for parent
118 * process
119 */
120 TEST(sched_getparam(getppid(), &param));
subrata_modakbdbaec52009-02-26 12:14:51 +0000121
plarsa8b7bfe2002-12-05 22:00:00 +0000122 /*
subrata_modak56207ce2009-03-23 13:35:39 +0000123 * Check return code & priority. For normal process,
plarsa8b7bfe2002-12-05 22:00:00 +0000124 * scheduling policy is SCHED_OTHER. For this
125 * scheduling policy, only allowed priority value is 0.
126 * So we should get 0 for priority value
127 */
Garrett Cooper0ae003b2010-12-19 10:36:32 -0800128 if (TEST_RETURN == 0 && param.sched_priority == 0)
plarsa8b7bfe2002-12-05 22:00:00 +0000129 exit(0);
Garrett Cooper0ae003b2010-12-19 10:36:32 -0800130 else {
plarsa8b7bfe2002-12-05 22:00:00 +0000131 tst_resm(TWARN, "sched_getparam()"
subrata_modak923b23f2009-11-02 13:57:16 +0000132 "returned %ld, errno = %d : %s;"
plarsa8b7bfe2002-12-05 22:00:00 +0000133 " returned process priority value"
134 " is %d", TEST_RETURN, TEST_ERRNO,
135 strerror(TEST_ERRNO),
136 param.sched_priority);
137 exit(1);
138 }
139
140 default:
141 /* Parent */
142 if ((waitpid(child_pid, &status, 0)) < 0) {
143 tst_resm(TFAIL, "wait() failed");
144 continue;
145 }
Garrett Cooper0ae003b2010-12-19 10:36:32 -0800146 if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0))
plarsa8b7bfe2002-12-05 22:00:00 +0000147 tst_resm(TPASS, "Test Passed");
Garrett Cooper0ae003b2010-12-19 10:36:32 -0800148 else
plarsa8b7bfe2002-12-05 22:00:00 +0000149 tst_resm(TFAIL, "Test Failed");
plarsa8b7bfe2002-12-05 22:00:00 +0000150 }
151
Garrett Cooper2c282152010-12-16 00:55:50 -0800152 }
plarsa8b7bfe2002-12-05 22:00:00 +0000153
plarsa8b7bfe2002-12-05 22:00:00 +0000154 cleanup();
Garrett Cooperc89ea2b2010-12-19 10:07:55 -0800155 tst_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800156}
plarsa8b7bfe2002-12-05 22:00:00 +0000157
158/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400159void setup(void)
plarsa8b7bfe2002-12-05 22:00:00 +0000160{
Garrett Cooper2c282152010-12-16 00:55:50 -0800161
plarsa8b7bfe2002-12-05 22:00:00 +0000162 tst_sig(FORK, DEF_HANDLER, cleanup);
163
plarsa8b7bfe2002-12-05 22:00:00 +0000164 TEST_PAUSE;
165
Garrett Cooper2c282152010-12-16 00:55:50 -0800166}
plarsa8b7bfe2002-12-05 22:00:00 +0000167
168/*
169 *cleanup() - performs all ONE TIME cleanup for this test at
170 * completion or premature exit.
171 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400172void cleanup(void)
plarsa8b7bfe2002-12-05 22:00:00 +0000173{
Garrett Cooperc89ea2b2010-12-19 10:07:55 -0800174}