lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd
PATCH v2 1/4 lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd
The drivers are checked with modprobe. If modprobe is not available on the system, the checks are silently skipped.
---
v2: * moved tst_check_driver() from tst_test.h to tst_kernel.h
* added the new option description to the doc and comment to tst_kernel.h
* iterating over the driver list moved out from tst_check_drivers(), the function renamed accordingly.
doc/test-writing-guidelines.txt | 10 ++++++++++ include/tst_kernel.h | 8 ++++++++ include/tst_test.h | 3 +++ lib/tst_kernel.c | 9 +++++++++ lib/tst_test.c | 9 +++++++++ testcases/lib/.gitignore | 1 + testcases/lib/Makefile | 2 +- testcases/lib/tst_check_drivers.c | 24 ++++++++++++++++++++++++ 8 files changed, 65 insertions(+), 1 deletions(-) create mode 100644 testcases/lib/tst_check_drivers.c
doc/test-writing-guidelines.txt +10 -0
@@ -1449,6 +1449,16 @@ https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html CRC32c checksum generation is supported by LTP. In order to use it, the test should include "tst_checksum.h" header, then can call tst_crc32c(). +2.2.26 Checking kernel for the driver support +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +Someties test needs certain drivers to be available in the kernel and must +end with TCONF if any are missing. For this task there is the '.needs_drivers' +option which accepts NULL-terminated array of the drivers names. + +Since it relies on modprobe command, the check will be skipped if the command +itself is not available on the system. + 2.3 Writing a testcase in shell ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/tst_kernel.h +8 -0
@@ -23,4 +23,12 @@*/ int tst_kernel_bits (void ); +/** +* Checks support for the kernel driver. +* +* @param name The name of the driver. +* @return Returns 0 if the kernel has the driver or modprobe is missing. +*/ +int tst_check_driver (const char *name); +#endif /* TST_KERNEL_H__ */
include/tst_test.h +3 -0
@@ -170,6 +170,9 @@ struct tst_test {/* NULL terminated array of resource file names */ const char *const *resource_files; + +/* NULL terminated array of needed kernel drivers */ +const char *const *needs_drivers; };/*
lib/tst_kernel.c +9 -0
@@ -45,3 +45,12 @@ int tst_kernel_bits(void)return kernel_bits; } + +int tst_check_driver (const char *name) +{ +const char *const argv[] = {"modprobe" , name,NULL }; +int res =tst_run_cmd_ (NULL , argv,"/dev/null" ,"/dev/null" ,1 ); + +/* 255 - it looks like modprobe not available */ +return (res ==255 ) ?0 : res; +}
lib/tst_test.c +9 -0
@@ -767,6 +767,15 @@ static void do_setup(int argc, char *argv[])if (tst_test->min_kver)check_kver (); +if (tst_test->needs_drivers) { +const char *name; +int i; + +for (i =0 ; (name = tst_test->needs_drivers[i]); ++i) +if (tst_check_driver (name)) +tst_brk (TCONF ,"%s driver not available" , name); + } +if (tst_test->format_device) tst_test->needs_device =1 ;
testcases/lib/.gitignore +1 -0
@@ -1,5 +1,6 @@ /tst_sleep /tst_random +/tst_check_drivers /tst_checkpoint /tst_rod /tst_kvcmp
testcases/lib/Makefile +1 -1
@@ -28,6 +28,6 @@ INSTALL_TARGETS := *.sh MAKE_TARGETS := tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\ tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\ - tst_getconf tst_supported_fs + tst_getconf tst_supported_fs tst_check_drivers include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/lib/tst_check_drivers.c new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved. */ + +#include <stdio.h> +#include "tst_kernel.h" + +int main (int argc,const char *argv[]) +{ +const char *name; +int i; + +if (argc <2 ) { +fprintf (stderr,"Please provide kernel driver list\n" ); +return 1 ; + } + +for (i =1 ; (name = argv[i]); ++i) +if (tst_check_driver (name)) { +fprintf (stderr,"%s" , name); +return 1 ; + } + +return 0 ; +}
Signature · 1 line
1.7.1
PATCH v2 2/4 lib/tst_test.sh: add TST_NEEDS_DRIVERS parameter
The drivers are checked with 'tst_check_drivers' command.
---
v2: add a check for empty TST_NEEDS_DRIVERS
doc/test-writing-guidelines.txt | 1 + testcases/lib/tst_test.sh | 12 ++++++++++++ 2 files changed, 13 insertions(+), 0 deletions(-)
doc/test-writing-guidelines.txt +1 -0
@@ -1653,6 +1653,7 @@ simply by setting right '$TST_NEEDS_FOO'. | 'TST_NEEDS_CMDS' | String with command names that has to be present for the test (see below). | 'TST_NEEDS_MODULE' | Test module name needed for the test (see below). +| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test. |============================================================================= Checking for presence of commands
testcases/lib/tst_test.sh +12 -0
@@ -285,6 +285,16 @@ tst_check_cmds() return 0 } +tst_test_drivers() +{ + [ $# -eq 0 ] && return 0 + + local drv="$(tst_check_drivers $@ 2>&1)" + + [ -n "$drv" ] && tst_brk TCONF "$drv driver not available" + return 0 +} + tst_is_int() { [ "$1" -eq "$1" ] 2>/dev/null
@@ -332,6 +342,7 @@ tst_run() OPTS|USAGE|PARSE_ARGS|POS_ARGS);; NEEDS_ROOT|NEEDS_TMPDIR|NEEDS_DEVICE|DEVICE);; NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);; + NEEDS_DRIVERS);; IPV6|IPVER|TEST_DATA|TEST_DATA_IFS);; RETRY_FUNC|RETRY_FN_EXP_BACKOFF);; *) tst_res TWARN "Reserved variable TST_$_tst_i used!";;
@@ -369,6 +380,7 @@ tst_run() fi tst_test_cmds $TST_NEEDS_CMDS + tst_test_drivers $TST_NEEDS_DRIVERS if [ -n "$TST_MIN_KVER" ]; then tst_kvcmp -lt "$TST_MIN_KVER" && \
Signature · 1 line
1.7.1
PATCH v2 2/4 lib/tst_test.sh: add TST_NEEDS_DRIVERS parameter
Hi Alexey,
Quoted 3 lines
The drivers are checked with '
tst_check_drivers' command.Signed-off-by Alexey Kodanev <[email protected]>
Thanks for the docs.
Kind regards,
Petr
PATCH v2 2/4 lib/tst_test.sh: add TST_NEEDS_DRIVERS parameter
In reply to Alexey KodanevHi!
testcases/lib/tst_test.sh tst_check_cmds() · line 292
Quoted 5 lines
testcases/lib/tst_test.sh +5
-0+tst_test_drivers() +{ + [ $# -eq 0 ] && return 0 + + local drv="$(tst_check_drivers $@ 2>&1)"
Wouldn't it be easier to just redirect the stderr into /dev/null here and check the $? instead of [ -n "$drv" ] ?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 2/4 lib/tst_test.sh: add TST_NEEDS_DRIVERS parameter
Quoted 10 lines · Cyril Hrubis
Hi!
testcases/lib/tst_test.sh tst_check_cmds() · line 292
Quoted 5 lines
testcases/lib/tst_test.sh +5
-0+tst_test_drivers() +{ + [ $# -eq 0 ] && return 0 + + local drv="$(tst_check_drivers $@ 2>&1)"Wouldn't it be easier to just redirect the stderr into
/dev/nullhere and check the $? instead of [ -n "$drv" ] ?
It's better to print the error message if any, including the driver name that is missing. And checking $? should work here too, will change that.
PATCH v2 3/4 lib/tst_test.sh: add TST_RTNL_CHK() helper function
In reply to Alexey KodanevIt should parse iproute commands output and exit the test with TCONF if there are certain messages returned from iproute/RTNETLINK.
---
v2: no changes
testcases/lib/tst_test.sh | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-)
testcases/lib/tst_test.sh +16 -0
@@ -202,6 +202,22 @@ TST_RETRY_FUNC() return $2 } +TST_RTNL_CHK() +{ + local msg1="RTNETLINK answers: Function not implemented" + local msg2="RTNETLINK answers: Operation not supported" + local output="$($@ 2>&1 || echo 'LTP_ERR')" + local msg + + echo "$output" | grep -q "LTP_ERR" || return 0 + + for msg in "$msg1" "$msg2"; do + echo "$output" | grep -q "$msg" && tst_brk TCONF "'$@': $msg" + done + + tst_brk TBROK "$@ failed: $output" +} + tst_umount() { local device="$1"
Signature · 1 line
1.7.1
PATCH v2 3/4 lib/tst_test.sh: add TST_RTNL_CHK() helper function
Hi Alexey,
Quoted 6 lines
It should parse iproute commands output and exit the test with TCONF if there are certain messages returned from iproute/RTNETLINK.
Signed-off-by Alexey Kodanev <[email protected]>---
v2: no changes
Merged your patch to have it for the release.
Thanks a lot!
Kind regards,
Petr
PATCH v2 4/4 network/ipsec: replace ipsec_try() with TST_RTNL_CHK()
In reply to Alexey Kodanev---
v2: fixed missing ip before TST_RTNL_CHK
testcases/network/stress/ipsec/ipsec_lib.sh | 21 +++------------------ 1 files changed, 3 insertions(+), 18 deletions(-)
testcases/network/stress/ipsec/ipsec_lib.sh +3 -18
@@ -157,21 +157,6 @@ ipsec_set_algoline() esac } -ipsec_try() -{ - local output="$($@ 2>&1 || echo 'TERR')" - - if echo "$output" | grep -q "TERR"; then - echo "$output" | grep -q \ - 'RTNETLINK answers: Function not implemented' && \ - tst_brk TCONF "'$@': not implemented" - echo "$output" | grep -q \ - 'RTNETLINK answers: Operation not supported' && \ - tst_brk TCONF "'$@': not supported (maybe missing 'ip${TST_IPV6}_vti' kernel module)" - tst_brk TBROK "$@ failed: $output" - fi -} - # tst_ipsec target src_addr dst_addr: config ipsec # # target: target of the configuration host ( lhost / rhost )
@@ -195,7 +180,7 @@ tst_ipsec() if [ $target = lhost ]; then local spi_1="0x$SPI" local spi_2="0x$(( $SPI + 1 ))" - ipsec_try ip xfrm state add src $src dst $dst spi $spi_1 \ + TST_RTNL_CHK ip xfrm state add src $src dst $dst spi $spi_1 \ $p $ALG mode $mode sel src $src dst $dst ROD ip xfrm state add src $dst dst $src spi $spi_2 \ $p $ALG mode $mode sel src $dst dst $src
@@ -257,12 +242,12 @@ tst_ipsec_vti() cleanup_vti=$vti if [ $target = lhost ]; then - ipsec_try ip li add $vti $type local $src remote $dst $key $d + TST_RTNL_CHK ip li add $vti $type local $src remote $dst $key $d ROD ip li set $vti up local spi_1="spi 0x$SPI" local spi_2="spi 0x$(( $SPI + 1 ))" - ipsec_try $ipx st add $o_dir $p $spi_1 $ALG $m + TST_RTNL_CHK $ipx st add $o_dir $p $spi_1 $ALG $m ROD $ipx st add $i_dir $p $spi_2 $ALG $m ROD $ipx po add dir out tmpl $o_dir $p $m $mrk ROD $ipx po add dir in tmpl $i_dir $p $m $mrk
Signature · 1 line
1.7.1
PATCH v2 4/4 network/ipsec: replace ipsec_try() with TST_RTNL_CHK()
Quoted 1 line
Signed-off-by Alexey Kodanev <[email protected]>
Quoted 2 lines
---
v2: fixed missing ip beforeTST_RTNL_CHK
I was just going to report it :-).
Kind regards,
Petr
PATCH v2 4/4 network/ipsec: replace ipsec_try() with TST_RTNL_CHK()
In reply to Alexey KodanevHi Alexey,
Quoted 3 lines
Signed-off-by Alexey Kodanev <[email protected]>---
v2: fixed missing ip beforeTST_RTNL_CHK
Merged your patch to have it for the release.
Thanks a lot!
NOTE: I'm going to leave the 1st and 2nd patch, as there is currently no test using it. I guess we'd like to use it in tst_net.sh for netns.
Kind regards,
Petr
PATCH v2 1/4 lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd
In reply to Alexey KodanevHi Alexey,
Quoted 4 lines
The drivers are checked with modprobe. If modprobe is not available on the system, the checks are silently skipped.
Signed-off-by Alexey Kodanev <[email protected]>
Quoted 5 lines
---
v2: * movedtst_check_driver()fromtst_test.htotst_kernel.h
* added the new option description to the doc and comment totst_kernel.h
* iterating over the driver list moved out fromtst_check_drivers(), the function renamed accordingly.
...
Quoted 4 lines
+2.2.26 Checking kernel for the driver support +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ Someties test needs certain drivers to be available in the kernel and must
Typo Sometimes
Quoted 8 lines
doc/test-writing-guidelines.txt +6
-0+end with TCONF if any are missing. For this task there is the '.needs_drivers' +option which accepts NULL-terminated array of the drivers names. + +Since it relies on modprobe command, the check will be skipped if the command +itself is not available on the system. +++ b/testcases/lib/tst_check_drivers.c
...
testcases/lib/tst_check_drivers.c line 24
Quoted 13 lines
testcases/lib/tst_check_drivers.c new file +13
-0+if (argc <2 ) { +fprintf (stderr,"Please provide kernel driver list\n" ); +return 1 ; + } + +for (i =1 ; (name = argv[i]); ++i) +if (tst_check_driver (name)) { +fprintf (stderr,"%s" , name); +return 1 ; + } + +return 0 ; +}
It'd be handy to be able to load module with parameters. E.g.:
tcrypt sec=1 mode=200
We have 2 options: to name strig by spaces to b:
./tst_check_drivers "tcrypt sec=1 mode=200" other_module
Or handle in tst_check_drivers.c just one module and call it several times.
None of them is elegant.
Otherwise LGTM.
Kind regards,
Petr
PATCH v2 1/4 lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd
Quoted 8 lines · Petr Vorel
Hi Alexey,
Quoted 4 lines
The drivers are checked with modprobe. If modprobe is not available on the system, the checks are silently skipped.
Signed-off-by Alexey Kodanev <[email protected]>Reviewed-by Petr Vorel <[email protected]>
Hi Petr,
Quoted 22 lines
Quoted 5 lines
---
v2: * movedtst_check_driver()fromtst_test.htotst_kernel.h
* added the new option description to the doc and comment totst_kernel.h
* iterating over the driver list moved out fromtst_check_drivers(), the function renamed accordingly....
Quoted 4 lines
+2.2.26 Checking kernel for the driver support +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+ Someties test needs certain drivers to be available in the kernel and mustTypo Sometimes
Quoted 8 lines
doc/test-writing-guidelines.txt +6
-0+end with TCONF if any are missing. For this task there is the '.needs_drivers' +option which accepts NULL-terminated array of the drivers names. + +Since it relies on modprobe command, the check will be skipped if the command +itself is not available on the system. +++ b/testcases/lib/tst_check_drivers.c...
Quoted 16 lines
testcases/lib/tst_check_drivers.c line 24
Quoted 13 lines
testcases/lib/tst_check_drivers.c new file +13
-0+if (argc <2 ) { +fprintf (stderr,"Please provide kernel driver list\n" ); +return 1 ; + } + +for (i =1 ; (name = argv[i]); ++i) +if (tst_check_driver (name)) { +fprintf (stderr,"%s" , name); +return 1 ; + } + +return 0 ; +}It'd be handy to be able to load module with parameters. E.g.:
tcrypt sec=1 mode=200
Do you want to start tcrypt module in the test setup? It's probably better to add the -n/--dry-run option, so at first we verify that the kernel actually has it, then either end with TCONF or continue. That's the purpose of the 'needs_drivers'.
Moreover, if the failure occurs during the loading instead, the test must return TBROK, not TCONF, right?
Quoted 4 lines
We have 2 options: to name strig by spaces to b:
./tst_check_drivers "tcrypt sec=1 mode=200"other_moduleOr handle in
tst_check_drivers.cjust one module and call it several times.
like modprobe?
Quoted 9 lines
None of them is elegant.
Otherwise LGTM.
Kind regards,
Petr
PATCH v2 1/4 lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd
In reply to Alexey KodanevHi Alexey,
Quoted 10 lines
The drivers are checked with modprobe. If modprobe is not available on the system, the checks are silently skipped.
Signed-off-by Alexey Kodanev <[email protected]>---
v2: * movedtst_check_driver()fromtst_test.htotst_kernel.h
* added the new option description to the doc and comment totst_kernel.h
* iterating over the driver list moved out fromtst_check_drivers(), the function renamed accordingly.
Quoted 10 lines
doc/test-writing-guidelines.txt | 10 ++++++++++ include/tst_kernel.h | 8 ++++++++ include/tst_test.h | 3 +++ lib/tst_kernel.c | 9 +++++++++ lib/tst_test.c | 9 +++++++++ testcases/lib/.gitignore | 1 + testcases/lib/Makefile | 2 +- testcases/lib/tst_check_drivers.c | 24 ++++++++++++++++++++++++ 8 files changed, 65 insertions(+), 1 deletions(-) create mode 100644 testcases/lib/tst_check_drivers.c
I'd like this whole patchset being merged before git freeze. Do you plan it?
Kind regards,
Petr
PATCH v2 1/4 lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd
In reply to Alexey KodanevHi!
doc/test-writing-guidelines.txt https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html · line 1457
Quoted 6 lines
+2.2.26 Checking kernel for the driver support
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^doc/test-writing-guidelines.txt +4
-0+ +Someties test needs certain drivers to be available in the kernel and must +end with TCONF if any are missing. For this task there is the '.needs_drivers' +option which accepts NULL-terminated array of the drivers names.
Maybe we should explicitly say here that this works for both drivers that are compiled-in and modules, since otherwise this may confuse the users, especially since we talk about modprobe in the next paragraph.
I would write something as:
"Some tests may need specific kernel drivers, either compiled in, or loaded as a module. If .need_drivers points to a NULL-terminated array of kernel module names these are all checked and the test exits with TCONF on first missing driver."
Quoted 114 lines
doc/test-writing-guidelines.txt +3
-0+Since it relies on modprobe command, the check will be skipped if the command +itself is not available on the system. + 2.3 Writing a testcase in shell ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~include/tst_kernel.h +8
-0@@ -23,4 +23,12 @@*/ int tst_kernel_bits (void ); +/** +* Checks support for the kernel driver. +* +* @param name The name of the driver. +* @return Returns 0 if the kernel has the driver or modprobe is missing. +*/ +int tst_check_driver (const char *name); +#endif /* TST_KERNEL_H__ */ include/tst_test.h +3
-0@@ -170,6 +170,9 @@ struct tst_test {/* NULL terminated array of resource file names */ const char *const *resource_files; + +/* NULL terminated array of needed kernel drivers */ +const char *const *needs_drivers; };/* lib/tst_kernel.c +9
-0@@ -45,3 +45,12 @@ int tst_kernel_bits(void)return kernel_bits; } + +int tst_check_driver (const char *name) +{ +const char *const argv[] = {"modprobe" , name,NULL }; +int res =tst_run_cmd_ (NULL , argv,"/dev/null" ,"/dev/null" ,1 ); + +/* 255 - it looks like modprobe not available */ +return (res ==255 ) ?0 : res; +}lib/tst_test.c +9
-0@@ -767,6 +767,15 @@ static void do_setup(int argc, char *argv[])if (tst_test->min_kver)check_kver (); +if (tst_test->needs_drivers) { +const char *name; +int i; + +for (i =0 ; (name = tst_test->needs_drivers[i]); ++i) +if (tst_check_driver (name)) +tst_brk (TCONF ,"%s driver not available" , name); + } +if (tst_test->format_device) tst_test->needs_device =1 ;testcases/lib/.gitignore +1
-0@@ -1,5 +1,6 @@ /tst_sleep /tst_random +/tst_check_drivers /tst_checkpoint /tst_rod /tst_kvcmptestcases/lib/Makefile +1
-1@@ -28,6 +28,6 @@ INSTALL_TARGETS := *.sh MAKE_TARGETS := tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\ tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\ - tst_getconf tst_supported_fs + tst_getconf tst_supported_fs tst_check_drivers include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/lib/tst_check_drivers.c new file +11
-0@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved. */ + +#include <stdio.h> +#include "tst_kernel.h" + +int main (int argc,const char *argv[]) +{ +const char *name; +int i; +
testcases/lib/tst_check_drivers.c line 21
Quoted 10 lines
testcases/lib/tst_check_drivers.c new file +10
-0+if (argc <2 ) { +fprintf (stderr,"Please provide kernel driver list\n" ); +return 1 ; + } + +for (i =1 ; (name = argv[i]); ++i) +if (tst_check_driver (name)) { +fprintf (stderr,"%s" , name); +return 1 ; + }
I would be happier if we put a curly braces around large blocks inside of other blocks as LKML prefers to do, since this piece of code is starting to look a bit like python...
Other than that this looks very good.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH v2 1/4 lib/tst_test.c: add 'needs_drivers' option with tst_check_drivers cmd
Quoted 12 lines · Cyril Hrubis
Hi!
doc/test-writing-guidelines.txt https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html · line 1457
Quoted 6 lines
+2.2.26 Checking kernel for the driver support
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^doc/test-writing-guidelines.txt +4
-0+ +Someties test needs certain drivers to be available in the kernel and must +end with TCONF if any are missing. For this task there is the '.needs_drivers' +option which accepts NULL-terminated array of the drivers names.Maybe we should explicitly say here that this works for both drivers that are compiled-in and modules, since otherwise this may confuse the users, especially since we talk about modprobe in the next paragraph.
Quoted 7 lines
I would write something as:
"Some tests may need specific kernel drivers, either compiled in, or loaded as a module. If .need_drivers points to a NULL-terminated array of kernel module names these are all checked and the test exits with TCONF on first missing driver."
OK, thanks! I guess this also correlates with using the --dry-run option of modprobe that I'm going to add in the 3rd version [1], if there are no objections.
[1] http://lists.linux.it/pipermail/ltp/2018-August/009128.html