public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Hangbin Liu <liuhangbin@gmail.com>
To: Petr Machata <petrm@nvidia.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	netdev@vger.kernel.org, Ido Schimmel <idosch@nvidia.com>,
	Shuah Khan <shuah@kernel.org>,
	linux-kselftest@vger.kernel.org, mlxsw@nvidia.com,
	Benjamin Poirier <bpoirier@nvidia.com>
Subject: Re: [PATCH net-next 01/10] selftests: net: Unify code of busywait() and slowwait()
Date: Mon, 15 Apr 2024 15:21:06 +0800	[thread overview]
Message-ID: <ZhzVYgjBmELthSUX@Laptop-X1> (raw)
In-Reply-To: <db8b8885e254893bba61d824d7cf2a6774dcb336.1712940759.git.petrm@nvidia.com>

On Fri, Apr 12, 2024 at 07:03:04PM +0200, Petr Machata wrote:
> Bodies of busywait() and slowwait() functions are almost identical. Extract
> the common code into a helper, loopy_wait, and convert busywait() and
> slowwait() into trivial wrappers.
> 
> Moreover, the fact that slowwait() uses seconds for units is really not
> intuitive, and the comment does not help much. Instead make the unit part
> of the name of the argument to further clarify what units are expected.
> 
> Cc: Hangbin Liu <liuhangbin@gmail.com>
> Signed-off-by: Petr Machata <petrm@nvidia.com>
> Reviewed-by: Benjamin Poirier <bpoirier@nvidia.com>
> ---
>  tools/testing/selftests/net/forwarding/lib.sh | 22 ++-----------------
>  tools/testing/selftests/net/lib.sh            | 16 +++++++++++---
>  2 files changed, 15 insertions(+), 23 deletions(-)
> 
> diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
> index 4103ed7afcde..658e4e7bf4b9 100644
> --- a/tools/testing/selftests/net/forwarding/lib.sh
> +++ b/tools/testing/selftests/net/forwarding/lib.sh
> @@ -95,27 +95,9 @@ source "$net_forwarding_dir/../lib.sh"
>  # timeout in seconds
>  slowwait()
>  {
> -	local timeout=$1; shift
> +	local timeout_sec=$1; shift
>  
> -	local start_time="$(date -u +%s)"
> -	while true
> -	do
> -		local out
> -		out=$("$@")
> -		local ret=$?
> -		if ((!ret)); then
> -			echo -n "$out"
> -			return 0
> -		fi
> -
> -		local current_time="$(date -u +%s)"
> -		if ((current_time - start_time > timeout)); then
> -			echo -n "$out"
> -			return 1
> -		fi
> -
> -		sleep 0.1
> -	done
> +	loopy_wait "sleep 0.1" "$((timeout_sec * 1000))" "$@"
>  }
>  
>  ##############################################################################
> diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/net/lib.sh
> index b7f7b8695165..c868c0aec121 100644
> --- a/tools/testing/selftests/net/lib.sh
> +++ b/tools/testing/selftests/net/lib.sh
> @@ -58,9 +58,10 @@ ksft_exit_status_merge()
>  		$ksft_xfail $ksft_pass $ksft_skip $ksft_fail
>  }
>  
> -busywait()
> +loopy_wait()
>  {
> -	local timeout=$1; shift
> +	local sleep_cmd=$1; shift
> +	local timeout_ms=$1; shift
>  
>  	local start_time="$(date -u +%s%3N)"
>  	while true
> @@ -74,13 +75,22 @@ busywait()
>  		fi
>  
>  		local current_time="$(date -u +%s%3N)"
> -		if ((current_time - start_time > timeout)); then
> +		if ((current_time - start_time > timeout_ms)); then
>  			echo -n "$out"
>  			return 1
>  		fi
> +
> +		$sleep_cmd
>  	done
>  }
>  
> +busywait()
> +{
> +	local timeout_ms=$1; shift
> +
> +	loopy_wait : "$timeout_ms" "$@"
> +}
> +
>  cleanup_ns()
>  {
>  	local ns=""
> -- 
> 2.43.0
> 

Reviewed-by: Hangbin Liu <liuhangbin@gmail.com>

  reply	other threads:[~2024-04-15  7:21 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-12 17:03 [PATCH net-next 00/10] selftests: Assortment of fixes Petr Machata
2024-04-12 17:03 ` [PATCH net-next 01/10] selftests: net: Unify code of busywait() and slowwait() Petr Machata
2024-04-15  7:21   ` Hangbin Liu [this message]
2024-04-12 17:03 ` [PATCH net-next 02/10] selftests: forwarding: lib.sh: Validate NETIFS Petr Machata
2024-04-15  7:47   ` Hangbin Liu
2024-04-12 17:03 ` [PATCH net-next 03/10] selftests: forwarding: bail_on_lldpad() should SKIP Petr Machata
2024-04-15  7:46   ` Hangbin Liu
2024-04-12 17:03 ` [PATCH net-next 04/10] selftests: drivers: hw: Fix ethtool_rmon Petr Machata
2024-04-12 17:03 ` [PATCH net-next 05/10] selftests: drivers: hw: ethtool.sh: Adjust output Petr Machata
2024-04-12 17:03 ` [PATCH net-next 06/10] selftests: drivers: hw: Include tc_common.sh in hw_stats_l3 Petr Machata
2024-04-12 17:03 ` [PATCH net-next 07/10] selftests: mlxsw: ethtool_lanes: Wait for lanes parameter dump explicitly Petr Machata
2024-04-12 17:03 ` [PATCH net-next 08/10] selftests: forwarding: router_mpath_nh: Add a diagram Petr Machata
2024-04-15  8:28   ` Hangbin Liu
2024-04-15 12:39   ` David Ahern
2024-04-12 17:03 ` [PATCH net-next 09/10] selftests: forwarding: router_mpath_nh_res: " Petr Machata
2024-04-15  8:31   ` Hangbin Liu
2024-04-12 17:03 ` [PATCH net-next 10/10] selftests: forwarding: router_nh: " Petr Machata
2024-04-15  8:31   ` Hangbin Liu
2024-04-16 10:20 ` [PATCH net-next 00/10] selftests: Assortment of fixes patchwork-bot+netdevbpf

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=ZhzVYgjBmELthSUX@Laptop-X1 \
    --to=liuhangbin@gmail.com \
    --cc=bpoirier@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=petrm@nvidia.com \
    --cc=shuah@kernel.org \
    /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