public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
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 09:48:53 +0200	[thread overview]
Message-ID: <c34e4432-ffe1-47a9-e93e-bce6b256072e@jv-coder.de> (raw)
In-Reply-To: <20191009073609.GB27854@dell5510>

Hi,
>> 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?
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
> ...
>> +_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"; do
Just an accident by my editor, I'll fix it for v2
>
>> +
>> +			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
>> +		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
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.
>
> Kind regards,
> Petr

J?rg

  reply	other threads:[~2019-10-09  7:48 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 ` [LTP] [PATCH 1/2] tst_test.sh: Add TST_USES_MODULE Joerg Vehlow
2019-10-09  7:36   ` Petr Vorel
2019-10-09  7:48     ` Joerg Vehlow [this message]
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=c34e4432-ffe1-47a9-e93e-bce6b256072e@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