1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2019 Linus Walleij <linus.walleij@linaro.org>
4 *
5 * Description:
6 * Extended ioprio_set() test.
7 * Tests to set all 8 priority levels for best effort priority, then
8 * switches to test all 8 priority levels for idle priority.
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
run(void)17 static void run(void)
18 {
19 int class, prio;
20 int fail_in_loop;
21
22 /* Bump to best effort scheduling, all 8 priorities */
23 class = IOPRIO_CLASS_BE;
24
25 fail_in_loop = 0;
26 for (prio = 0; prio < IOPRIO_PRIO_NUM; prio++) {
27 TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
28 IOPRIO_PRIO_VALUE(class, prio)));
29 if (TST_RET == -1) {
30 tst_res(TFAIL | TTERRNO, "ioprio_set IOPRIO_CLASS_BE prio %d failed", prio);
31 fail_in_loop = 1;
32 }
33 }
34 if (!fail_in_loop)
35 tst_res(TPASS, "tested all prios in class %s",
36 to_class_str[class]);
37
38 /* Bump down to idle scheduling */
39 class = IOPRIO_CLASS_IDLE;
40
41 fail_in_loop = 0;
42 for (prio = 0; prio < IOPRIO_PRIO_NUM; prio++) {
43 TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
44 IOPRIO_PRIO_VALUE(class, prio)));
45 if (TST_RET == -1) {
46 tst_res(TFAIL | TTERRNO, "ioprio_set IOPRIO_CLASS_IDLE prio %d failed", prio);
47 fail_in_loop = 1;
48 }
49 }
50 if (!fail_in_loop)
51 tst_res(TPASS, "tested all prios in class %s",
52 to_class_str[class]);
53
54 /* Test NONE scheduling */
55 class = IOPRIO_CLASS_NONE;
56 TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
57 IOPRIO_PRIO_VALUE(class, 0)));
58 if (TST_RET == -1)
59 tst_res(TFAIL | TTERRNO, "ioprio_set IOPRIO_CLASS_NONE failed");
60 else
61 ioprio_check_setting(class, 0, 1);
62 }
63
64 static struct tst_test test = {
65 .test_all = run,
66 };
67