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