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 14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 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 (at) 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" 77 78 #include <errno.h> 79 #include <sched.h> 80 #include <pwd.h> 81 82 static void cleanup(void); 83 static void setup(void); 84 85 static struct sched_param param = { 0 }; 86 static struct sched_param param1 = { 1 }; 87 88 char *TCID = "sched_setparam04"; 89 90 static pid_t unused_pid; 91 static pid_t inval_pid = -1; 92 static pid_t zero_pid; 93 94 static struct test_case_t { 95 char *desc; 96 pid_t *pid; 97 struct sched_param *p; 98 int exp_errno; 99 char err_desc[10]; 100 } test_cases[] = { 101 { 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, 106 "EINVAL"} 107 }; 108 109 int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); 110 111 int main(int ac, char **av) 112 { 113 int lc, ind; 114 115 tst_parse_opts(ac, av, NULL, NULL); 116 117 setup(); /* global setup */ 118 119 /* The following loop checks looping state if -i option given */ 120 for (lc = 0; TEST_LOOPING(lc); lc++) { 121 /* reset tst_count in case we are looping */ 122 tst_count = 0; 123 124 for (ind = 0; ind < TST_TOTAL; ind++) { 125 /* 126 * call the system call with the TEST() macro 127 */ 128 TEST(sched_setparam(*(test_cases[ind].pid), 129 test_cases[ind].p)); 130 131 if ((TEST_RETURN == -1) && 132 (TEST_ERRNO == test_cases[ind].exp_errno)) { 133 tst_resm(TPASS, "expected failure; Got %s", 134 test_cases[ind].err_desc); 135 } else { 136 tst_resm(TFAIL, "Call failed to produce " 137 "expected error; Expected errno: %d " 138 "Got : %d, %s", 139 test_cases[ind].exp_errno, 140 TEST_ERRNO, strerror(TEST_ERRNO)); 141 } 142 } 143 } 144 145 cleanup(); 146 147 tst_exit(); 148 } 149 150 /* 151 * setup() - performs all the ONE TIME setup for this test. 152 */ 153 void setup(void) 154 { 155 unused_pid = tst_get_unused_pid(cleanup); 156 157 tst_sig(NOFORK, DEF_HANDLER, cleanup); 158 159 TEST_PAUSE; 160 161 } 162 163 /* 164 * cleanup() - performs all the ONE TIME cleanup for this test at completion 165 * or premature exit. 166 */ 167 void cleanup(void) 168 { 169 170 } 171