1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2019 Linus Walleij <linus.walleij@linaro.org>
4 *
5 * Description:
6 * Basic ioprio_set() test. Gets the current process I/O priority and
7 * bumps it up one notch, then down two notches and checks that the
8 * new priority is reported back correctly.
9 */
10 #include <sys/types.h>
11 #include <sys/syscall.h>
12
13 #include "tst_test.h"
14 #include "lapi/syscalls.h"
15 #include "ioprio.h"
16
17 static int orig_class;
18 static int orig_prio;
19
run(void)20 static void run(void)
21 {
22 int class = orig_class, prio = orig_prio;
23
24 /* Bump prio to what it was + 1 */
25 class = IOPRIO_CLASS_BE;
26 prio = prio + 1;
27 if (!prio_in_range(prio)) {
28 tst_res(TCONF, "ioprio increase out of range (%d)", prio);
29 goto second;
30 }
31
32 TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
33 IOPRIO_PRIO_VALUE(class, prio)));
34 if (TST_RET == -1)
35 tst_res(TFAIL | TTERRNO, "ioprio_set failed");
36 else
37 ioprio_check_setting(class, prio, 1);
38
39 second:
40 /* Bump prio down two notches */
41 prio = prio - 2;
42 if (!prio_in_range(prio)) {
43 tst_res(TCONF, "ioprio decrease out of range (%d)", prio);
44 return;
45 }
46
47 TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
48 IOPRIO_PRIO_VALUE(class, prio)));
49 if (TST_RET == -1)
50 tst_res(TFAIL | TTERRNO, "ioprio_set failed");
51 else
52 ioprio_check_setting(class, prio, 1);
53 }
54
setup(void)55 static void setup(void)
56 {
57 /* Get the I/O priority for the current process */
58 TEST(sys_ioprio_get(IOPRIO_WHO_PROCESS, 0));
59 if (TST_RET == -1)
60 tst_brk(TBROK | TTERRNO, "ioprio_get failed");
61
62 orig_class = IOPRIO_PRIO_CLASS(TST_RET);
63 orig_prio = IOPRIO_PRIO_LEVEL(TST_RET);
64
65 tst_res(TINFO, "ioprio_get returned class %s prio %d",
66 to_class_str[orig_class], orig_prio);
67 }
68
69 static struct tst_test test = {
70 .setup = setup,
71 .test_all = run,
72 };
73