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