blob: 3f169e80b789677b04bd228ae3e4306e5c22ec48 [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
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "test.h"
74#include "usctest.h"
75
76#include <errno.h>
77#include <sched.h>
78
79#define LARGE_PID 999999
80
81static void cleanup(void);
82static void setup(void);
83
84static struct sched_param param;
85
86char *TCID= "sched_getparam03";
87extern int Tst_count;
88
89static int exp_enos[] = {EINVAL, ESRCH, 0}; /* 0 terminated list of *
90 * expected errnos */
91
92static struct test_case_t {
93 char *desc;
94 pid_t pid;
95 struct sched_param *p;
96 int exp_errno;
97 char err_desc[10];
98} test_cases[] = {
99 { "test with non-existing pid", LARGE_PID, &param, ESRCH, "ESRCH" },
100 { "test invalid pid value", -1, &param, EINVAL, "EINVAL" },
101 { "test with invalid address for p", 0, NULL, EINVAL, "EINVAL" },
102};
103
104int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
105
106int
107main(int ac, char **av)
108{
109 int lc, ind; /* loop counter */
110 char *msg; /* message returned from parse_opts */
111
112 /* parse standard options */
113 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL))
114 != (char *) NULL) {
115 tst_brkm(TBROK, tst_exit, "OPTION PARSING ERROR - %s", msg);
116 }
117
118 setup(); /* global setup */
119
120 /* The following loop checks looping state if -i option given */
121 for (lc = 0; TEST_LOOPING(lc); lc++) {
122 /* reset Tst_count in case we are looping */
123 Tst_count = 0;
124
125 for (ind = 0; ind < TST_TOTAL; ind++) {
126
127 /* Call sched_getparam(2) to test different test
128 * conditions. verify that it fails with -1 return
129 * value and sets appropriate errno.
subrata_modakbdbaec52009-02-26 12:14:51 +0000130 */
plarsa8b7bfe2002-12-05 22:00:00 +0000131 TEST(sched_getparam(test_cases[ind].pid,
132 test_cases[ind].p));
subrata_modakbdbaec52009-02-26 12:14:51 +0000133
plarsa8b7bfe2002-12-05 22:00:00 +0000134 if ((TEST_RETURN == -1) &&
135 (TEST_ERRNO == test_cases[ind].exp_errno)) {
136 tst_resm(TPASS, "expected failure; Got %s",
137 test_cases[ind].err_desc);
138 } else {
139 tst_resm(TFAIL, "Call failed to produce "
140 "expected error; Expected errno: %d "
141 "Got : %d, %s",
142 test_cases[ind].exp_errno,
143 TEST_ERRNO, strerror(TEST_ERRNO));
144 }
145 TEST_ERROR_LOG(TEST_ERRNO);
146 }
147 }
148
149 cleanup();
subrata_modakbdbaec52009-02-26 12:14:51 +0000150
plarsa8b7bfe2002-12-05 22:00:00 +0000151 /*NOTREACHED*/
152 return 0;
153}
154
155/*
156 * setup() - performs all the ONE TIME setup for this test.
157 */
158void
159setup(void)
160{
161
162 /* capture signals */
163 tst_sig(NOFORK, DEF_HANDLER, cleanup);
164
165 /* Set up the expected error numbers for -e option */
166 TEST_EXP_ENOS(exp_enos);
167
168 /* Pause if that option was specified */
169 TEST_PAUSE;
170
171}
172
173/*
174 * cleanup() - performs all the ONE TIME cleanup for this test at completion
175 * or premature exit.
176 */
177void
178cleanup(void)
179{
180
181 /*
182 * print timing stats if that option was specified.
183 * print errno log if that option was specified.
184 */
185 TEST_CLEANUP;
186
187 /* exit with return code appropriate for results */
188 tst_exit();
189}
190