plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* |
| 21 | * Test Name: nice03 |
| 22 | * |
| 23 | * Test Description: |
| 24 | * Verify that any user can successfully increase the nice value of |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 25 | * the process by passing an increment value (< max. applicable limits) to |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 26 | * nice() system call. |
| 27 | * |
| 28 | * Expected Result: |
| 29 | * nice() should return value 0 on success and the user should succeed |
| 30 | * to increase 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, |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 43 | * Verify the Functionality of system call |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 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 | * nice03 [-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 | * The maximum iterations with the -i option is 9 |
| 65 | * |
| 66 | */ |
| 67 | |
| 68 | #include <stdio.h> |
| 69 | #include <unistd.h> |
| 70 | #include <errno.h> |
| 71 | #include <fcntl.h> |
| 72 | #include <sys/time.h> |
| 73 | #include <sys/resource.h> |
| 74 | |
| 75 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 77 | char *TCID = "nice03"; |
| 78 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | |
| 80 | #define NICEINC 2 |
| 81 | int Org_nice; /* original priority of the test process */ |
| 82 | |
| 83 | void setup(); /* Main setup function of test */ |
| 84 | void cleanup(); /* cleanup function for the test */ |
| 85 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 86 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 88 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 89 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | int New_nice; /* priority of process after nice() */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 91 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 92 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 93 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 94 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 95 | setup(); |
| 96 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 98 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 99 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 100 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 101 | /* |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 102 | * Call nice(2) with an 'incr' parameter set |
| 103 | * to a +ve value < max. applicable limit. |
| 104 | * (Linux - 20) |
| 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 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 115 | New_nice = getpriority(PRIO_PROCESS, 0); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 117 | /* Validate functionality of the nice() */ |
| 118 | if (New_nice != (Org_nice + NICEINC)) { |
| 119 | tst_resm(TFAIL, "nice() failed to modify the " |
| 120 | "priority of process"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 121 | } else { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 122 | tst_resm(TPASS, "Functionality of nice(%d) is " |
| 123 | "correct", NICEINC); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | } |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 125 | Org_nice = New_nice; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 126 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 127 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 128 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 129 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 130 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | |
| 132 | /* |
| 133 | * void |
| 134 | * setup() - performs all ONE TIME setup for this test. |
| 135 | * Create a temporary directory and change directory to it. |
| 136 | * Get the process id of test process. |
| 137 | * Get the current nice value of test process and save it in a file. |
| 138 | * Read the nice value from file into a variable. |
| 139 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 140 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 141 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 142 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 144 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 145 | TEST_PAUSE; |
| 146 | |
| 147 | Org_nice = getpriority(PRIO_PROCESS, 0); |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * void |
| 152 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 153 | * completion or premature exit. |
| 154 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 155 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 156 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 157 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 158 | } |