[LTP] [PATCH v1] tst_net.sh: Add more tst_require_cmds check

Wei Gao wegao@suse.com
Tue Jan 17 09:48:56 CET 2023


On Tue, Jan 17, 2023 at 09:33:14AM +0100, Petr Vorel wrote:
> Hi Wei,
> 
> > More strict check for ns_xxx etc will help avoid following issue:
> > https://github.com/linux-test-project/ltp/issues/991
> 
> > Signed-off-by: Wei Gao <wegao@suse.com>
> > Suggested-by: Petr Vorel <pvorel@suse.cz>
> > ---
> >  testcases/lib/tst_net.sh | 2 ++
> >  1 file changed, 2 insertions(+)
> 
> > diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> > index ceb45c98d..ec915ad74 100644
> > --- a/testcases/lib/tst_net.sh
> > +++ b/testcases/lib/tst_net.sh
> > @@ -205,6 +205,7 @@ tst_rhost_run()
> >  	sh_cmd="$pre_cmd $cmd $post_cmd"
> 
> >  	if [ -n "${TST_USE_NETNS:-}" ]; then
> > +		tst_require_cmds ip ns_create ns_exec ns_ifmove
> Why this? none of these commands is used here.
This line is the key to avoid wrong configuration(such as add ip inteface etc..) continue even ns_xxx not exist,
you can check following code, line 222 will execute ns_xxx with error but not exit test immediately, so if we add 
require_cmds here then we can avoid it. (line 222 $rcmd will contain command ns_xxx)

 218                 tst_res_ TINFO "tst_rhost_run: cmd: $cmd"
 219                 tst_res_ TINFO "$use: $rcmd \"$sh_cmd\" $out 2>&1"
 220         fi
 221
 222         output=$($rcmd "$sh_cmd" $out 2>&1 || echo 'RTERR')
 223
 224         echo "$output" | grep -q 'RTERR$' && ret=1
 225         if [ $ret -eq 1 ]; then


> 
> >  		use="NETNS"
> >  		rcmd="$LTP_NETNS sh -c"
> >  	else
> > @@ -1006,6 +1007,7 @@ IPV6_RHOST="${IPV6_RHOST:-fd00:1:1:1::1/64}"
> >  # tst_net_iface_prefix -h
> >  # tst_net_vars -h
> >  if [ -z "$_tst_net_parse_variables" ]; then
> > +	tst_require_cmds tst_net_ip_prefix
> This is correct.
> 
> Kind regards,
> Petr


More information about the ltp mailing list