• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 along
13  * with this program; if not, write the Free Software Foundation, Inc.,
14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  */
17 /**********************************************************
18  *
19  *    TEST IDENTIFIER	: sched_rr_get_interval03
20  *
21  *    EXECUTED BY	: root / superuser
22  *
23  *    TEST TITLE	: Tests for error conditions
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_rr_get_interval() fails with errno set to EINVAL for an
36  *	   invalid pid
37  *	2) sched_rr_get_interval() fails with errno set to ESRCH if the
38  *	   process with specified pid does not exists
39  *	2) sched_rr_get_interval() fails with errno set to EFAULT if the
40  *	   address specified as &tp is invalid
41  *
42  *	Setup:
43  *	  Setup signal handling.
44  *	  Set expected errors for logging.
45  *	  Pause for SIGUSR1 if option specified.
46  *	  Change scheduling policy to SCHED_RR
47  *
48  *	Test:
49  *	 Loop if the proper options are given.
50  *	  Execute system call
51  *	  if call fails with expected errno,
52  *		Test passed.
53  *	  Otherwise
54  *		Test failed
55  *
56  *	Cleanup:
57  *	  Print errno log and/or timing stats if options given
58  *
59  * USAGE:  <for command-line>
60  * sched_rr_get_interval03 [-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 static void setup();
78 static void cleanup();
79 
80 char *TCID = "sched_rr_get_interval03";
81 struct timespec tp;
82 
83 static pid_t unused_pid;
84 static pid_t inval_pid = -1;
85 static pid_t zero_pid;
86 
87 struct test_cases_t {
88 	pid_t *pid;
89 	struct timespec *tp;
90 	int exp_errno;
91 } test_cases[] = {
92 	{
93 	&inval_pid, &tp, EINVAL}, {
94 	&unused_pid, &tp, ESRCH},
95 #ifndef UCLINUX
96 	    /* Skip since uClinux does not implement memory protection */
97 	{
98 	&zero_pid, (struct timespec *)-1, EFAULT}
99 #endif
100 };
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 
107 	int lc, i;
108 
109 	tst_parse_opts(ac, av, NULL, NULL);
110 
111 	setup();
112 
113 	for (lc = 0; TEST_LOOPING(lc); lc++) {
114 
115 		tst_count = 0;
116 
117 		for (i = 0; i < TST_TOTAL; ++i) {
118 			/*
119 			 * Call sched_rr_get_interval(2)
120 			 */
121 			TEST(sched_rr_get_interval(*(test_cases[i].pid),
122 						   test_cases[i].tp));
123 
124 			if ((TEST_RETURN == -1) &&
125 			    (TEST_ERRNO == test_cases[i].exp_errno)) {
126 				tst_resm(TPASS, "Test Passed");
127 			} else {
128 				tst_resm(TFAIL | TTERRNO, "Test Failed,"
129 					 " sched_rr_get_interval() returned %ld",
130 					 TEST_RETURN);
131 			}
132 		}
133 	}
134 
135 	/* cleanup and exit */
136 	cleanup();
137 
138 	tst_exit();
139 
140 }
141 
142 /* setup() - performs all ONE TIME setup for this test */
setup(void)143 void setup(void)
144 {
145 	tst_require_root();
146 	/*
147 	 * Initialize scheduling parameter structure to use with
148 	 * sched_setscheduler()
149 	 */
150 	struct sched_param p = { 1 };
151 
152 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
153 
154 	TEST_PAUSE;
155 
156 	/* Change scheduling policy to SCHED_RR */
157 	if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) {
158 		tst_brkm(TBROK, cleanup, "sched_setscheduler() failed");
159 	}
160 
161 	unused_pid = tst_get_unused_pid(cleanup);
162 }
163 
164 /*
165  *cleanup() -  performs all ONE TIME cleanup for this test at
166  *		completion or premature exit.
167  */
cleanup(void)168 void cleanup(void)
169 {
170 
171 }
172