Linux Test Project
 help / color / mirror / Atom feed
* [LTP] [RFC] tst_check_cmds to exit only current test
@ 2018-03-29 11:45 Petr Vorel
  2018-04-04 13:15 ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2018-03-29 11:45 UTC (permalink / raw)
  To: ltp

Hi,

I'm thinking about implementing tst_check_cmds() equivalent just for current test.
tst_check_cmds() breaks whole testing (tst_brkm TCONF "'$cmd' not found"), which is usually what we want. But sometimes it'd be handy to have an easy way to skip only current test.
E.g. interface stress tests (if-addr-adddel, ...) run test with ifconfig and then with ip and require ifconfig (tst_check_cmds ifconfig).
As ifconfig is not already available in some distros nothing is tested in this case.

# TODO: find a better name
# another option (maybe better would be to add getopt option to tst_check_cmds()
tst_check_cmds_test()
{
	local cmd
	for cmd in $*; do
		if ! command -v $cmd > /dev/null 2>&1; then
			tst_res TCONF "'$cmd' not found"
			return 32; # we don't have tst_flag2mask() in new API
		fi
	done
}

testcases/network/stress/interface/if-addr-adddel
test_body()
{
	local cmd_type=$1                                                                                                                   
                                                                                                                                        
    case $cmd_type in                                                                                                                   
    if_cmd) local cmd_name='ifconfig' ;;
    ip_cmd) local cmd_name='ip' ;;                                                                                                      
    *) tst_brkm TBROK "Unknown test parameter '$cmd_type'"                                                                              
    esac
	tst_check_cmds_test ifconfig || return
...

Is it valid approach approach or should we use getopts to run the test twice?
Well, this wouldn't help with interface stress tests as test_net.sh still use the old
shell API, but that can change.

Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [RFC] tst_check_cmds to exit only current test
  2018-03-29 11:45 [LTP] [RFC] tst_check_cmds to exit only current test Petr Vorel
@ 2018-04-04 13:15 ` Cyril Hrubis
  2018-04-04 13:44   ` Petr Vorel
  2018-04-04 13:46   ` Petr Vorel
  0 siblings, 2 replies; 7+ messages in thread
From: Cyril Hrubis @ 2018-04-04 13:15 UTC (permalink / raw)
  To: ltp

Hi!
> # TODO: find a better name
> # another option (maybe better would be to add getopt option to tst_check_cmds()
> tst_check_cmds_test()

Just call it tst_test_cmds() then.

> {
> 	local cmd
> 	for cmd in $*; do
> 		if ! command -v $cmd > /dev/null 2>&1; then
> 			tst_res TCONF "'$cmd' not found"
> 			return 32; # we don't have tst_flag2mask() in new API
> 		fi
> 	done
> }
> 
> testcases/network/stress/interface/if-addr-adddel
> test_body()
> {
> 	local cmd_type=$1                                                                                                                   
>                                                                                                                                         
>     case $cmd_type in                                                                                                                   
>     if_cmd) local cmd_name='ifconfig' ;;
>     ip_cmd) local cmd_name='ip' ;;                                                                                                      
>     *) tst_brkm TBROK "Unknown test parameter '$cmd_type'"                                                                              
>     esac
> 	tst_check_cmds_test ifconfig || return
> ...

Huh, why do we even have the case here?

Why isn't the cmd_type either ip or ifconfig?

Then we can just do:

	tst_test_cmds $1 || return

> Is it valid approach approach or should we use getopts to run the test twice?

That is a valid approach as well, we can just do:

if-addr-adddel_ifconfig if-addr-adddel ifconfig
if-addr-adddel_ip if-addr-adddel ip

in the runtest file, which would make the test results more detailed,
as it will be clear what was actually skipped, which is always nice.

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [RFC] tst_check_cmds to exit only current test
  2018-04-04 13:15 ` Cyril Hrubis
@ 2018-04-04 13:44   ` Petr Vorel
  2018-04-04 13:51     ` Cyril Hrubis
  2018-04-04 13:46   ` Petr Vorel
  1 sibling, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2018-04-04 13:44 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> > # TODO: find a better name
> > # another option (maybe better would be to add getopt option to tst_check_cmds()
> > tst_check_cmds_test()

> Just call it tst_test_cmds() then.

> > {
> > 	local cmd
> > 	for cmd in $*; do
> > 		if ! command -v $cmd > /dev/null 2>&1; then
> > 			tst_res TCONF "'$cmd' not found"
> > 			return 32; # we don't have tst_flag2mask() in new API
> > 		fi
> > 	done
> > }
I'll implement it regardless it's actually used in interface tests as it's handy (I'd like
to use it in ima tests).
I just don't like that new API doesn't have constants for TCONF, TPASS, etc (legacy API
has it).

> > testcases/network/stress/interface/if-addr-adddel
> > test_body()
> > {
> > 	local cmd_type=$1

> >     case $cmd_type in
> >     if_cmd) local cmd_name='ifconfig' ;;
> >     ip_cmd) local cmd_name='ip' ;;
> >     *) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
> >     esac
> > 	tst_check_cmds_test ifconfig || return
> > ...

> Huh, why do we even have the case here?

> Why isn't the cmd_type either ip or ifconfig?

> Then we can just do:

> 	tst_test_cmds $1 || return
Copy pasted, make sense to use much simpler form.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [RFC] tst_check_cmds to exit only current test
  2018-04-04 13:15 ` Cyril Hrubis
  2018-04-04 13:44   ` Petr Vorel
@ 2018-04-04 13:46   ` Petr Vorel
  2018-04-04 13:58     ` Alexey Kodanev
  1 sibling, 1 reply; 7+ messages in thread
From: Petr Vorel @ 2018-04-04 13:46 UTC (permalink / raw)
  To: ltp

Hi Alexey,

> > Is it valid approach approach or should we use getopts to run the test twice?

> That is a valid approach as well, we can just do:

> if-addr-adddel_ifconfig if-addr-adddel ifconfig
> if-addr-adddel_ip if-addr-adddel ip

> in the runtest file, which would make the test results more detailed,
> as it will be clear what was actually skipped, which is always nice.
Any objection to this? I'd prefer to use this way (changed in all interface tests).


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [RFC] tst_check_cmds to exit only current test
  2018-04-04 13:44   ` Petr Vorel
