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
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
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 <errno.h>
77 #include <sched.h>
78 #include <pwd.h>
79 #include "test.h"
80
81 static void cleanup(void);
82 static void setup(void);
83
84 static struct sched_param param = { 0 };
85 static struct sched_param param1 = { 1 };
86
87 char *TCID = "sched_setparam04";
88
89 static pid_t unused_pid;
90 static pid_t inval_pid = -1;
91 static pid_t zero_pid;
92
93 static struct test_case_t {
94 char *desc;
95 pid_t *pid;
96 struct sched_param *p;
97 int exp_errno;
98 char err_desc[10];
99 } test_cases[] = {
100 {
101 "test with non-existing pid", &unused_pid, ¶m, ESRCH, "ESRCH"}, {
102 "test invalid pid value", &inval_pid, ¶m, EINVAL, "EINVAL"}, {
103 "test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"}, {
104 "test with invalid p.sched_priority", &zero_pid, ¶m1, EINVAL,
105 "EINVAL"}
106 };
107
108 int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
109
main(int ac,char ** av)110 int main(int ac, char **av)
111 {
112 int lc, ind;
113
114 tst_parse_opts(ac, av, NULL, NULL);
115
116 setup(); /* global setup */
117
118 /* The following loop checks looping state if -i option given */
119 for (lc = 0; TEST_LOOPING(lc); lc++) {
120 /* reset tst_count in case we are looping */
121 tst_count = 0;
122
123 for (ind = 0; ind < TST_TOTAL; ind++) {
124 /*
125 * call the system call with the TEST() macro
126 */
127 TEST(sched_setparam(*(test_cases[ind].pid),
128 test_cases[ind].p));
129
130 if ((TEST_RETURN == -1) &&
131 (TEST_ERRNO == test_cases[ind].exp_errno)) {
132 tst_resm(TPASS, "expected failure; Got %s",
133 test_cases[ind].err_desc);
134 } else {
135 tst_resm(TFAIL, "Call failed to produce "
136 "expected error; Expected errno: %d "
137 "Got : %d, %s",
138 test_cases[ind].exp_errno,
139 TEST_ERRNO, strerror(TEST_ERRNO));
140 }
141 }
142 }
143
144 cleanup();
145
146 tst_exit();
147 }
148
149 /*
150 * setup() - performs all the ONE TIME setup for this test.
151 */
setup(void)152 void setup(void)
153 {
154 unused_pid = tst_get_unused_pid(cleanup);
155
156 tst_sig(NOFORK, DEF_HANDLER, cleanup);
157
158 TEST_PAUSE;
159
160 }
161
162 /*
163 * cleanup() - performs all the ONE TIME cleanup for this test at completion
164 * or premature exit.
165 */
cleanup(void)166 void cleanup(void)
167 {
168
169 }
170