• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: nice02
22  *
23  * Test Description:
24  *  Verify that any user can successfully increase the nice value of
25  *  the process by passing a higher increment value (> max. applicable limits)
26  *  to nice() system call.
27  *
28  * Expected Result:
29  *  nice() should return value 0 on success and root user should succeed to
30  *  increase the nice value of the 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  *  nice02 [-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  *  none
65  */
66 #include <unistd.h>
67 #include <errno.h>
68 #include <fcntl.h>
69 #include <sys/time.h>
70 #include <sys/resource.h>
71 
72 #include "test.h"
73 
74 char *TCID = "nice02";
75 int TST_TOTAL = 1;
76 
77 #define	NICEINC		50
78 
79 void setup();			/* Main setup function of test */
80 void cleanup();			/* cleanup function for the test */
81 
main(int ac,char ** av)82 int main(int ac, char **av)
83 {
84 	int lc;
85 	int New_nice;		/* priority of process after nice() */
86 	int max_val;		/* Maximum nice value per OS. */
87 
88 	tst_parse_opts(ac, av, NULL, NULL);
89 
90 	setup();
91 
92 	for (lc = 0; TEST_LOOPING(lc); lc++) {
93 
94 		tst_count = 0;
95 
96 		/*
97 		 * Call nice(2) with an 'incr' parameter set
98 		 * to a higher +ve value.
99 		 */
100 		TEST(nice(NICEINC));
101 
102 		/* check return code */
103 		if (TEST_RETURN == -1) {
104 			tst_resm(TFAIL, "nice(%d) Failed, errno=%d : %s",
105 				 NICEINC, TEST_ERRNO, strerror(TEST_ERRNO));
106 			continue;
107 		}
108 
109 		/*
110 		 * Get the current priority of the test process.
111 		 */
112 		errno = 0;
113 		New_nice = getpriority(PRIO_PROCESS, 0);
114 		if (New_nice == -1 && errno != 0) {
115 			tst_brkm(TFAIL, cleanup, "Fail to get priority "
116 				 "of process after nice()");
117 		}
118 
119 		/*
120 		 * Validate functionality of the nice().
121 		 *
122 		 * Default priority is 0, Max is 20.
123 		 */
124 		max_val = 20;
125 
126 		if (New_nice != (max_val - 1)) {
127 			tst_resm(TFAIL, "Priority of process : %d "
128 				 "doesn't match the expected:%d",
129 				 New_nice, (max_val - 1));
130 		} else {
131 			tst_resm(TPASS, "Functionality of nice(%d)"
132 				 " successful", NICEINC);
133 		}
134 	}
135 
136 	cleanup();
137 	tst_exit();
138 }
139 
140 /*
141  * setup() - performs all ONE TIME setup for this test.
142  */
setup(void)143 void setup(void)
144 {
145 
146 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
147 
148 	TEST_PAUSE;
149 }
150 
151 /*
152  * cleanup() - performs all ONE TIME cleanup for this test at
153  *             completion or premature exit.
154  *  Remove the test directory and testfile created in the setup.
155  */
cleanup(void)156 void cleanup(void)
157 {
158 
159 }
160