plars | a8b7bfe | 2002-12-05 22:00: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 |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 15 | * |
| 16 | */ |
| 17 | /******************************************************************* |
| 18 | * |
| 19 | * TEST IDENTIFIER : sched_getparam03 |
| 20 | * |
| 21 | * EXECUTED BY : anyone |
| 22 | * |
| 23 | * TEST TITLE : testing error conditions for sched_getparam(2) |
| 24 | * |
| 25 | * TEST CASE TOTAL : 3 |
| 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_getparam(2) returns -1 and sets errno to ESRCH if the |
| 36 | * process with specified pid could not be found |
| 37 | * 2) sched_getparam(2) returns -1 and sets errno to EINVAL if |
| 38 | * the parameter pid is an invalid value (-1) |
| 39 | * 3) sched_getparam(2) returns -1 and sets errno to EINVAL if the |
| 40 | * parameter p is an invalid address |
| 41 | * |
| 42 | * ALGORITHM |
| 43 | * Setup: |
| 44 | * Setup signal handling. |
| 45 | * Pause for SIGUSR1 if option specified. |
| 46 | * |
| 47 | * Test: |
| 48 | * Loop if the proper options are given. |
| 49 | * Execute system call |
| 50 | * Check return code, if (system call failed (return=-1)) & |
| 51 | * (errno set == expected errno) |
| 52 | * Issue sys call fails with expected return value and errno. |
| 53 | * Otherwise, |
| 54 | * Issue sys call returns unexpected value. |
| 55 | * |
| 56 | * Cleanup: |
| 57 | * Print errno log and/or timing stats if options given |
| 58 | * |
| 59 | * USAGE: <for command-line> |
| 60 | * sched_getparam03 [-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 "test.h" |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 74 | |
| 75 | #include <errno.h> |
| 76 | #include <sched.h> |
| 77 | |
| 78 | #define LARGE_PID 999999 |
| 79 | |
| 80 | static void cleanup(void); |
| 81 | static void setup(void); |
| 82 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 83 | static struct sched_param param; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 84 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 85 | char *TCID = "sched_getparam03"; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 86 | |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 87 | static pid_t unused_pid; |
| 88 | static pid_t zero_pid; |
| 89 | static pid_t inval_pid = -1; |
| 90 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 91 | static struct test_case_t { |
| 92 | char *desc; |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 93 | pid_t *pid; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 94 | struct sched_param *p; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 95 | int exp_errno; |
| 96 | char err_desc[10]; |
| 97 | } test_cases[] = { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 98 | { |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 99 | "test with non-existing pid", &unused_pid, ¶m, ESRCH, "ESRCH"}, { |
| 100 | "test invalid pid value", &inval_pid, ¶m, EINVAL, "EINVAL"}, { |
| 101 | "test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"},}; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 102 | |
| 103 | int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); |
| 104 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 105 | int main(int ac, char **av) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 106 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | int lc, ind; /* loop counter */ |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 108 | const char *msg; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 109 | |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -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); |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 112 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 113 | setup(); /* global setup */ |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 114 | |
| 115 | /* The following loop checks looping state if -i option given */ |
| 116 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 117 | /* reset tst_count in case we are looping */ |
| 118 | tst_count = 0; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 119 | |
| 120 | for (ind = 0; ind < TST_TOTAL; ind++) { |
| 121 | |
| 122 | /* Call sched_getparam(2) to test different test |
| 123 | * conditions. verify that it fails with -1 return |
| 124 | * value and sets appropriate errno. |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 125 | */ |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 126 | TEST(sched_getparam(*(test_cases[ind].pid), |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | test_cases[ind].p)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 128 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 129 | if ((TEST_RETURN == -1) && |
| 130 | (TEST_ERRNO == test_cases[ind].exp_errno)) { |
| 131 | tst_resm(TPASS, "expected failure; Got %s", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 132 | test_cases[ind].err_desc); |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 133 | } else { |
| 134 | tst_resm(TFAIL, "Call failed to produce " |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 135 | "expected error; Expected errno: %d " |
| 136 | "Got : %d, %s", |
| 137 | test_cases[ind].exp_errno, |
| 138 | TEST_ERRNO, strerror(TEST_ERRNO)); |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 139 | } |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | |
| 143 | cleanup(); |
Garrett Cooper | 5374050 | 2010-12-16 00:04:01 -0800 | [diff] [blame] | 144 | tst_exit(); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 145 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* |
| 149 | * setup() - performs all the ONE TIME setup for this test. |
| 150 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 151 | void setup(void) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 152 | { |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 153 | unused_pid = tst_get_unused_pid(cleanup); |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 154 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 155 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 156 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 157 | TEST_PAUSE; |
| 158 | |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * cleanup() - performs all the ONE TIME cleanup for this test at completion |
| 163 | * or premature exit. |
| 164 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 165 | void cleanup(void) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 166 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 167 | } |