Add TST_USES_MODULE and tst_test_root
In preparation of lsmod01.sh patch v4.
The test requires a module only, if no modules are loaded and in order to load the module, root is required.
PATCH 1/2 tst_test.sh: Add TST_USES_MODULE
From: Joerg Vehlow <[email protected]>
Adds a new library variable TST_USES_MODULE, that can be used, when a test may need a module, but should not fail, if the module is not available.
--- doc/test-writing-guidelines.txt | 4 ++- testcases/lib/tst_test.sh | 50 ++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 18 deletions(-)
doc/test-writing-guidelines.txt +3 -1
@@ -2125,6 +2125,8 @@ 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_USES_MODULE' | Same as TST_NEEDS_MODULE, except that a missing module +| | is not an error. | 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test. |=============================================================================
@@ -2174,7 +2176,7 @@ Locating kernel modules +++++++++++++++++++++++ The LTP build system can build kernel modules as well, setting -'$TST_NEEDS_MODULE' to module name will cause to library to look for the +'$TST_NEEDS_MODULE' to module name will cause the library to look for the module in a few possible paths. If module was found the path to it will be stored into '$TST_MODPATH'
testcases/lib/tst_test.sh +33 -17
68 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 1/2 tst_test.sh: Add TST_USES_MODULE
Hi Joerg,
Quoted 4 lines
From: Joerg Vehlow <[email protected]>
Adds a new library variable
TST_USES_MODULE, that can be used, when a test may need a module, but should not fail, if the module is not available.
I wonder if TST_USES_MODULE is descriptive enough. But it looks to me better than TST_GET_MODPATH (which Cyril suggested in v3).
We should think twice as _USES_ keyword should be used consistently for the same approach in different functionality (i.e. TST_USES_FOO is the same as TST_NEEDS_FOO, but not TCONF/TBROK if it fails).
But whole concept of TST_USES_FOO looks to me a bit complicated, if needed only for modules. Cannot we just call _tst_find_module directly in this case and not introduce variable?
...
Quoted 11 lines
+++
b/doc/test-writing-guidelines.txtdoc/test-writing-guidelines.txt +2
-0@@ -2125,6 +2125,8 @@ 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_USES_MODULE' | Same as TST_NEEDS_MODULE, except that a missing module +| | is not an error. | 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test. |=============================================================================
doc/test-writing-guidelines.txt Locating kernel modules · line 2179
Quoted 5 lines
doc/test-writing-guidelines.txt +1
-1@@ -2174,7 +2176,7 @@ Locating kernel modules +++++++++++++++++++++++ The LTP build system can build kernel modules as well, setting -'$TST_NEEDS_MODULE' to module name will cause to library to look for the +'$TST_NEEDS_MODULE' to module name will cause the library to look for the
This is unrelated change, I merged it as a separate commit (c518ee8b9).
...
testcases/lib/tst_test.sh _tst_require_root() · line 406
Quoted 8 lines
testcases/lib/tst_test.sh +8
-0+_tst_find_module() +{ + local _tst_module=$1 + local _tst_is_required=${2:-0} + + for tst_module in "$_tst_module" \ + "$LTPROOT/testcases/bin/$_tst_module" \ + "$TST_STARTWD/$_tst_module"; do
nit: (can be fixed by person who merges it): It's not visible, but uses more tags than it should be, so it looks like:
+ for tst_module in "$_tst_module" \
+ "$LTPROOT/testcases/bin/$_tst_module" \
+ "$TST_STARTWD/$_tst_module"; do
+
+ if [ -f "$tst_module" ]; then
+ TST_MODPATH="$tst_module"
+ break
+ fi
I actually like the original alignment created by Alexey:
for tst_module in "$TST_NEEDS_MODULE" \
"$LTPROOT/testcases/bin/$TST_NEEDS_MODULE" \
"$TST_STARTWD/$TST_NEEDS_MODULE"; dotestcases/lib/tst_test.sh _tst_require_root() · line 418
Quoted 12 lines
testcases/lib/tst_test.sh +12
-0+ + if [ -f "$tst_module" ]; then + TST_MODPATH="$tst_module" + break + fi + done + + if [ -z "$TST_MODPATH" ]; then + if [ $_tst_is_required -eq 1 ]; then + tst_brk TCONF "Failed to find module '$_tst_module'" + else + tst_res TINFO "Module '$_tst_module' not found."
nit: please drop dot at the end (can be fixed by person who merges it).
testcases/lib/tst_test.sh _tst_require_root() · line 422
Quoted 4 lines
testcases/lib/tst_test.sh +4
-0+ fi + else + tst_res TINFO "Found module at '$TST_MODPATH'" + fi
nit: this is IMHO more readable
if [ -n "$TST_MODPATH" ]; then
tst_res TINFO "Found module at '$TST_MODPATH'" return
fi
if [ $_tst_is_required -eq 1 ]; then
tst_brk TCONF "Failed to find module '$_tst_module'"
else
tst_res TINFO "Module '$_tst_module' not found"
fi
Kind regards,
Petr
PATCH 1/2 tst_test.sh: Add TST_USES_MODULE
Hi,
Quoted 5 lines
Quoted 2 lines
Adds a new library variable
TST_USES_MODULE, that can be used, when a test may need a module, but should not fail, if the module is not available.I wonder if
TST_USES_MODULEis descriptive enough. But it looks to me better thanTST_GET_MODPATH(which Cyril suggested in v3).
Quoted 7 lines
We should think twice as _USES_ keyword should be used consistently for the same approach in different functionality (i.e.
TST_USES_FOOis the same asTST_NEEDS_FOO, but not TCONF/TBROK if it fails).But whole concept of
TST_USES_FOOlooks to me a bit complicated, if needed only for modules. Cannot we just call_tst_find_moduledirectly in this case and not introduce variable?
I was thinking about adding a function to search for a module, but struggled with
returning the name of the found found module.
I had something like
MODPATH=$(tst_find_module "$MODULE_NAME")
but this cannot use tst_res or tst_brk, which I don't like. I also don't like just calling_tst_find_module and getting the result in some "magic" variable. That is the reason
why I went with Cyril's Idea of a variable
Quoted 20 lines
...
testcases/lib/tst_test.sh _tst_require_root() · line 406
Quoted 8 lines
testcases/lib/tst_test.sh +8
-0+_tst_find_module() +{ + local _tst_module=$1 + local _tst_is_required=${2:-0} + + for tst_module in "$_tst_module" \ + "$LTPROOT/testcases/bin/$_tst_module" \ + "$TST_STARTWD/$_tst_module"; donit: (can be fixed by person who merges it): It's not visible, but uses more tags than it should be, so it looks like:
testcases/lib/tst_test.sh +8
-0+ for tst_module in "$_tst_module" \ + "$LTPROOT/testcases/bin/$_tst_module" \ + "$TST_STARTWD/$_tst_module"; do + + if [ -f "$tst_module" ]; then + TST_MODPATH="$tst_module" + break + fiI actually like the original alignment created by Alexey:
Quoted 3 lines
for tst_module in "$TST_NEEDS_MODULE" \
"$LTPROOT/testcases/bin/$TST_NEEDS_MODULE" \
"$TST_STARTWD/$TST_NEEDS_MODULE"; doJust an accident by my editor, I'll fix it for v2
Quoted 14 lines
testcases/lib/tst_test.sh _tst_require_root() · line 418
Quoted 13 lines
testcases/lib/tst_test.sh +12
-0+ + if [ -f "$tst_module" ]; then + TST_MODPATH="$tst_module" + break + fi + done + + if [ -z "$TST_MODPATH" ]; then + if [ $_tst_is_required -eq 1 ]; then + tst_brk TCONF "Failed to find module '$_tst_module'" + else + tst_res TINFO "Module '$_tst_module' not found."nit: please drop dot at the end (can be fixed by person who merges it).
Fixed for v2
Quoted 11 lines
testcases/lib/tst_test.sh _tst_require_root() · line 422
Quoted 4 lines
testcases/lib/tst_test.sh +4
-0+ fi + else + tst_res TINFO "Found module at '$TST_MODPATH'" + finit: this is IMHO more readable
if [ -n "$TST_MODPATH" ]; then
tst_resTINFO "Found module at '$TST_MODPATH'" return
fi
Quoted 5 lines
if [ $_tst_is_required -eq 1 ]; then
tst_brkTCONF "Failed to find module '$_tst_module'"
else
tst_resTINFO "Module '$_tst_module' not found"
fi
It would still keep the else and not use a return. Indentation clearly shows what's going on.
But I agree to invert the logic, first testing the good case, than the bad.
Quoted 3 lines
Kind regards,
Petr
J?rg
PATCH 2/2 tst_test.sh: Add public tst_test_root command
In reply to Joerg VehlowFrom: Joerg Vehlow <[email protected]>
If a test requires root only under certan circumstances, TST_NEEDS_ROOT is not sufficient, because it always requires root.
--- testcases/lib/tst_test.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
testcases/lib/tst_test.sh +8 -8
@@ -326,6 +326,13 @@ tst_check_cmds() return 0 } +tst_test_root() +{ + if [ "$(id -ru)" != 0 ]; then + tst_brk TCONF "Must be super/root for this test!" + fi +} + tst_test_drivers() { [ $# -eq 0 ] && return 0
@@ -389,13 +396,6 @@ _tst_setup_timer() _tst_setup_timer_pid=$! } -_tst_require_root() -{ - if [ "$(id -ru)" != 0 ]; then - tst_brk TCONF "Must be super/root for this test!" - fi -} - _tst_find_module() { local _tst_module=$1
@@ -469,7 +469,7 @@ tst_run() tst_brk TBROK "Number of iterations (-i) must be > 0" fi - [ "$TST_NEEDS_ROOT" = 1 ] && _tst_require_root + [ "$TST_NEEDS_ROOT" = 1 ] && tst_test_root [ "$TST_DISABLE_APPARMOR" = 1 ] && tst_disable_apparmor [ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
Signature · 1 line
2.20.1
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Hi Joerg,
...
Quoted 2 lines
testcases/lib/tst_test.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
...
testcases/lib/tst_test.sh _tst_setup_timer() · line 397
Quoted 6 lines
testcases/lib/tst_test.sh +0
-6-_tst_require_root() -{ - if [ "$(id -ru)" != 0 ]; then - tst_brk TCONF "Must be super/root for this test!" - fi -}
You need to replace s/_tst_require_root/tst_test_root/ in other library files (tst_net.sh, tst_security.sh).
...
Kind regards,
Petr
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Hi,
Quoted 2 lines
You need to replace s/_tst_require_root/tst_test_root/ in other library files (
tst_net.sh,tst_security.sh).
Sorry, did not expect functions with _ to be used in other files. I'll check it next time
J?rg
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Hi J?rg,
Quoted 4 lines
Quoted 2 lines
You need to replace s/_tst_require_root/tst_test_root/ in other library files (
tst_net.sh,tst_security.sh).Sorry, did not expect functions with _ to be used in other files. I'll check it next time
No problem :). Yes, they cannot be used in tests. But new shell API library is spread in 3 files. I added a patch to document library itself from developer perspective [1].
Kind regards,
Petr
PATCH 2/2 tst_test.sh: Add public tst_test_root command
In reply to Joerg VehlowHi!
Quoted 11 lines
If a test requires root only under certan circumstances,
TST_NEEDS_ROOTis not sufficient, because it always requires root.--- testcases/lib/tst_test.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)testcases/lib/tst_test.sh +0
-0
testcases/lib/tst_test.sh tst_check_cmds() · line 334
Quoted 9 lines
testcases/lib/tst_test.sh +6
-0@@ -326,6 +326,13 @@ tst_check_cmds() return 0 } +tst_test_root() +{ + if [ "$(id -ru)" != 0 ]; then + tst_brk TCONF "Must be super/root for this test!" + fi +}
Can we keep the name to be tst_require_root() please?
Historically this function has been always named like this in LTP.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Hi,
Quoted 4 lines
Can we keep the name to be
tst_require_root()please?Historically this function has been always named like this in LTP.
Not a very good argument for two reasons:
1. The function was internal to the library, so no one (except for library developers)
?? should know about it anyway. The old public interface
(TST_NEEDS_ROOT) is unchanged
2. I wanted to make it consistent with other functions, that do similar stuff like
?? tst_test_drivers and tst_test_cmds. Both also call tst_brk in case
of unsuccessful tests.
J?rg
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Hi!
Quoted 7 lines
Quoted 4 lines
Can we keep the name to be
tst_require_root()please?Historically this function has been always named like this in LTP.
Not a very good argument for two reasons:
1. The function was internal to the library, so no one (except for library developers)
It has been in a public API for the old library for more than ten years before the new library was written.
Quoted 4 lines
2. I wanted to make it consistent with other functions, that do similar stuff like
????tst_test_driversandtst_test_cmds. Both also calltst_brkin case
of unsuccessful tests.
Well I do not like these names either, it's less descriptive that it would have been with tst_require_cmds and tst_require_drivers, so if anything I would be for renaming the tst_test_* ones.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
Can we keep the name to be
tst_require_root()please?Historically this function has been always named like this in LTP.
Not a very good argument for two reasons:
1. The function was internal to the library, so no one (except for library developers)It has been in a public API for the old library for more than ten years before the new library was written.
Has been, but is not anymore. But I accept it as an argument.
Quoted 8 lines
Quoted 5 lines
2. I wanted to make it consistent with other functions, that do similar stuff like
????tst_test_driversandtst_test_cmds. Both also calltst_brkin case
of unsuccessful tests.Well I do not like these names either, it's less descriptive that it would have been with
tst_require_cmdsandtst_require_drivers, so if anything I would be for renaming the tst_test_* ones.
Fair enough, that makes sense. But then we require a change to tst_test_* first,
otherwise the api names are inconsistent. And I'm not sure if changing the other functions is really worth it.
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Hi!
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
2. I wanted to make it consistent with other functions, that do similar stuff like
????tst_test_driversandtst_test_cmds. Both also calltst_brkin case
of unsuccessful tests.Well I do not like these names either, it's less descriptive that it would have been with
tst_require_cmdsandtst_require_drivers, so if anything I would be for renaming the tst_test_* ones.Fair enough, that makes sense. But then we require a change to tst_test_* first,
otherwise the api names are inconsistent. And I'm not sure if changing the other functions is really worth it.
Should be easy for tst_test_drivers, that one is only used to implement the NEEDS_DRIVERS variable. And for the second one, we would have to change a few tests and one line of documentation, but that would be just a simple script. I can do that if we agree on the change.
@Jan @Peter what do you think?
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Hi Cyril,
Quoted 12 lines
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
2. I wanted to make it consistent with other functions, that do similar stuff like
????tst_test_driversandtst_test_cmds. Both also calltst_brkin case
of unsuccessful tests.Well I do not like these names either, it's less descriptive that it would have been with
tst_require_cmdsandtst_require_drivers, so if anything I would be for renaming the tst_test_* ones.Fair enough, that makes sense. But then we require a change to tst_test_* first,
otherwise the api names are inconsistent. And I'm not sure if changing the other functions is really worth it.
Quoted 6 lines
Should be easy for
tst_test_drivers, that one is only used to implement theNEEDS_DRIVERSvariable. And for the second one, we would have to change a few tests and one line of documentation, but that would be just a simple script. I can do that if we agree on the change.@Jan @Peter what do you think?
We already did rename once (0567a8958 shell: Rename s/tst_check_cmds/tst_test_cmds/), but even if we didn't;
I'm for renaming tst_test_* to tst_require_* - clear names are important (consistency with names as well).
Kind regards,
Petr
PATCH 2/2 tst_test.sh: Add public tst_test_root command
Quoted 6 lines
Quoted 2 lines
@Jan @Peter what do you think?
We already did rename once (
0567a8958shell: Rename s/tst_check_cmds/tst_test_cmds/), but even if we didn't;
I'm for renaming tst_test_* to tst_require_* - clear names are important (consistency with names as well).
That's two (and me) in favor of renaming tst_test_. I will submit a patch for it.
PATCH 2/2 tst_test.sh: Add public tst_test_root command
In reply to Cyril HrubisHi,
Quoted 9 lines
testcases/lib/tst_test.sh tst_check_cmds() · line 334
Quoted 6 lines
testcases/lib/tst_test.sh +6
-0+tst_test_root() +{ + if [ "$(id -ru)" != 0 ]; then + tst_brk TCONF "Must be super/root for this test!" + fi +}Can we keep the name to be
tst_require_root()please? Historically this function has been always named like this in LTP.
+1
Kind regards,
Petr