robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 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 |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : sched_rr_get_interval01 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 21 | * EXECUTED BY : root / superuser |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 23 | * TEST TITLE : Basic test for sched_rr_get_interval(2) |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 27 | * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 29 | * SIGNALS |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 30 | * Uses SIGUSR1 to pause before test if option set. |
| 31 | * (See the parse_opts(3) man page). |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 32 | * |
| 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_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 36 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 37 | * Setup: |
| 38 | * Setup signal handling. |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 39 | * Pause for SIGUSR1 if option specified. |
| 40 | * Change scheduling policy to SCHED_RR |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 42 | * Test: |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 43 | * Loop if the proper options are given. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 44 | * Execute system call |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 45 | * Check return code, if it is 0, |
| 46 | * Test passed. |
| 47 | * Otherwise |
| 48 | * Test failed |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 50 | * Cleanup: |
| 51 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 52 | * |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 53 | * 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" |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 70 | |
| 71 | static void setup(); |
| 72 | static void cleanup(); |
| 73 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 74 | char *TCID = "sched_rr_get_interval01"; |
| 75 | int TST_TOTAL = 1; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 76 | |
| 77 | struct timespec tp; |
| 78 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 79 | int main(int ac, char **av) |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 80 | { |
| 81 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 82 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 83 | const char *msg; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 84 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 85 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 86 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 87 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 88 | setup(); |
| 89 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 90 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 91 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 92 | tst_count = 0; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 93 | |
| 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_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 102 | tst_resm(TPASS, "sched_rr_get_interval() returned %ld", |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 103 | TEST_RETURN); |
| 104 | } else { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 105 | tst_resm(TFAIL | TTERRNO, |
| 106 | "Test Failed, sched_rr_get_interval()" |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 107 | "returned %ld", TEST_RETURN); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 108 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 109 | } |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 110 | |
| 111 | /* cleanup and exit */ |
| 112 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 113 | tst_exit(); |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 114 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 115 | } |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 116 | |
| 117 | /* setup() - performs all ONE TIME setup for this test */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 118 | void setup(void) |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 119 | { |
| 120 | /* |
| 121 | * Initialize scheduling parameter structure to use with |
| 122 | * sched_setscheduler() |
| 123 | */ |
| 124 | struct sched_param p = { 1 }; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 125 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 126 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 127 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 128 | 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 Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 134 | } |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | *cleanup() - performs all ONE TIME cleanup for this test at |
| 138 | * completion or premature exit. |
| 139 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 140 | void cleanup(void) |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 141 | { |
| 142 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 143 | } |