blob: bbb5a15e5d812351a17892d19867a2c7d76585ed [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_interval01
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 : Basic test for sched_rr_get_interval(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
robbiew3640a382002-12-24 16:50:34 +000025 * TEST CASE TOTAL : 1
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 * This is a Phase I test for the sched_rr_get_interval(2) system call.
35 * It is intended to provide a limited exposure of the system call.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
subrata_modak56207ce2009-03-23 13:35:39 +000037 * Setup:
38 * Setup signal handling.
robbiew3640a382002-12-24 16:50:34 +000039 * Pause for SIGUSR1 if option specified.
40 * Change scheduling policy to SCHED_RR
subrata_modak4bb656a2009-02-26 12:02:09 +000041 *
subrata_modak56207ce2009-03-23 13:35:39 +000042 * Test:
robbiew3640a382002-12-24 16:50:34 +000043 * Loop if the proper options are given.
subrata_modak56207ce2009-03-23 13:35:39 +000044 * Execute system call
robbiew3640a382002-12-24 16:50:34 +000045 * Check return code, if it is 0,
46 * Test passed.
47 * Otherwise
48 * Test failed
subrata_modak4bb656a2009-02-26 12:02:09 +000049 *
subrata_modak56207ce2009-03-23 13:35:39 +000050 * Cleanup:
51 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000052 *
robbiew3640a382002-12-24 16:50:34 +000053 * USAGE: <for command-line>
54 * sched_rr_get_interval01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
55 * where, -c n : Run n copies concurrently.
56 * -e : Turn on errno logging.
57 * -h : Show help screen
58 * -f : Turn off functional testing
59 * -i n : Execute test n times.
60 * -I x : Execute test for x seconds.
61 * -p : Pause for SIGUSR1 before starting
62 * -P x : Pause for x seconds between iterations.
63 * -t : Turn on syscall timing.
64 *
65 ****************************************************************/
66
67#include <errno.h>
68#include <sched.h>
69#include "test.h"
robbiew3640a382002-12-24 16:50:34 +000070
71static void setup();
72static void cleanup();
73
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020074char *TCID = "sched_rr_get_interval01";
75int TST_TOTAL = 1;
robbiew3640a382002-12-24 16:50:34 +000076
77struct timespec tp;
78
subrata_modak56207ce2009-03-23 13:35:39 +000079int main(int ac, char **av)
robbiew3640a382002-12-24 16:50:34 +000080{
81
Cyril Hrubis89af32a2012-10-24 16:39:11 +020082 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020083 const char *msg;
robbiew3640a382002-12-24 16:50:34 +000084
Garrett Coopera9e49f12010-12-16 10:54:03 -080085 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080086 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
robbiew3640a382002-12-24 16:50:34 +000087
robbiew3640a382002-12-24 16:50:34 +000088 setup();
89
robbiew3640a382002-12-24 16:50:34 +000090 for (lc = 0; TEST_LOOPING(lc); lc++) {
91
Caspar Zhangd59a6592013-03-07 14:59:12 +080092 tst_count = 0;
robbiew3640a382002-12-24 16:50:34 +000093
94 /*
95 * Call sched_rr_get_interval(2) with pid=0 so that it will
96 * write into the timespec structure pointed to by tp, the
97 * round robin time quantum for the current process.
98 */
99 TEST(sched_rr_get_interval(0, &tp));
100
101 if (TEST_RETURN == 0) {
subrata_modak923b23f2009-11-02 13:57:16 +0000102 tst_resm(TPASS, "sched_rr_get_interval() returned %ld",
robbiew3640a382002-12-24 16:50:34 +0000103 TEST_RETURN);
104 } else {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800105 tst_resm(TFAIL | TTERRNO,
106 "Test Failed, sched_rr_get_interval()"
subrata_modak923b23f2009-11-02 13:57:16 +0000107 "returned %ld", TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000108 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800109 }
robbiew3640a382002-12-24 16:50:34 +0000110
111 /* cleanup and exit */
112 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800113 tst_exit();
robbiew3640a382002-12-24 16:50:34 +0000114
Garrett Cooper2c282152010-12-16 00:55:50 -0800115}
robbiew3640a382002-12-24 16:50:34 +0000116
117/* setup() - performs all ONE TIME setup for this test */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400118void setup(void)
robbiew3640a382002-12-24 16:50:34 +0000119{
120 /*
121 * Initialize scheduling parameter structure to use with
122 * sched_setscheduler()
123 */
124 struct sched_param p = { 1 };
subrata_modakbdbaec52009-02-26 12:14:51 +0000125
robbiew3640a382002-12-24 16:50:34 +0000126 tst_sig(NOFORK, DEF_HANDLER, cleanup);
127
robbiew3640a382002-12-24 16:50:34 +0000128 TEST_PAUSE;
129
130 /* Change scheduling policy to SCHED_RR */
131 if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) {
132 tst_brkm(TBROK, cleanup, "sched_setscheduler() failed");
133 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800134}
robbiew3640a382002-12-24 16:50:34 +0000135
136/*
137 *cleanup() - performs all ONE TIME cleanup for this test at
138 * completion or premature exit.
139 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400140void cleanup(void)
robbiew3640a382002-12-24 16:50:34 +0000141{
142
Chris Dearmanec6edca2012-10-17 19:54:01 -0700143}