blob: f2adc9f6e265e01a5229282bb80fc4e98039132b [file] [log] [blame]
robbiew3640a382002-12-24 16:50:34 +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 along
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
robbiew3640a382002-12-24 16:50:34 +000015 *
16 */
17/**********************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
robbiew3640a382002-12-24 16:50:34 +000019 * TEST IDENTIFIER : sched_rr_get_interval03
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
robbiew3640a382002-12-24 16:50:34 +000021 * EXECUTED BY : root / superuser
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
robbiew3640a382002-12-24 16:50:34 +000023 * TEST TITLE : Tests for error conditions
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiew3640a382002-12-24 16:50:34 +000025 * TEST CASE TOTAL : 3
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
robbiew3640a382002-12-24 16:50:34 +000027 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
robbiew3640a382002-12-24 16:50:34 +000029 * SIGNALS
subrata_modak56207ce2009-03-23 13:35:39 +000030 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
robbiew3640a382002-12-24 16:50:34 +000032 *
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 *
subrata_modak56207ce2009-03-23 13:35:39 +000042 * Setup:
43 * Setup signal handling.
robbiew3640a382002-12-24 16:50:34 +000044 * Set expected errors for logging.
45 * Pause for SIGUSR1 if option specified.
46 * Change scheduling policy to SCHED_RR
47 *
subrata_modak56207ce2009-03-23 13:35:39 +000048 * Test:
robbiew3640a382002-12-24 16:50:34 +000049 * Loop if the proper options are given.
subrata_modak56207ce2009-03-23 13:35:39 +000050 * Execute system call
robbiew3640a382002-12-24 16:50:34 +000051 * if call fails with expected errno,
52 * Test passed.
53 * Otherwise
54 * Test failed
55 *
subrata_modak56207ce2009-03-23 13:35:39 +000056 * Cleanup:
57 * Print errno log and/or timing stats if options given
robbiew3640a382002-12-24 16:50:34 +000058 *
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"
robbiew3640a382002-12-24 16:50:34 +000076
robbiew3640a382002-12-24 16:50:34 +000077static void setup();
78static void cleanup();
79
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020080char *TCID = "sched_rr_get_interval03";
robbiew3640a382002-12-24 16:50:34 +000081struct timespec tp;
robbiew3640a382002-12-24 16:50:34 +000082
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040083static pid_t unused_pid;
84static pid_t inval_pid = -1;
85static pid_t zero_pid;
86
robbiew3640a382002-12-24 16:50:34 +000087struct test_cases_t {
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040088 pid_t *pid;
robbiew3640a382002-12-24 16:50:34 +000089 struct timespec *tp;
90 int exp_errno;
91} test_cases[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000092 {
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040093 &inval_pid, &tp, EINVAL}, {
94 &unused_pid, &tp, ESRCH},
vapier7ec19d92006-02-27 04:38:56 +000095#ifndef UCLINUX
subrata_modak56207ce2009-03-23 13:35:39 +000096 /* Skip since uClinux does not implement memory protection */
97 {
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040098 &zero_pid, (struct timespec *)-1, EFAULT}
vapier7ec19d92006-02-27 04:38:56 +000099#endif
robbiew3640a382002-12-24 16:50:34 +0000100};
101
102int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
103
subrata_modak56207ce2009-03-23 13:35:39 +0000104int main(int ac, char **av)
robbiew3640a382002-12-24 16:50:34 +0000105{
106
Cyril Hrubis89af32a2012-10-24 16:39:11 +0200107 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +0200108 const char *msg;
robbiew3640a382002-12-24 16:50:34 +0000109
Garrett Coopera9e49f12010-12-16 10:54:03 -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);
robbiew3640a382002-12-24 16:50:34 +0000112
robbiew3640a382002-12-24 16:50:34 +0000113 setup();
114
robbiew3640a382002-12-24 16:50:34 +0000115 for (lc = 0; TEST_LOOPING(lc); lc++) {
116
Caspar Zhangd59a6592013-03-07 14:59:12 +0800117 tst_count = 0;
robbiew3640a382002-12-24 16:50:34 +0000118
119 for (i = 0; i < TST_TOTAL; ++i) {
120 /*
121 * Call sched_rr_get_interval(2)
122 */
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400123 TEST(sched_rr_get_interval(*(test_cases[i].pid),
robbiew3640a382002-12-24 16:50:34 +0000124 test_cases[i].tp));
125
126 if ((TEST_RETURN == -1) &&
127 (TEST_ERRNO == test_cases[i].exp_errno)) {
128 tst_resm(TPASS, "Test Passed");
129 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800130 tst_resm(TFAIL | TTERRNO, "Test Failed,"
131 " sched_rr_get_interval() returned %ld",
132 TEST_RETURN);
robbiew3640a382002-12-24 16:50:34 +0000133 }
subrata_modak4bb656a2009-02-26 12:02:09 +0000134 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800135 }
robbiew3640a382002-12-24 16:50:34 +0000136
137 /* cleanup and exit */
138 cleanup();
139
Garrett Cooper53740502010-12-16 00:04:01 -0800140 tst_exit();
robbiew3640a382002-12-24 16:50:34 +0000141
Garrett Cooper2c282152010-12-16 00:55:50 -0800142}
robbiew3640a382002-12-24 16:50:34 +0000143
144/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400145void setup(void)
robbiew3640a382002-12-24 16:50:34 +0000146{
147 /*
148 * Initialize scheduling parameter structure to use with
149 * sched_setscheduler()
150 */
151 struct sched_param p = { 1 };
152
robbiew3640a382002-12-24 16:50:34 +0000153 tst_sig(NOFORK, DEF_HANDLER, cleanup);
154
robbiew3640a382002-12-24 16:50:34 +0000155 TEST_PAUSE;
156
157 /* Change scheduling policy to SCHED_RR */
158 if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) {
159 tst_brkm(TBROK, cleanup, "sched_setscheduler() failed");
160 }
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400161
162 unused_pid = tst_get_unused_pid(cleanup);
Garrett Cooper2c282152010-12-16 00:55:50 -0800163}
robbiew3640a382002-12-24 16:50:34 +0000164
165/*
166 *cleanup() - performs all ONE TIME cleanup for this test at
167 * completion or premature exit.
168 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400169void cleanup(void)
robbiew3640a382002-12-24 16:50:34 +0000170{
171
Chris Dearmanec6edca2012-10-17 19:54:01 -0700172}