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_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 (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_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" 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 83 static struct sched_param param; 84 85 char *TCID = "sched_getparam03"; 86 87 static pid_t unused_pid; 88 static pid_t zero_pid; 89 static pid_t inval_pid = -1; 90 91 static struct test_case_t { 92 char *desc; 93 pid_t *pid; 94 struct sched_param *p; 95 int exp_errno; 96 char err_desc[10]; 97 } test_cases[] = { 98 { 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"},}; 102 103 int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]); 104 105 int main(int ac, char **av) 106 { 107 int lc, ind; 108 109 tst_parse_opts(ac, av, NULL, NULL); 110 111 setup(); /* global setup */ 112 113 /* The following loop checks looping state if -i option given */ 114 for (lc = 0; TEST_LOOPING(lc); lc++) { 115 /* reset tst_count in case we are looping */ 116 tst_count = 0; 117 118 for (ind = 0; ind < TST_TOTAL; ind++) { 119 120 /* Call sched_getparam(2) to test different test 121 * conditions. verify that it fails with -1 return 122 * value and sets appropriate errno. 123 */ 124 TEST(sched_getparam(*(test_cases[ind].pid), 125 test_cases[ind].p)); 126 127 if ((TEST_RETURN == -1) && 128 (TEST_ERRNO == test_cases[ind].exp_errno)) { 129 tst_resm(TPASS, "expected failure; Got %s", 130 test_cases[ind].err_desc); 131 } else { 132 tst_resm(TFAIL, "Call failed to produce " 133 "expected error; Expected errno: %d " 134 "Got : %d, %s", 135 test_cases[ind].exp_errno, 136 TEST_ERRNO, strerror(TEST_ERRNO)); 137 } 138 } 139 } 140 141 cleanup(); 142 tst_exit(); 143 144 } 145 146 /* 147 * setup() - performs all the ONE TIME setup for this test. 148 */ 149 void setup(void) 150 { 151 unused_pid = tst_get_unused_pid(cleanup); 152 153 tst_sig(NOFORK, DEF_HANDLER, cleanup); 154 155 TEST_PAUSE; 156 157 } 158 159 /* 160 * cleanup() - performs all the ONE TIME cleanup for this test at completion 161 * or premature exit. 162 */ 163 void cleanup(void) 164 { 165 } 166