1 /*
2 * Copyright (c) International Business Machines Corp., 2001
3 * 07/2001 Ported by Wayne Boyer
4 * 11/2016 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
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 the
14 * 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, see <http://www.gnu.org/licenses/>.
18 */
19
20 /*
21 * Verify that,
22 * 1) getpriority(2) fails with -1 and sets errno to EINVAL if 'which'
23 * argument was not one of PRIO_PROCESS, PRIO_PGRP, or PRIO_USER.
24 * 2) getpriority(2) fails with -1 and sets errno to ESRCH if no
25 * process was located for 'which' and 'who' arguments.
26 */
27
28 #include <errno.h>
29 #include <sys/resource.h>
30 #include <sys/time.h>
31 #include "tst_test.h"
32
33 #define INVAL_FLAG -1
34 #define INVAL_ID -1
35
36 static struct tcase {
37 int which;
38 int who;
39 int exp_errno;
40 } tcases[] = {
41 /* test 1 */
42 {INVAL_FLAG, 0, EINVAL},
43
44 /* test 2 */
45 {PRIO_PROCESS, INVAL_ID, ESRCH},
46 {PRIO_PGRP, INVAL_ID, ESRCH},
47 {PRIO_USER, INVAL_ID, ESRCH}
48 };
49
verify_getpriority(unsigned int n)50 static void verify_getpriority(unsigned int n)
51 {
52 struct tcase *tc = &tcases[n];
53
54 TEST(getpriority(tc->which, tc->who));
55
56 if (TST_RET != -1) {
57 tst_res(TFAIL, "getpriority(%d, %d) succeeds unexpectedly, "
58 "returned %li", tc->which, tc->who, TST_RET);
59 return;
60 }
61
62 if (tc->exp_errno != TST_ERR) {
63 tst_res(TFAIL | TTERRNO,
64 "getpriority(%d, %d) should fail with %s",
65 tc->which, tc->who, tst_strerrno(tc->exp_errno));
66 return;
67 }
68
69 tst_res(TPASS | TTERRNO, "getpriority(%d, %d) fails as expected",
70 tc->which, tc->who);
71 }
72
73 static struct tst_test test = {
74 .tcnt = ARRAY_SIZE(tcases),
75 .test = verify_getpriority,
76 };
77