blob: 3d7a5609f93882ec5267e0af666eb1d5eaa857fa [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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080014 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plarsa8b7bfe2002-12-05 22:00:00 +000015 *
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"
plarsa8b7bfe2002-12-05 22:00:00 +000074
75#include <errno.h>
76#include <sched.h>
77
78#define LARGE_PID 999999
79
80static void cleanup(void);
81static void setup(void);
82
subrata_modak56207ce2009-03-23 13:35:39 +000083static struct sched_param param;
plarsa8b7bfe2002-12-05 22:00:00 +000084
subrata_modak56207ce2009-03-23 13:35:39 +000085char *TCID = "sched_getparam03";
plarsa8b7bfe2002-12-05 22:00:00 +000086
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040087static pid_t unused_pid;
88static pid_t zero_pid;
89static pid_t inval_pid = -1;
90
plarsa8b7bfe2002-12-05 22:00:00 +000091static struct test_case_t {
92 char *desc;
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040093 pid_t *pid;
subrata_modak56207ce2009-03-23 13:35:39 +000094 struct sched_param *p;
plarsa8b7bfe2002-12-05 22:00:00 +000095 int exp_errno;
96 char err_desc[10];
97} test_cases[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000098 {
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040099 "test with non-existing pid", &unused_pid, &param, ESRCH, "ESRCH"}, {
100 "test invalid pid value", &inval_pid, &param, EINVAL, "EINVAL"}, {
101 "test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"},};
plarsa8b7bfe2002-12-05 22:00:00 +0000102
103int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
104
subrata_modak56207ce2009-03-23 13:35:39 +0000105int main(int ac, char **av)
plarsa8b7bfe2002-12-05 22:00:00 +0000106{
subrata_modak56207ce2009-03-23 13:35:39 +0000107 int lc, ind; /* loop counter */
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200108 const char *msg;
plarsa8b7bfe2002-12-05 22:00:00 +0000109
Garrett Cooper53740502010-12-16 00:04:01 -0800110 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -0800111 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plarsa8b7bfe2002-12-05 22:00:00 +0000112
subrata_modak56207ce2009-03-23 13:35:39 +0000113 setup(); /* global setup */
plarsa8b7bfe2002-12-05 22:00:00 +0000114
115 /* The following loop checks looping state if -i option given */
116 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +0800117 /* reset tst_count in case we are looping */
118 tst_count = 0;
plarsa8b7bfe2002-12-05 22:00:00 +0000119
120 for (ind = 0; ind < TST_TOTAL; ind++) {
121
122 /* Call sched_getparam(2) to test different test
123 * conditions. verify that it fails with -1 return
124 * value and sets appropriate errno.
subrata_modakbdbaec52009-02-26 12:14:51 +0000125 */
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400126 TEST(sched_getparam(*(test_cases[ind].pid),
subrata_modak56207ce2009-03-23 13:35:39 +0000127 test_cases[ind].p));
subrata_modakbdbaec52009-02-26 12:14:51 +0000128
plarsa8b7bfe2002-12-05 22:00:00 +0000129 if ((TEST_RETURN == -1) &&
130 (TEST_ERRNO == test_cases[ind].exp_errno)) {
131 tst_resm(TPASS, "expected failure; Got %s",
subrata_modak56207ce2009-03-23 13:35:39 +0000132 test_cases[ind].err_desc);
plarsa8b7bfe2002-12-05 22:00:00 +0000133 } else {
134 tst_resm(TFAIL, "Call failed to produce "
subrata_modak56207ce2009-03-23 13:35:39 +0000135 "expected error; Expected errno: %d "
136 "Got : %d, %s",
137 test_cases[ind].exp_errno,
138 TEST_ERRNO, strerror(TEST_ERRNO));
plarsa8b7bfe2002-12-05 22:00:00 +0000139 }
plarsa8b7bfe2002-12-05 22:00:00 +0000140 }
141 }
142
143 cleanup();
Garrett Cooper53740502010-12-16 00:04:01 -0800144 tst_exit();
subrata_modakbdbaec52009-02-26 12:14:51 +0000145
plarsa8b7bfe2002-12-05 22:00:00 +0000146}
147
148/*
149 * setup() - performs all the ONE TIME setup for this test.
150 */
subrata_modak56207ce2009-03-23 13:35:39 +0000151void setup(void)
plarsa8b7bfe2002-12-05 22:00:00 +0000152{
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400153 unused_pid = tst_get_unused_pid(cleanup);
plarsa8b7bfe2002-12-05 22:00:00 +0000154
plarsa8b7bfe2002-12-05 22:00:00 +0000155 tst_sig(NOFORK, DEF_HANDLER, cleanup);
156
plarsa8b7bfe2002-12-05 22:00:00 +0000157 TEST_PAUSE;
158
159}
160
161/*
162 * cleanup() - performs all the ONE TIME cleanup for this test at completion
163 * or premature exit.
164 */
subrata_modak56207ce2009-03-23 13:35:39 +0000165void cleanup(void)
plarsa8b7bfe2002-12-05 22:00:00 +0000166{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700167}