syscalls/ioprio: Add test cases for I/O priority
PATCH v4 1/1 syscalls/ioprio: Add test cases for I/O priority
The ioprio_get/ioprio_set syscalls are used primarily by the userspace tool "ionice" to set priority of a process, user or process group toward the I/O (block layer) scheduler.
This adds a simple iprio_get test and two more verbose tests for ioprio_set.
---
ChangeLog v3->v4:
- Rename syscall wrappers ioprio_get() and ioprio_set() to sys_ioprio_get() and sys_ioprio_set() to match the glibc convention.
- Issue tst_brk(TBROK ... if we can't even get the inital priority in the first prio set test.
- Add a define for the number of priorities and use arithmetic MOD to wrap priorities around from what they are at test start. Also use this define in prio test loops.
- Also report failed priority level in IDLE scheduling class priority test.
- Use TPASS|TTERRNO to print successful failure with the right error numbers on negative tests.
- Use TINFO on prints that more serve as information than as result of any test.
ChangeLog v2->v3:
- Add testcases to runtest/syscalls
- Add an info blurb to each test file
- Move syscall wrappers into ioprio.h
- Add helper to check that class is in range and use that consistently in the test cases
- Check the new priorities for validity when we bump the prio +1 and -2.
- Factor prio/class check function into the header as well and use the same in both setting tests
- Don't get the current prio before looping over all 8 prios in ioprio_set02
- Break out the negative tests from ioprio_set02 to ioprio_set03
- Also check that the negative tests return EINVAL
- Diet down includes
- Use tst_syscall()
- Drop .min_kver since we use tst_syscall() to determine if the syscall is there
- Fixed relevant checkpatch warnings, left 80 col warnings as these are non-compulsory
ChangeLog v1->v2:
- Use the new test fixture "tst_test.h"
- Fix up legalese in the Makefile to a simple SPDX tag.
- Test from v2.6.13 when the syscall was introduced
--- runtest/syscalls | 5 + testcases/kernel/syscalls/ioprio/.gitignore | 4 + testcases/kernel/syscalls/ioprio/Makefile | 6 ++ testcases/kernel/syscalls/ioprio/ioprio.h | 94 +++++++++++++++++++ .../kernel/syscalls/ioprio/ioprio_get01.c | 47 ++++++++++ .../kernel/syscalls/ioprio/ioprio_set01.c | 63 +++++++++++++ .../kernel/syscalls/ioprio/ioprio_set02.c | 67 +++++++++++++ .../kernel/syscalls/ioprio/ioprio_set03.c | 57 +++++++++++ 8 files changed, 343 insertions(+) create mode 100644 testcases/kernel/syscalls/ioprio/.gitignore create mode 100644 testcases/kernel/syscalls/ioprio/Makefile create mode 100644 testcases/kernel/syscalls/ioprio/ioprio.h create mode 100644 testcases/kernel/syscalls/ioprio/ioprio_get01.c create mode 100644 testcases/kernel/syscalls/ioprio/ioprio_set01.c create mode 100644 testcases/kernel/syscalls/ioprio/ioprio_set02.c create mode 100644 testcases/kernel/syscalls/ioprio/ioprio_set03.c
runtest/syscalls +5 -0
@@ -542,6 +542,11 @@ ioperm02 ioperm02 iopl01 iopl01 iopl02 iopl02 +ioprio_get01 ioprio_get01 +ioprio_set01 ioprio_set01 +ioprio_set02 ioprio_set02 +ioprio_set03 ioprio_set03 + io_cancel01 io_cancel01 io_destroy01 io_destroy01 io_getevents01 io_getevents01
testcases/kernel/syscalls/ioprio/.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +ioprio_get01 +ioprio_set01 +ioprio_set02 +ioprio_set03
testcases/kernel/syscalls/ioprio/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/ioprio/ioprio.h new file +94 -0
94 lines not on this page · raw message
testcases/kernel/syscalls/ioprio/ioprio_get01.c new file +47 -0
47 lines not on this page · raw message
testcases/kernel/syscalls/ioprio/ioprio_set01.c new file +63 -0
63 lines not on this page · raw message
testcases/kernel/syscalls/ioprio/ioprio_set02.c new file +67 -0
67 lines not on this page · raw message
testcases/kernel/syscalls/ioprio/ioprio_set03.c new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.21.0
PATCH v4 1/1 syscalls/ioprio: Add test cases for I/O priority
Hi!
Quoted 34 lines
testcases/kernel/syscalls/ioprio/ioprio_set01.c new file +28
-0@@ -0,0 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 Linus Walleij <[email protected]> +* +* Description: +* Basic ioprio_set() test. Gets the current process I/O priority and +* bumps it up one notch, then down two notches and checks that the +* new priority is reported back correctly. +*/ +#include <sys/types.h> +#include <sys/syscall.h> + +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "ioprio.h" + +static void run (void ) +{ +int class, prio; + +/* Get the I/O priority for the current process */ +TEST (sys_ioprio_get (IOPRIO_WHO_PROCESS ,0 )); + +if (TST_RET ==-1 ) +tst_brk (TBROK |TTERRNO ,"ioprio_get failed" ); + + class =IOPRIO_PRIO_CLASS (TST_RET ); + prio =IOPRIO_PRIO_LEVEL (TST_RET );
testcases/kernel/syscalls/ioprio/ioprio_set01.c line 38
Quoted 10 lines
testcases/kernel/syscalls/ioprio/ioprio_set01.c new file +10
-0+tst_res (TINFO ,"ioprio_get returned class %s prio %d" , + to_class_str[class], prio); + +/* Bump prio to what it was + 1 */ + class =IOPRIO_CLASS_BE ; +if (!prio_in_range (prio +1 )) { +tst_res (TFAIL ,"ioprio increase out of range (%d)" , prio +1 ); +return ; + } + prio = (prio +1 ) %IOPRIO_PRIO_NUM ;
I guess that the % IOPRION_PRIO_NUM is not needed here since we already checked that the prio+1 is in range, or do I miss something?
testcases/kernel/syscalls/ioprio/ioprio_set01.c line 52
Quoted 13 lines
testcases/kernel/syscalls/ioprio/ioprio_set01.c new file +13
-0+TEST (sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class, prio))); +if (TST_RET ==-1 ) +tst_res (TFAIL |TTERRNO ,"ioprio_set failed" ); +else +ioprio_check_setting (class, prio,1 ); + +/* Bump prio down two notches */ +if (!prio_in_range (prio -2 )) { +tst_res (TFAIL ,"ioprio increase out of range (%d)" , prio -2 ); +return ; + } + prio = (prio -2 ) %IOPRIO_PRIO_NUM ;
Here as well.
Quoted 17 lines
testcases/kernel/syscalls/ioprio/ioprio_set01.c new file +11
-0+TEST (sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class, prio))); +if (TST_RET ==-1 ) +tst_res (TFAIL |TTERRNO ,"ioprio_set failed" ); +else +ioprio_check_setting (class, prio,1 ); +} + +static struct tst_test test = { + .test_all = run, +};testcases/kernel/syscalls/ioprio/ioprio_set02.c new file +0
-0
testcases/kernel/syscalls/ioprio/ioprio_set02.c line 6
Quoted 6 lines
testcases/kernel/syscalls/ioprio/ioprio_set02.c new file +6
-0@@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 Linus Walleij <[email protected]> +* +* Description: +* Extended ioprio_set() test. Gets the current process I/O priority and
^
We are not getting anything here.
Quoted 81 lines
testcases/kernel/syscalls/ioprio/ioprio_set02.c new file +61
-0+* tests to set all 8 priority levels for best effort prioritym then +* switches to test all 8 priority levels for idle priority. Also test +* some non-working priorities to make sure they don't work. +*/ +#include <sys/types.h> +#include <sys/syscall.h> + +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "ioprio.h" + +static void run (void ) +{ +int class, prio; +int fail_in_loop; + +/* Bump to best effort scheduling, all 8 priorities */ + class =IOPRIO_CLASS_BE ; + + fail_in_loop =0 ; +for (prio =0 ; prio <IOPRIO_PRIO_NUM ; prio++) { +TEST (sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class, prio))); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"ioprio_set IOPRIO_CLASS_BE prio %d failed" , prio); + fail_in_loop =1 ; + } + } +if (!fail_in_loop) +tst_res (TPASS ,"tested all prios in class %s" , + to_class_str[class]); + +/* Bump down to idle scheduling */ + class =IOPRIO_CLASS_IDLE ; + + fail_in_loop =0 ; +for (prio =0 ; prio <IOPRIO_PRIO_NUM ; prio++) { +TEST (sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class, prio))); +if (TST_RET ==-1 ) { +tst_res (TFAIL |TTERRNO ,"ioprio_set IOPRIO_CLASS_IDLE prio %d failed" , prio); + fail_in_loop =1 ; + } + } +if (!fail_in_loop) +tst_res (TPASS ,"tested all prios in class %s" , + to_class_str[class]); + +/* Test NONE scheduling */ + class =IOPRIO_CLASS_NONE ; +TEST (sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class,0 ))); +if (TST_RET ==-1 ) +tst_res (TFAIL |TTERRNO ,"ioprio_set IOPRIO_CLASS_NONE failed" ); +else +ioprio_check_setting (class,0 ,1 ); +} + +static struct tst_test test = { + .test_all = run, +};testcases/kernel/syscalls/ioprio/ioprio_set03.c new file +14
-0@@ -0,0 +1,57 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2019 Linus Walleij <[email protected]> +* +* Description: +* Negative ioprio_set() test. Test some non-working priorities to make +* sure they don't work. +*/ +#include <sys/types.h> +#include <sys/syscall.h> + +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "ioprio.h"
testcases/kernel/syscalls/ioprio/ioprio_set03.c line 24
Quoted 10 lines
testcases/kernel/syscalls/ioprio/ioprio_set03.c new file +10
-0+ +static void run (void ) +{ +int class; + + class =IOPRIO_CLASS_BE ; + +/* Test to fail with prio 8, first set prio 4 */ +sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class,4 ));
What do we need this for?
Quoted 18 lines
testcases/kernel/syscalls/ioprio/ioprio_set03.c new file +18
-0+TEST (sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class,8 ))); +if (TST_RET ==-1 ) { +ioprio_check_setting (class,4 ,1 ); +if (errno ==EINVAL ) +tst_res (TPASS |TTERRNO ,"returned correct error for wrong prio" ); +else +tst_res (TFAIL ,"ioprio_set returns wrong errno %d" , +TST_ERR ); + }else { +tst_res (TFAIL ,"ioprio_set IOPRIO_CLASS_BE prio 8 should not work" ); + } + +/* Any other prio than 0 should not work with NONE */ + class =IOPRIO_CLASS_NONE ; +TEST (sys_ioprio_set (IOPRIO_WHO_PROCESS ,0 , +IOPRIO_PRIO_VALUE (class,4 ))); +if (TST_RET ==-1 ) {
testcases/kernel/syscalls/ioprio/ioprio_set03.c line 52
Quoted 10 lines
testcases/kernel/syscalls/ioprio/ioprio_set03.c new file +10
-0+tst_res (TINFO ,"tested illegal priority with class %s" , + to_class_str[class]); +if (errno ==EINVAL ) +tst_res (TPASS |TTERRNO ,"returned correct error for wrong prio" ); +else +tst_res (TFAIL ,"ioprio_set returns wrong errno %d" , +TST_ERR ); + }else { +tst_res (TFAIL ,"ioprio_set IOPRIO_CLASS_NONE should fail" ); + }
This is almost copy&pasted I would consider putting it into a function...
testcases/kernel/syscalls/ioprio/ioprio_set03.c line 57
Quoted 5 lines
testcases/kernel/syscalls/ioprio/ioprio_set03.c new file +5
-0+} + +static struct tst_test test = { + .test_all = run, +};
Other than the minor issues this looks good.
Also I can fix these and apply the patch myself, no need to resend v5.
Signature · 2 lines
Cyril Hrubis [email protected]