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_interval03 |
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 : Tests for error conditions |
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 : 3 |
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 | * 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_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 42 | * Setup: |
| 43 | * Setup signal handling. |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 44 | * Set expected errors for logging. |
| 45 | * Pause for SIGUSR1 if option specified. |
| 46 | * Change scheduling policy to SCHED_RR |
| 47 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 48 | * Test: |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 49 | * Loop if the proper options are given. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 50 | * Execute system call |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 51 | * if call fails with expected errno, |
| 52 | * Test passed. |
| 53 | * Otherwise |
| 54 | * Test failed |
| 55 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 56 | * Cleanup: |
| 57 | * Print errno log and/or timing stats if options given |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 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" |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 76 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 77 | static void setup(); |
| 78 | static void cleanup(); |
| 79 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 80 | char *TCID = "sched_rr_get_interval03"; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 81 | struct timespec tp; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 82 | |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 83 | static pid_t unused_pid; |
| 84 | static pid_t inval_pid = -1; |
| 85 | static pid_t zero_pid; |
| 86 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 87 | struct test_cases_t { |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 88 | pid_t *pid; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 89 | struct timespec *tp; |
| 90 | int exp_errno; |
| 91 | } test_cases[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | { |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 93 | &inval_pid, &tp, EINVAL}, { |
| 94 | &unused_pid, &tp, ESRCH}, |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 95 | #ifndef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 96 | /* Skip since uClinux does not implement memory protection */ |
| 97 | { |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 98 | &zero_pid, (struct timespec *)-1, EFAULT} |
vapier | 7ec19d9 | 2006-02-27 04:38:56 +0000 | [diff] [blame] | 99 | #endif |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); |
| 103 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | int main(int ac, char **av) |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 105 | { |
| 106 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 107 | int lc, i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 108 | const char *msg; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 109 | |
Garrett Cooper | a9e49f1 | 2010-12-16 10:54:03 -0800 | [diff] [blame] | 110 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 111 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 112 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 113 | setup(); |
| 114 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 115 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 116 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 117 | tst_count = 0; |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 118 | |
| 119 | for (i = 0; i < TST_TOTAL; ++i) { |
| 120 | /* |
| 121 | * Call sched_rr_get_interval(2) |
| 122 | */ |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 123 | TEST(sched_rr_get_interval(*(test_cases[i].pid), |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 124 | 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 Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 130 | tst_resm(TFAIL | TTERRNO, "Test Failed," |
| 131 | " sched_rr_get_interval() returned %ld", |
| 132 | TEST_RETURN); |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 133 | } |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 134 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 135 | } |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 136 | |
| 137 | /* cleanup and exit */ |
| 138 | cleanup(); |
| 139 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 140 | tst_exit(); |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 141 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 142 | } |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 143 | |
| 144 | /* setup() - performs all ONE TIME setup for this test */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 145 | void setup(void) |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 146 | { |
| 147 | /* |
| 148 | * Initialize scheduling parameter structure to use with |
| 149 | * sched_setscheduler() |
| 150 | */ |
| 151 | struct sched_param p = { 1 }; |
| 152 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 153 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 154 | |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 155 | 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 Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 161 | |
| 162 | unused_pid = tst_get_unused_pid(cleanup); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 163 | } |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | *cleanup() - performs all ONE TIME cleanup for this test at |
| 167 | * completion or premature exit. |
| 168 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 169 | void cleanup(void) |
robbiew | 3640a38 | 2002-12-24 16:50:34 +0000 | [diff] [blame] | 170 | { |
| 171 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 172 | } |