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 a higher increment value (> max. applicable limits)
10 * to nice() system call.
11 */
12 #include <unistd.h>
13 #include <errno.h>
14 #include <sys/resource.h>
15
16 #include "tst_test.h"
17
18 #define NICEINC 50
19 #define MAX_PRIO 19
20 #define DEFAULT_PRIO 0
21
verify_nice(void)22 static void verify_nice(void)
23 {
24 int new_nice;
25
26 TEST(nice(NICEINC));
27
28 if (TST_RET == -1) {
29 tst_res(TFAIL | TTERRNO, "nice(%d) returned -1", NICEINC);
30 return;
31 }
32
33 if (TST_ERR) {
34 tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC);
35 return;
36 }
37
38 new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
39
40 if (new_nice != MAX_PRIO) {
41 tst_res(TFAIL, "Process priority %i, expected %i",
42 new_nice, MAX_PRIO);
43 return;
44 }
45
46 tst_res(TPASS, "nice(%d) passed", NICEINC);
47
48 TEST(nice(DEFAULT_PRIO));
49 if (TST_ERR)
50 tst_brk(TBROK | TERRNO, "nice(-NICEINC) failed");
51 }
52
53 static struct tst_test test = {
54 .test_all = verify_nice,
55 };
56