@ 2018-04-04 13:51     ` Cyril Hrubis
  2018-04-04 14:57       ` Petr Vorel
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2018-04-04 13:51 UTC (permalink / raw)
  To: ltp

Hi!
> > > {
> > > 	local cmd
> > > 	for cmd in $*; do
> > > 		if ! command -v $cmd > /dev/null 2>&1; then
> > > 			tst_res TCONF "'$cmd' not found"
> > > 			return 32; # we don't have tst_flag2mask() in new API
> > > 		fi
> > > 	done
> > > }
> I'll implement it regardless it's actually used in interface tests as it's handy (I'd like
> to use it in ima tests).
> I just don't like that new API doesn't have constants for TCONF, TPASS, etc (legacy API
> has it).

That is intentional as you are not supposed to exit the test yourself as
the result is stored in the counters and the return value is composed
based on that. That also means that the test without the tst_run()
function has to call tst_do_exit() at the end if it uses tst_res() to
report results.

And actually in this case it does not matter what do we return here as
the return value is not propagate anywhere, just doing return 1 would
work as well.

> > > testcases/network/stress/interface/if-addr-adddel
> > > test_body()
> > > {
> > > 	local cmd_type=$1
> 
> > >     case $cmd_type in
> > >     if_cmd) local cmd_name='ifconfig' ;;
> > >     ip_cmd) local cmd_name='ip' ;;
> > >     *) tst_brkm TBROK "Unknown test parameter '$cmd_type'"
> > >     esac
> > > 	tst_check_cmds_test ifconfig || return
> > > ...
> 
> > Huh, why do we even have the case here?
> 
> > Why isn't the cmd_type either ip or ifconfig?
> 
> > Then we can just do:
> 
> > 	tst_test_cmds $1 || return
> Copy pasted, make sense to use much simpler form.
> 
> 
> Kind regards,
> Petr

-- 
Cyril Hrubis
chrubis@suse.cz

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [RFC] tst_check_cmds to exit only current test
  2018-04-04 13:46   ` Petr Vorel
@ 2018-04-04 13:58     ` Alexey Kodanev
  0 siblings, 0 replies; 7+ messages in thread
From: Alexey Kodanev @ 2018-04-04 13:58 UTC (permalink / raw)
  To: ltp

On 04.04.2018 16:46, Petr Vorel wrote:
> Hi Alexey,
> 
>>> Is it valid approach approach or should we use getopts to run the test twice?
> 
>> That is a valid approach as well, we can just do:
> 
>> if-addr-adddel_ifconfig if-addr-adddel ifconfig
>> if-addr-adddel_ip if-addr-adddel ip
> 
>> in the runtest file, which would make the test results more detailed,
>> as it will be clear what was actually skipped, which is always nice.
> Any objection to this? I'd prefer to use this way (changed in all interface tests).

No, I agree.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [LTP] [RFC] tst_check_cmds to exit only current test
  2018-04-04 13:51     ` Cyril Hrubis
@ 2018-04-04 14:57       ` Petr Vorel
  0 siblings, 0 replies; 7+ messages in thread
From: Petr Vorel @ 2018-04-04 14:57 UTC (permalink / raw)
  To: ltp

Hi Cyril,

> > I'll implement it regardless it's actually used in interface tests as it's handy (I'd like
> > to use it in ima tests).
> > I just don't like that new API doesn't have constants for TCONF, TPASS, etc (legacy API
> > has it).

> That is intentional as you are not supposed to exit the test yourself as
> the result is stored in the counters and the return value is composed
> based on that. That also means that the test without the tst_run()
> function has to call tst_do_exit() at the end if it uses tst_res() to
> report results.
If API users don't need to distinguish exit output (TCONF, TWARN), it's really no need to
export it. But there are other ways to use it than just exit.

Commit d5c80cb04 ("tst_netload: Exit with TCONF when netstress exit with CONF")
could have benefited from it. The point was that netstress binary which is using API is
called from network tests, we could use it's exit code (i.e. if netstress TCONF, we
shouldn't TFAIL, but also TCONF).

We use grep anyway, as tst_rhost_run() from library don't exit error int according to T*,
but just 1. Maybe I'm missing something and trying to use wrong approach.


> And actually in this case it does not matter what do we return here as
> the return value is not propagate anywhere, just doing return 1 would
> work as well.
Originally I was thinking about more use-cases, but there is really just one => I'll use 1
as error indicator.


Kind regards,
Petr

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-04-04 14:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-29 11:45 [LTP] [RFC] tst_check_cmds to exit only current test Petr Vorel
2018-04-04 13:15 ` Cyril Hrubis
2018-04-04 13:44   ` Petr Vorel
2018-04-04 13:51     ` Cyril Hrubis
2018-04-04 14:57       ` Petr Vorel
2018-04-04 13:46   ` Petr Vorel
2018-04-04 13:58     ` Alexey Kodanev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox