blob: 303b82aa688e18101249b7579b8b23829a50a882 [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
13 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080014 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
vapierd13d74b2006-02-11 07:24:00 +000015 *
16 */
17 /*******************************************************************
18 *
19 * TEST IDENTIFIER : sched_setparam04
20 *
21 * EXECUTED BY : anyone
22 *
23 * TEST TITLE : testing error conditions for sched_setparam(2)
24 *
25 * TEST CASE TOTAL : 4
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 * Verify that,
35 * 1) sched_setparam(2) returns -1 and sets errno to ESRCH if the
36 * process with specified pid could not be found
37 * 2) sched_setparam(2) returns -1 and sets errno to EINVAL if
38 * the parameter pid is an invalid value (-1)
39 * 3) sched_setparam(2) returns -1 and sets errno to EINVAL if the
40 * parameter p is an invalid address
41 * 4) sched_setparam(2) returns -1 sets errno to EINVAL if the
42 * value for p.sched_priority is other than 0 for scheduling
43 * policy, SCHED_OTHER
44 *
45 * ALGORITHM
46 * Setup:
47 * Setup signal handling.
48 * Pause for SIGUSR1 if option specified.
49 *
50 * Test:
51 * Loop if the proper options are given.
52 * Execute system call
53 * Check return code, if (system call failed (return=-1)) &
54 * (errno set == expected errno)
55 * Issue sys call fails with expected return value and errno.
56 * Otherwise,
57 * Issue sys call returns unexpected value.
58 *
59 * Cleanup:
60 * Print errno log and/or timing stats if options given
61 *
62 * USAGE: <for command-line>
63 * sched_setparam04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
64 * where, -c n : Run n copies concurrently.
65 * -e : Turn on errno logging.
66 * -h : Show help screen
67 * -f : Turn off functional testing
68 * -i n : Execute test n times.
69 * -I x : Execute test for x seconds.
70 * -p : Pause for SIGUSR1 before starting
71 * -P x : Pause for x seconds between iterations.
72 * -t : Turn on syscall timing.
73 *
74 *********************************************************************/
75
76#include "test.h"
vapierd13d74b2006-02-11 07:24:00 +000077
78#include <errno.h>
79#include <sched.h>
80#include <pwd.h>
81
vapierd13d74b2006-02-11 07:24:00 +000082static void cleanup(void);
83static void setup(void);
84
subrata_modak56207ce2009-03-23 13:35:39 +000085static struct sched_param param = { 0 };
86static struct sched_param param1 = { 1 };
vapierd13d74b2006-02-11 07:24:00 +000087
subrata_modak56207ce2009-03-23 13:35:39 +000088char *TCID = "sched_setparam04";
vapierd13d74b2006-02-11 07:24:00 +000089
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040090static pid_t unused_pid;
91static pid_t inval_pid = -1;
92static pid_t zero_pid;
93
vapierd13d74b2006-02-11 07:24:00 +000094static struct test_case_t {
95 char *desc;
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040096 pid_t *pid;
subrata_modak56207ce2009-03-23 13:35:39 +000097 struct sched_param *p;
vapierd13d74b2006-02-11 07:24:00 +000098 int exp_errno;
99 char err_desc[10];
100} test_cases[] = {
subrata_modak56207ce2009-03-23 13:35:39 +0000101 {
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400102 "test with non-existing pid", &unused_pid, &param, ESRCH, "ESRCH"}, {
103 "test invalid pid value", &inval_pid, &param, EINVAL, "EINVAL"}, {
104 "test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"}, {
105 "test with invalid p.sched_priority", &zero_pid, &param1, EINVAL,
subrata_modak56207ce2009-03-23 13:35:39 +0000106 "EINVAL"}
vapierd13d74b2006-02-11 07:24:00 +0000107};
108
109int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
110
subrata_modak56207ce2009-03-23 13:35:39 +0000111int main(int ac, char **av)
vapierd13d74b2006-02-11 07:24:00 +0000112{
subrata_modak56207ce2009-03-23 13:35:39 +0000113 int lc, ind; /* loop counter */
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200114 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +0000115
Garrett Cooper53740502010-12-16 00:04:01 -0800116 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800117 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000118
subrata_modak56207ce2009-03-23 13:35:39 +0000119 setup(); /* global setup */
vapierd13d74b2006-02-11 07:24:00 +0000120
121 /* The following loop checks looping state if -i option given */
122 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800123 /* reset tst_count in case we are looping */
124 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +0000125
subrata_modak56207ce2009-03-23 13:35:39 +0000126 for (ind = 0; ind < TST_TOTAL; ind++) {
vapierd13d74b2006-02-11 07:24:00 +0000127 /*
128 * call the system call with the TEST() macro
subrata_modak56207ce2009-03-23 13:35:39 +0000129 */
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400130 TEST(sched_setparam(*(test_cases[ind].pid),
subrata_modak56207ce2009-03-23 13:35:39 +0000131 test_cases[ind].p));
subrata_modakbdbaec52009-02-26 12:14:51 +0000132
vapierd13d74b2006-02-11 07:24:00 +0000133 if ((TEST_RETURN == -1) &&
134 (TEST_ERRNO == test_cases[ind].exp_errno)) {
135 tst_resm(TPASS, "expected failure; Got %s",
subrata_modak56207ce2009-03-23 13:35:39 +0000136 test_cases[ind].err_desc);
vapierd13d74b2006-02-11 07:24:00 +0000137 } else {
138 tst_resm(TFAIL, "Call failed to produce "
subrata_modak56207ce2009-03-23 13:35:39 +0000139 "expected error; Expected errno: %d "
140 "Got : %d, %s",
141 test_cases[ind].exp_errno,
142 TEST_ERRNO, strerror(TEST_ERRNO));
vapierd13d74b2006-02-11 07:24:00 +0000143 }
vapierd13d74b2006-02-11 07:24:00 +0000144 }
145 }
146
147 cleanup();
subrata_modakbdbaec52009-02-26 12:14:51 +0000148
Garrett Cooper53740502010-12-16 00:04:01 -0800149 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000150}
151
152/*
153 * setup() - performs all the ONE TIME setup for this test.
154 */
subrata_modak56207ce2009-03-23 13:35:39 +0000155void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000156{
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400157 unused_pid = tst_get_unused_pid(cleanup);
vapierd13d74b2006-02-11 07:24:00 +0000158
vapierd13d74b2006-02-11 07:24:00 +0000159 tst_sig(NOFORK, DEF_HANDLER, cleanup);
160
vapierd13d74b2006-02-11 07:24:00 +0000161 TEST_PAUSE;
162
163}
164
165/*
166 * cleanup() - performs all the ONE TIME cleanup for this test at completion
167 * or premature exit.
168 */
subrata_modak56207ce2009-03-23 13:35:39 +0000169void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000170{
subrata_modakbdbaec52009-02-26 12:14:51 +0000171
Chris Dearmanec6edca2012-10-17 19:54:01 -0700172}