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_getparam03
20 *
21 * EXECUTED BY : anyone
22 *
23 * TEST TITLE : testing error conditions for sched_getparam(2)
24 *
25 * TEST CASE TOTAL : 3
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_getparam(2) returns -1 and sets errno to ESRCH if the
36 * process with specified pid could not be found
37 * 2) sched_getparam(2) returns -1 and sets errno to EINVAL if
38 * the parameter pid is an invalid value (-1)
39 * 3) sched_getparam(2) returns -1 and sets errno to EINVAL if the
40 * parameter p is an invalid address
41 *
42 * ALGORITHM
43 * Setup:
44 * Setup signal handling.
45 * Pause for SIGUSR1 if option specified.
46 *
47 * Test:
48 * Loop if the proper options are given.
49 * Execute system call
50 * Check return code, if (system call failed (return=-1)) &
51 * (errno set == expected errno)
52 * Issue sys call fails with expected return value and errno.
53 * Otherwise,
54 * Issue sys call returns unexpected value.
55 *
56 * Cleanup:
57 * Print errno log and/or timing stats if options given
58 *
59 * USAGE: <for command-line>
60 * sched_getparam03 [-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 "test.h"
76
77 #define LARGE_PID 999999
78
79 static void cleanup(void);
80 static void setup(void);
81
82 static struct sched_param param;
83
84 char *TCID = "sched_getparam03";
85
86 static pid_t unused_pid;
87 static pid_t zero_pid;
88 static pid_t inval_pid = -1;
89
90 static struct test_case_t {
91 char *desc;
92 pid_t *pid;
93 struct sched_param *p;
94 int exp_errno;
95 char err_desc[10];
96 } test_cases[] = {
97 {
98 "test with non-existing pid", &unused_pid, ¶m, ESRCH, "ESRCH"}, {
99 "test invalid pid value", &inval_pid, ¶m, EINVAL, "EINVAL"}, {
100 "test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"},};
101
102 int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
103
main(int ac,char ** av)104 int main(int ac, char **av)
105 {
106 int lc, ind;
107
108 tst_parse_opts(ac, av, NULL, NULL);
109
110 setup(); /* global setup */
111
112 /* The following loop checks looping state if -i option given */
113 for (lc = 0; TEST_LOOPING(lc); lc++) {
114 /* reset tst_count in case we are looping */
115 tst_count = 0;
116
117 for (ind = 0; ind < TST_TOTAL; ind++) {
118
119 /* Call sched_getparam(2) to test different test
120 * conditions. verify that it fails with -1 return
121 * value and sets appropriate errno.
122 */
123 TEST(sched_getparam(*(test_cases[ind].pid),
124 test_cases[ind].p));
125
126 if ((TEST_RETURN == -1) &&
127 (TEST_ERRNO == test_cases[ind].exp_errno)) {
128 tst_resm(TPASS, "expected failure; Got %s",
129 test_cases[ind].err_desc);
130 } else {
131 tst_resm(TFAIL, "Call failed to produce "
132 "expected error; Expected errno: %d "
133 "Got : %d, %s",
134 test_cases[ind].exp_errno,
135 TEST_ERRNO, strerror(TEST_ERRNO));
136 }
137 }
138 }
139
140 cleanup();
141 tst_exit();
142
143 }
144
145 /*
146 * setup() - performs all the ONE TIME setup for this test.
147 */
setup(void)148 void setup(void)
149 {
150 unused_pid = tst_get_unused_pid(cleanup);
151
152 tst_sig(NOFORK, DEF_HANDLER, cleanup);
153
154 TEST_PAUSE;
155
156 }
157
158 /*
159 * cleanup() - performs all the ONE TIME cleanup for this test at completion
160 * or premature exit.
161 */
cleanup(void)162 void cleanup(void)
163 {
164 }
165