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