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