1 /* 2 * 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 20 /* 21 * NAME 22 * sched_setscheduler01.c 23 * 24 * DESCRIPTION 25 * Testcase to test whether sched_setscheduler(2) sets the errnos 26 * correctly. 27 * 28 * ALGORITHM 29 * 1. Call sched_setscheduler with an invalid pid, and expect 30 * ESRCH to be returned. 31 * 2. Call sched_setscheduler with an invalid scheduling policy, 32 * and expect EINVAL to be returned. 33 * 3. Call sched_setscheduler with an invalid "param" address, 34 * which lies outside the address space of the process, and expect 35 * EFAULT to be returned. 36 * 4. Call sched_setscheduler with an invalid priority value 37 * in "param" and expect EINVAL to be returned 38 * 39 * USAGE: <for command-line> 40 * sched_setscheduler01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] 41 * where, -c n : Run n copies concurrently. 42 * -e : Turn on errno logging. 43 * -i n : Execute test n times. 44 * -I x : Execute test for x seconds. 45 * -P x : Pause for x seconds between iterations. 46 * -t : Turn on syscall timing. 47 * 48 * HISTORY 49 * 07/2001 Ported by Wayne Boyer 50 * 51 * RESTRICTIONS 52 * None 53 */ 54 #include <stdio.h> 55 #include <errno.h> 56 #include <sched.h> 57 #include <pwd.h> 58 #include "test.h" 59 60 #define SCHED_INVALID 99 61 62 char *TCID = "sched_setscheduler01"; 63 64 struct sched_param param; 65 struct sched_param param1 = { 1 }; 66 67 void setup(void); 68 void cleanup(void); 69 70 static pid_t unused_pid; 71 static pid_t init_pid = 1; 72 static pid_t zero_pid; 73 74 struct test_case_t { 75 pid_t *pid; 76 int policy; 77 struct sched_param *p; 78 int error; 79 } TC[] = { 80 /* The pid is invalid - ESRCH */ 81 { 82 &unused_pid, SCHED_OTHER, ¶m, ESRCH}, 83 /* The policy is invalid - EINVAL */ 84 { 85 &init_pid, SCHED_INVALID, ¶m, EINVAL}, 86 #ifndef UCLINUX 87 /* Skip since uClinux does not implement memory protection */ 88 /* The param address is invalid - EFAULT */ 89 { 90 &init_pid, SCHED_OTHER, (struct sched_param *)-1, EFAULT}, 91 #endif 92 /* The priority value in param invalid - EINVAL */ 93 { 94 &zero_pid, SCHED_OTHER, ¶m1, EINVAL} 95 }; 96 97 int TST_TOTAL = ARRAY_SIZE(TC); 98 99 int main(int ac, char **av) 100 { 101 int lc; 102 103 int i; 104 105 tst_parse_opts(ac, av, NULL, NULL); 106 107 for (lc = 0; TEST_LOOPING(lc); lc++) { 108 /* reset tst_count in case we are looping */ 109 tst_count = 0; 110 111 setup(); 112 113 /* loop through the test cases */ 114 for (i = 0; i < TST_TOTAL; i++) { 115 116 TEST(sched_setscheduler(*(TC[i].pid), TC[i].policy, 117 TC[i].p)); 118 119 if (TEST_RETURN != -1) { 120 tst_resm(TFAIL, "call succeeded unexpectedly"); 121 continue; 122 } 123 124 if (TEST_ERRNO == TC[i].error) { 125 tst_resm(TPASS, "expected failure - " 126 "errno = %d : %s", TEST_ERRNO, 127 strerror(TEST_ERRNO)); 128 } else { 129 tst_resm(TFAIL, "unexpected error - %d : %s - " 130 "expected %d", TEST_ERRNO, 131 strerror(TEST_ERRNO), TC[i].error); 132 } 133 } 134 } 135 cleanup(); 136 137 tst_exit(); 138 139 } 140 141 /* 142 * setup() - performs all ONE TIME setup for this test. 143 */ 144 void setup(void) 145 { 146 unused_pid = tst_get_unused_pid(cleanup); 147 148 tst_sig(NOFORK, DEF_HANDLER, cleanup); 149 150 TEST_PAUSE; 151 } 152 153 /* 154 * cleanup() - performs all ONE TIME cleanup for this test at 155 * completion or premature exit. 156 */ 157 void cleanup(void) 158 { 159 160 } 161