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 * 11/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
6 */
7
8 /*
9 * Verify that getpriority(2) succeeds get the scheduling priority of
10 * the current process, process group or user, and the priority values
11 * are in the ranges of [0, 0], [0, 0] and [-20, 0] by default for the
12 * flags PRIO_PROCESS, PRIO_PGRP and PRIO_USER respectively.
13 */
14
15 #include <errno.h>
16 #include <sys/resource.h>
17 #include <sys/time.h>
18 #include "tst_test.h"
19
20 static struct tcase {
21 int which;
22 int min;
23 int max;
24 } tcases[] = {
25 {PRIO_PROCESS, 0, 0},
26 {PRIO_PGRP, 0, 0},
27 {PRIO_USER, -20, 0}
28 };
29
verify_getpriority(unsigned int n)30 static void verify_getpriority(unsigned int n)
31 {
32 struct tcase *tc = &tcases[n];
33
34 TEST(getpriority(tc->which, 0));
35
36 if (TST_ERR != 0) {
37 tst_res(TFAIL | TTERRNO, "getpriority(%d, 0) failed",
38 tc->which);
39 return;
40 }
41
42 if (TST_RET < tc->min || TST_RET > tc->max) {
43 tst_res(TFAIL, "getpriority(%d, 0) returned %ld, "
44 "expected in the range of [%d, %d]",
45 tc->which, TST_RET, tc->min, tc->max);
46 return;
47 }
48
49 tst_res(TPASS, "getpriority(%d, 0) returned %ld",
50 tc->which, TST_RET);
51 }
52
53 static struct tst_test test = {
54 .tcnt = ARRAY_SIZE(tcases),
55 .test = verify_getpriority,
56 };
57