• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines Corp., 2001
4  * Ported to LTP: Wayne Boyer
5  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
6  */
7 /*
8  *  Verify that any user can successfully increase the nice value of
9  *  the process by passing an increment value (< max. applicable limits) to
10  *  nice() system call.
11  */
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <errno.h>
15 #include <sys/resource.h>
16 #include "tst_test.h"
17 
18 #define	NICEINC	2
19 
nice_test(void)20 static void nice_test(void)
21 {
22 	int new_nice;
23 	int orig_nice;
24 
25 	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
26 
27 	TEST(nice(NICEINC));
28 
29 	if (TST_RET == -1) {
30 		tst_res(TFAIL | TTERRNO, "nice(%d) returned -1", NICEINC);
31 		return;
32 	}
33 
34 	if (TST_ERR) {
35 		tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC);
36 		return;
37 	}
38 
39 	new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
40 
41 	if (new_nice != (orig_nice + NICEINC)) {
42 		tst_res(TFAIL, "Process priority %i, expected %i",
43 		        new_nice, orig_nice + NICEINC);
44 		return;
45 	}
46 
47 	tst_res(TPASS, "nice(%d) passed", NICEINC);
48 
49 	exit(0);
50 }
51 
verify_nice(void)52 static void verify_nice(void)
53 {
54 	if (!SAFE_FORK())
55 		nice_test();
56 
57 	tst_reap_children();
58 }
59 
60 static struct tst_test test = {
61 	.forks_child = 1,
62 	.test_all = verify_nice,
63 };
64