public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 3/6] tst_net.sh: Harden against multiple loading
Date: Wed, 20 Jun 2018 11:52:32 +0200	[thread overview]
Message-ID: <20180620095232.GA21435@rei> (raw)
In-Reply-To: <20180618173707.30351-4-pvorel@suse.cz>

Hi!
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  testcases/lib/tst_net.sh | 42 +++++++++++++++++++++++++---------------
>  1 file changed, 26 insertions(+), 16 deletions(-)
> 
> diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
> index aad701952..ac61dfab8 100644
> --- a/testcases/lib/tst_net.sh
> +++ b/testcases/lib/tst_net.sh
> @@ -19,14 +19,6 @@
>  # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
>  #

Can't we just add some kind of guards to the library script?

If we add something like this:

[ "$TST_LIB_LOADED" ] && return 0
TST_LIB_LOADED=1

The library will be sourced exactly once.


> -TST_OPTS="6$TST_OPTS"
> -TST_PARSE_ARGS_CALLER="$TST_PARSE_ARGS"
> -TST_PARSE_ARGS="tst_net_parse_args"
> -TST_USAGE_CALLER="$TST_USAGE"
> -TST_USAGE="tst_net_usage"
> -TST_SETUP_CALLER="$TST_SETUP"
> -TST_SETUP="tst_net_setup"
> -
>  # Blank for an IPV4 test; 6 for an IPV6 test.
>  TST_IPV6=${TST_IPV6:-}
>  TST_IPVER=${TST_IPV6:-4}
> @@ -73,14 +65,6 @@ tst_net_setup()
>  	[ -n "$TST_SETUP_CALLER" ] && $TST_SETUP_CALLER
>  }
>  
> -if [ -z "$TST_LIB_LOADED" ]; then
> -	[ -n "$TST_USE_LEGACY_API" ] && . test.sh || . tst_test.sh
> -fi
> -
> -if [ -n "$TST_USE_LEGACY_API" ]; then
> -	tst_net_read_opts "$@"
> -fi
> -
>  # old vs. new API compatibility layer
>  tst_res_()
>  {
> @@ -659,6 +643,32 @@ tst_cleanup_rhost()
>  	tst_rhost_run -c "rm -rf $TST_TMPDIR"
>  }
>  
> +if [ -z "$TST_LIB_LOADED" ]; then
> +	TST_OPTS="6$TST_OPTS"
> +	TST_PARSE_ARGS_CALLER="$TST_PARSE_ARGS"
> +	TST_PARSE_ARGS="tst_net_parse_args"
> +	TST_USAGE_CALLER="$TST_USAGE"
> +	TST_USAGE="tst_net_usage"
> +	TST_SETUP_CALLER="$TST_SETUP"
> +	TST_SETUP="tst_net_setup"
> +
> +	if [ "$TST_PARSE_ARGS_CALLER" = "$TST_PARSE_ARGS" ]; then
> +		unset TST_PARSE_ARGS_CALLER
> +	fi
> +	if [ "$TST_USAGE_CALLER" = "$TST_USAGE" ]; then
> +		unset TST_USAGE_CALLER
> +	fi
> +	if [ "$TST_PARSE_ARGS_CALLER" = "$TST_PARSE_ARGS" ]; then
> +		unset TST_PARSE_ARGS_CALLER
> +	fi
> +
> +	[ -n "$TST_USE_LEGACY_API" ] && . test.sh || . tst_test.sh
> +fi
> +
> +if [ -n "$TST_USE_LEGACY_API" ]; then
> +	tst_net_read_opts "$@"
> +fi
> +
>  # Management Link
>  [ -z "$RHOST" ] && TST_USE_NETNS="yes"
>  export RHOST="$RHOST"
> -- 
> 2.17.1
> 

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2018-06-20  9:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-18 17:37 [LTP] [PATCH 0/6] Migrate tests using virt_lib.sh and ipsec_lib.sh to new API Petr Vorel
2018-06-18 17:37 ` [LTP] [PATCH 1/6] net/ipsec: Improve log info messages Petr Vorel
2018-06-18 17:37 ` [LTP] [PATCH 2/6] tst_test.sh: Introduce TST_LIB_LOADED Petr Vorel
2018-06-18 17:37 ` [LTP] [PATCH 3/6] tst_net.sh: Harden against multiple loading Petr Vorel
2018-06-20  9:52   ` Cyril Hrubis [this message]
2018-06-18 17:37 ` [LTP] [PATCH 4/6] net/ipsec: Use ':' as array separator for -s parameter Petr Vorel
2018-06-18 17:37 ` [LTP] [PATCH 5/6] net/{stress, virt}: Use SPDX-License-Identifier GPL-2.0-or-later Petr Vorel
2018-06-18 17:37 ` [LTP] [PATCH 6/6] net/{stress, virt}: Migrate tests using virt_lib.sh and ipsec_lib.sh Petr Vorel
2018-06-20 11:31   ` Alexey Kodanev
2018-06-22 11:21     ` 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=20180620095232.GA21435@rei \
    --to=chrubis@suse.cz \
    --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