From: Joerg Vehlow <lkml@jv-coder.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] tst_test.sh: Add TST_USES_MODULE
Date: Wed, 9 Oct 2019 08:16:18 +0200 [thread overview]
Message-ID: <20191009061619.48677-2-lkml@jv-coder.de> (raw)
In-Reply-To: <20191009061619.48677-1-lkml@jv-coder.de>
From: Joerg Vehlow <joerg.vehlow@aox-tech.de>
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(-)
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index cd0d28b8e..4a0652a8d 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -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'
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index e0b24c6b9..c70a5abbe 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -396,6 +396,32 @@ _tst_require_root()
fi
}
+_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
+
+ 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."
+ fi
+ else
+ tst_res TINFO "Found module at '$TST_MODPATH'"
+ fi
+}
+
tst_run()
{
local _tst_i
@@ -410,7 +436,7 @@ tst_run()
SETUP|CLEANUP|TESTFUNC|ID|CNT|MIN_KVER);;
OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
- NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
+ NEEDS_CMDS|NEEDS_MODULE|USES_MODULE|MODPATH|DATAROOT);;
NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
IPV6|IPVER|TEST_DATA|TEST_DATA_IFS);;
RETRY_FUNC|RETRY_FN_EXP_BACKOFF);;
@@ -487,22 +513,12 @@ tst_run()
TST_DEVICE_FLAG=1
fi
- if [ -n "$TST_NEEDS_MODULE" ]; then
- for tst_module in "$TST_NEEDS_MODULE" \
- "$LTPROOT/testcases/bin/$TST_NEEDS_MODULE" \
- "$TST_STARTWD/$TST_NEEDS_MODULE"; do
-
- if [ -f "$tst_module" ]; then
- TST_MODPATH="$tst_module"
- break
- fi
- done
-
- if [ -z "$TST_MODPATH" ]; then
- tst_brk TCONF "Failed to find module '$TST_NEEDS_MODULE'"
- else
- tst_res TINFO "Found module at '$TST_MODPATH'"
- fi
+ if [ -n "$TST_NEEDS_MODULE" ] && [ -n "$TST_USES_MODULE" ]; then
+ tst_brk TBROK "Setting TST_NEEDS_MODULE and TST_USES_MODULE at the same time is not allowed"
+ elif [ -n "$TST_NEEDS_MODULE" ]; then
+ _tst_find_module "$TST_NEEDS_MODULE" 1
+ elif [ -n "$TST_USES_MODULE" ]; then
+ _tst_find_module "$TST_USES_MODULE" 0
fi
if [ -n "$TST_SETUP" ]; then
--
2.20.1
next prev parent reply other threads:[~2019-10-09 6:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-09 6:16 [LTP] Add TST_USES_MODULE and tst_test_root Joerg Vehlow
2019-10-09 6:16 ` Joerg Vehlow [this message]
2019-10-09 7:36 ` [LTP] [PATCH 1/2] tst_test.sh: Add TST_USES_MODULE Petr Vorel
2019-10-09 7:48 ` Joerg Vehlow
2019-10-09 6:16 ` [LTP] [PATCH 2/2] tst_test.sh: Add public tst_test_root command Joerg Vehlow
2019-10-09 6:52 ` Petr Vorel
2019-10-09 6:57 ` Joerg Vehlow
2019-10-09 7:53 ` Petr Vorel
2019-10-09 11:39 ` Cyril Hrubis
2019-10-09 11:43 ` Joerg Vehlow
2019-10-09 11:48 ` Cyril Hrubis
2019-10-09 11:53 ` Joerg Vehlow
2019-10-09 12:28 ` Cyril Hrubis
2019-10-11 8:36 ` Petr Vorel
2019-10-11 8:39 ` Joerg Vehlow
2019-10-11 8:20 ` Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191009061619.48677-2-lkml@jv-coder.de \
--to=lkml@jv-coder.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox