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 * Verify that any user can successfully increase the nice value of
22 * the process by passing a higher increment value (> max. applicable limits)
23 * to nice() system call.
24 */
25 #include <unistd.h>
26 #include <errno.h>
27 #include <sys/resource.h>
28
29 #include "tst_test.h"
30
31 #define NICEINC 50
32 #define MAX_PRIO 19
33 #define DEFAULT_PRIO 0
34
verify_nice(void)35 static void verify_nice(void)
36 {
37 int new_nice;
38
39 TEST(nice(NICEINC));
40
41 if (TEST_RETURN == -1) {
42 tst_res(TFAIL | TTERRNO, "nice(%d) returned -1", NICEINC);
43 return;
44 }
45
46 if (TEST_ERRNO) {
47 tst_res(TFAIL | TTERRNO, "nice(%d) failed", NICEINC);
48 return;
49 }
50
51 new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
52
53 if (new_nice != MAX_PRIO) {
54 tst_res(TFAIL, "Process priority %i, expected %i",
55 new_nice, MAX_PRIO);
56 return;
57 }
58
59 tst_res(TPASS, "nice(%d) passed", NICEINC);
60
61 TEST(nice(DEFAULT_PRIO));
62 if (TEST_ERRNO)
63 tst_brk(TBROK | TERRNO, "nice(-NICEINC) failed");
64 }
65
66 static struct tst_test test = {
67 .test_all = verify_nice,
68 };
69