• 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) 2023 Linux Test Project
5  */
6 
7 /*\
8  * [Description]
9  *
10  * Negative ioprio_set() test. Test some non-working priorities to make
11  * sure they don't work.
12  */
13 
14 #include "tst_test.h"
15 #include "ioprio.h"
16 
run(void)17 static void run(void)
18 {
19 	int class;
20 
21 	class = IOPRIO_CLASS_BE;
22 
23 	/*
24 	 * Test to fail with prio 8, first set prio 4 so we know what it
25 	 * should still be after failure, i.e. we check that the priority
26 	 * didn't change as a side effect of setting an invalid priority.
27 	 */
28 	sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
29 		       IOPRIO_PRIO_VALUE(class, 4));
30 	TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
31 			    IOPRIO_PRIO_VALUE(class, IOPRIO_PRIO_NUM)));
32 	if (TST_RET == -1) {
33 		ioprio_check_setting(class, 4, 1);
34 		if (errno == EINVAL)
35 			tst_res(TPASS | TTERRNO, "returned correct error for wrong prio");
36 		else
37 			tst_res(TFAIL, "ioprio_set returns wrong errno %d",
38 				TST_ERR);
39 	} else {
40 		tst_res(TFAIL, "ioprio_set IOPRIO_CLASS_BE prio 8 should not work");
41 	}
42 
43 	/* Any other prio than 0 should not work with NONE */
44 	class = IOPRIO_CLASS_NONE;
45 	TEST(sys_ioprio_set(IOPRIO_WHO_PROCESS, 0,
46 			    IOPRIO_PRIO_VALUE(class, 4)));
47 	if (TST_RET == -1) {
48 		tst_res(TINFO, "tested illegal priority with class %s",
49 			to_class_str[class]);
50 		if (errno == EINVAL)
51 			tst_res(TPASS | TTERRNO, "returned correct error for wrong prio");
52 		else
53 			tst_res(TFAIL, "ioprio_set returns wrong errno %d",
54 				TST_ERR);
55 	} else {
56 		tst_res(TFAIL, "ioprio_set IOPRIO_CLASS_NONE should fail");
57 	}
58 }
59 
60 static struct tst_test test = {
61 	.test_all = run,
62 };
63