• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) International Business Machines  Corp., 2001
3  *  07/2001 Ported by Wayne Boyer
4  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
5  *
6  * This program is free software;  you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
14  * the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program;  if not, write to the Free Software Foundation,
18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /*
22  *  Verify that root can provide a negative value to nice()
23  *  and hence root can decrease the nice value of the process
24  *  using nice() system call
25  */
26 #include <unistd.h>
27 #include <errno.h>
28 #include <sys/resource.h>
29 #include "tst_test.h"
30 
31 #define	NICEINC		-12
32 
verify_nice(void)33 static void verify_nice(void)
34 {
35 	int new_nice;
36 	int orig_nice;
37 
38 	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
39 
40 	TEST(nice(NICEINC));
41 
42 	if (TST_RET != (orig_nice + NICEINC)) {
43 		tst_res(TFAIL | TTERRNO, "nice(%d) returned %li, expected %i",
44 			NICEINC, TST_RET, orig_nice + NICEINC);
45 		return;
46 	}
47 
48 	if (TST_ERR) {
49 		tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC);
50 		return;
51 	}
52 
53 	new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
54 
55 	if (new_nice != (orig_nice + NICEINC)) {
56 		tst_res(TFAIL, "Process priority %i, expected %i",
57 		        new_nice, orig_nice + NICEINC);
58 		return;
59 	}
60 
61 	tst_res(TPASS, "nice(%d) passed", NICEINC);
62 
63 	TEST(nice(-NICEINC));
64 	if (TST_ERR)
65 		tst_brk(TBROK | TERRNO, "nice(-NICEINC) failed");
66 }
67 
68 static struct tst_test test = {
69 	.test_all = verify_nice,
70 	.needs_root = 1,
71 };
72