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 * Test Name: getpriority02 22 * 23 * Test Description: 24 * Verify that, 25 * 1) getpriority() sets errno to ESRCH if no process was located 26 * was located for 'which' and 'who' arguments. 27 * 2) getpriority() sets errno to EINVAL if 'which' argument was 28 * not one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER. 29 * 30 * Expected Result: 31 * getpriority() should fail with return value -1 and set expected errno. 32 * 33 * Algorithm: 34 * Setup: 35 * Setup signal handling. 36 * Pause for SIGUSR1 if option specified. 37 * 38 * Test: 39 * Loop if the proper options are given. 40 * Execute system call 41 * Check return code, if system call failed (return=-1) 42 * if errno set == expected errno 43 * Issue sys call fails with expected return value and errno. 44 * Otherwise, 45 * Issue sys call fails with unexpected errno. 46 * Otherwise, 47 * Issue sys call returns unexpected value. 48 * 49 * Cleanup: 50 * Print errno log and/or timing stats if options given 51 * 52 * Usage: <for command-line> 53 * getpriority02 [-c n] [-e] [-i n] [-I x] [-p x] [-t] 54 * where, -c n : Run n copies concurrently. 55 * -e : Turn on errno logging. 56 * -i n : Execute test n times. 57 * -I x : Execute test for x seconds. 58 * -P x : Pause for x seconds between iterations. 59 * -t : Turn on syscall timing. 60 * 61 * HISTORY 62 * 07/2001 Ported by Wayne Boyer 63 * 64 * RESTRICTIONS: 65 * None. 66 */ 67 68 #include <stdio.h> 69 #include <unistd.h> 70 #include <sys/types.h> 71 #include <errno.h> 72 #include <fcntl.h> 73 #include <string.h> 74 #include <signal.h> 75 #include <sys/param.h> 76 #include <sys/time.h> 77 #include <sys/resource.h> 78 79 #include "test.h" 80 81 #define INVAL_PID -1 82 #define INVAL_FLAG -1 83 84 char *TCID = "getpriority02"; 85 int TST_TOTAL = 4; 86 87 struct test_case_t { /* test case struct. to hold ref. test cond's */ 88 int pro_which; 89 uid_t pro_uid; 90 char *desc; 91 int exp_errno; 92 } Test_cases[] = { 93 { 94 INVAL_FLAG, 0, "Invalid 'which' value specified", EINVAL}, { 95 PRIO_PROCESS, INVAL_PID, "Invalid 'who' value specified", ESRCH}, { 96 PRIO_PGRP, INVAL_PID, "Invalid 'who' value specified", ESRCH}, { 97 PRIO_USER, INVAL_PID, "Invalid 'who' value specified", ESRCH}, { 98 0, 0, NULL, 0} 99 }; 100 101 void setup(); /* Main setup function of test */ 102 void cleanup(); /* cleanup function for the test */ 103 104 int main(int ac, char **av) 105 { 106 int lc; 107 int ind; /* counter variable for test case looping */ 108 char *test_desc; /* test specific error message */ 109 int which; /* process priority category */ 110 uid_t who; /* process uid of the test process */ 111 112 tst_parse_opts(ac, av, NULL, NULL); 113 114 setup(); 115 116 for (lc = 0; TEST_LOOPING(lc); lc++) { 117 118 tst_count = 0; 119 120 for (ind = 0; ind < TST_TOTAL; ind++) { 121 which = Test_cases[ind].pro_which; 122 who = Test_cases[ind].pro_uid; 123 test_desc = Test_cases[ind].desc; 124 125 if (who == 0) { 126 /* Get the actual uid of the process */ 127 who = getuid(); 128 } 129 130 /* 131 * Invoke getpriority with the specified 132 * 'which' and 'who' arguments and verify 133 * that it fails with expected errno. 134 */ 135 TEST(getpriority(which, who)); 136 137 /* check return code from getpriority(2) */ 138 if (TEST_RETURN < 0) { 139 if (TEST_ERRNO == Test_cases[ind].exp_errno) { 140 tst_resm(TPASS, "getpriority(2) fails, " 141 "%s, errno:%d", 142 test_desc, TEST_ERRNO); 143 } else { 144 tst_resm(TFAIL, "getpriority() fails, " 145 "%s, errno:%d, expected errno:" 146 "%d", test_desc, TEST_ERRNO, 147 Test_cases[ind].exp_errno); 148 } 149 } else { 150 tst_resm(TFAIL, "getpriority() returned %ld, " 151 "expected -1, errno:%d", TEST_RETURN, 152 Test_cases[ind].exp_errno); 153 } 154 } 155 156 } 157 158 cleanup(); 159 160 tst_exit(); 161 } 162 163 /* 164 * setup() - performs all ONE TIME setup for this test. 165 */ 166 void setup(void) 167 { 168 169 tst_sig(NOFORK, DEF_HANDLER, cleanup); 170 171 TEST_PAUSE; 172 } 173 174 /* 175 * cleanup() - performs all ONE TIME cleanup for this test at 176 * completion or premature exit. 177 */ 178 void cleanup(void) 179 { 180 181 } 182