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