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