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: nice01 22 * 23 * Test Description: 24 * Verify that root can provide a negative value to nice() 25 * and hence root can decrease the nice value of the process 26 * using nice() system call 27 * 28 * Expected Result: 29 * nice() should return value 0 on success and root user should succeed 30 * to decrease the nice value of test process. 31 * 32 * Algorithm: 33 * Setup: 34 * Setup signal handling. 35 * Pause for SIGUSR1 if option specified. 36 * 37 * Test: 38 * Loop if the proper options are given. 39 * Execute system call 40 * Check return code, if system call failed (return=-1) 41 * Log the errno and Issue a FAIL message. 42 * Otherwise, 43 * Verify the Functionality of system call 44 * if successful, 45 * Issue Functionality-Pass message. 46 * Otherwise, 47 * Issue Functionality-Fail message. 48 * Cleanup: 49 * Print errno log and/or timing stats if options given 50 * 51 * Usage: <for command-line> 52 * nice01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] 53 * where, -c n : Run n copies concurrently. 54 * -f : Turn off functionality Testing. 55 * -i n : Execute test n times. 56 * -I x : Execute test for x seconds. 57 * -P x : Pause for x seconds between iterations. 58 * -t : Turn on syscall timing. 59 * 60 * HISTORY 61 * 07/2001 Ported by Wayne Boyer 62 * 63 * RESTRICTIONS: 64 * This test should be run by 'super-user' (root) only. 65 * 66 */ 67 #include <unistd.h> 68 #include <sys/types.h> 69 #include <errno.h> 70 #include <fcntl.h> 71 #include <sys/time.h> 72 #include <sys/resource.h> 73 74 #include "test.h" 75 76 #define NICEINC -12 77 #define TEMPFILE "temp_file" 78 79 char *TCID = "nice01"; 80 int TST_TOTAL = 1; 81 82 int Org_nice; /* original priority of the test process */ 83 FILE *fp; 84 85 void setup(); /* Main setup function of test */ 86 void cleanup(); /* cleanup function for the test */ 87 88 int main(int ac, char **av) 89 { 90 int lc; 91 int New_nice; /* priority of process after nice() */ 92 int rval; 93 94 tst_parse_opts(ac, av, NULL, NULL); 95 96 setup(); 97 98 for (lc = 0; TEST_LOOPING(lc); lc++) { 99 100 tst_count = 0; 101 102 /* 103 * Call nice(2) with an 'incr' parameter set 104 * to a negative value. 105 */ 106 TEST(nice(NICEINC)); 107 108 /* check return code */ 109 if (TEST_RETURN == -1) { 110 tst_resm(TFAIL, "nice(%d) Failed, errno=%d : %s", 111 NICEINC, TEST_ERRNO, strerror(TEST_ERRNO)); 112 continue; 113 } 114 115 New_nice = getpriority(PRIO_PROCESS, 0); 116 117 /* Validate functionality of the nice() */ 118 if (New_nice != (Org_nice + NICEINC)) { 119 tst_resm(TFAIL, "nice() fails to modify the " 120 "priority of process"); 121 } else { 122 tst_resm(TPASS, "Functionality of nice(%d) " 123 "successful", NICEINC); 124 } 125 126 /* return the process to the original priority */ 127 rval = nice(-NICEINC); 128 129 } 130 131 cleanup(); 132 tst_exit(); 133 } 134 135 /* 136 * setup() - performs all ONE TIME setup for this test. 137 * Make sure the test process uid is super user. 138 * Get the current priority value. 139 */ 140 void setup(void) 141 { 142 143 tst_require_root(); 144 145 tst_sig(NOFORK, DEF_HANDLER, cleanup); 146 147 TEST_PAUSE; 148 149 Org_nice = getpriority(PRIO_PROCESS, 0); 150 } 151 152 /* 153 * cleanup() - performs all ONE TIME cleanup for this test at 154 * completion or premature exit. 155 * Remove the test directory and testfile created in the setup. 156 */ 157 void cleanup(void) 158 { 159 160 } 161