vapier | d13d74b | 2006-02-11 07:24:00 +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 |
| 13 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /******************************************************************* |
| 18 | * |
| 19 | * TEST IDENTIFIER : sched_setparam04 |
| 20 | * |
| 21 | * EXECUTED BY : anyone |
| 22 | * |
| 23 | * TEST TITLE : testing error conditions for sched_setparam(2) |
| 24 | * |
| 25 | * TEST CASE TOTAL : 4 |
| 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_setparam(2) returns -1 and sets errno to ESRCH if the |
| 36 | * process with specified pid could not be found |
| 37 | * 2) sched_setparam(2) returns -1 and sets errno to EINVAL if |
| 38 | * the parameter pid is an invalid value (-1) |
| 39 | * 3) sched_setparam(2) returns -1 and sets errno to EINVAL if the |
| 40 | * parameter p is an invalid address |
| 41 | * 4) sched_setparam(2) returns -1 sets errno to EINVAL if the |
| 42 | * value for p.sched_priority is other than 0 for scheduling |
| 43 | * policy, SCHED_OTHER |
| 44 | * |
| 45 | * ALGORITHM |
| 46 | * Setup: |
| 47 | * Setup signal handling. |
| 48 | * Pause for SIGUSR1 if option specified. |
| 49 | * |
| 50 | * Test: |
| 51 | * Loop if the proper options are given. |
| 52 | * Execute system call |
| 53 | * Check return code, if (system call failed (return=-1)) & |
| 54 | * (errno set == expected errno) |
| 55 | * Issue sys call fails with expected return value and errno. |
| 56 | * Otherwise, |
| 57 | * Issue sys call returns unexpected value. |
| 58 | * |
| 59 | * Cleanup: |
| 60 | * Print errno log and/or timing stats if options given |
| 61 | * |
| 62 | * USAGE: <for command-line> |
| 63 | * sched_setparam04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] |
| 64 | * where, -c n : Run n copies concurrently. |
| 65 | * -e : Turn on errno logging. |
| 66 | * -h : Show help screen |
| 67 | * -f : Turn off functional testing |
| 68 | * -i n : Execute test n times. |
| 69 | * -I x : Execute test for x seconds. |
| 70 | * -p : Pause for SIGUSR1 before starting |
| 71 | * -P x : Pause for x seconds between iterations. |
| 72 | * -t : Turn on syscall timing. |
| 73 | * |
| 74 | *********************************************************************/ |
| 75 | |
| 76 | #include "test.h" |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 77 | |
| 78 | #include <errno.h> |
| 79 | #include <sched.h> |
| 80 | #include <pwd.h> |
| 81 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 82 | static void cleanup(void); |
| 83 | static void setup(void); |
| 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | static struct sched_param param = { 0 }; |
| 86 | static struct sched_param param1 = { 1 }; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 87 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 88 | char *TCID = "sched_setparam04"; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 89 | |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 90 | static pid_t unused_pid; |
| 91 | static pid_t inval_pid = -1; |
| 92 | static pid_t zero_pid; |
| 93 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 94 | static struct test_case_t { |
| 95 | char *desc; |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 96 | pid_t *pid; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | struct sched_param *p; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 98 | int exp_errno; |
| 99 | char err_desc[10]; |
| 100 | } test_cases[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 101 | { |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 102 | "test with non-existing pid", &unused_pid, ¶m, ESRCH, "ESRCH"}, { |
| 103 | "test invalid pid value", &inval_pid, ¶m, EINVAL, "EINVAL"}, { |
| 104 | "test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"}, { |
| 105 | "test with invalid p.sched_priority", &zero_pid, ¶m1, EINVAL, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 106 | "EINVAL"} |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); |
| 110 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 111 | int main(int ac, char **av) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 112 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | int lc, ind; /* loop counter */ |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 114 | const char *msg; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 115 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 116 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 117 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 118 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 119 | setup(); /* global setup */ |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 120 | |
| 121 | /* The following loop checks looping state if -i option given */ |
| 122 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 123 | /* reset tst_count in case we are looping */ |
| 124 | tst_count = 0; |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 125 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 126 | for (ind = 0; ind < TST_TOTAL; ind++) { |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 127 | /* |
| 128 | * call the system call with the TEST() macro |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 129 | */ |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 130 | TEST(sched_setparam(*(test_cases[ind].pid), |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | test_cases[ind].p)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 132 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 133 | if ((TEST_RETURN == -1) && |
| 134 | (TEST_ERRNO == test_cases[ind].exp_errno)) { |
| 135 | tst_resm(TPASS, "expected failure; Got %s", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | test_cases[ind].err_desc); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 137 | } else { |
| 138 | tst_resm(TFAIL, "Call failed to produce " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 139 | "expected error; Expected errno: %d " |
| 140 | "Got : %d, %s", |
| 141 | test_cases[ind].exp_errno, |
| 142 | TEST_ERRNO, strerror(TEST_ERRNO)); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 143 | } |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
| 147 | cleanup(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 148 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 149 | tst_exit(); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* |
| 153 | * setup() - performs all the ONE TIME setup for this test. |
| 154 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 155 | void setup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 156 | { |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 157 | unused_pid = tst_get_unused_pid(cleanup); |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 158 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 159 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 160 | |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 161 | TEST_PAUSE; |
| 162 | |
| 163 | } |
| 164 | |
| 165 | /* |
| 166 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 167 | * or premature exit. |
| 168 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 169 | void cleanup(void) |
vapier | d13d74b | 2006-02-11 07:24:00 +0000 | [diff] [blame] | 170 | { |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 171 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 172 | } |