diff mbox series

[net-next,5/6] selftests: forwarding: add wait_for_dev() helper

Message ID 20240412151314.3365034-6-jiri@resnulli.us (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series selftests: virtio_net: introduce initial testing infrastructure | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/build_tools success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 1 maintainers not CCed: linux-kselftest@vger.kernel.org
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success net selftest script(s) already in Makefile
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 25 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-04-12--18-00 (tests: 959)

Commit Message

Jiri Pirko April 12, 2024, 3:13 p.m. UTC
From: Jiri Pirko <jiri@nvidia.com>

The existing setup_wait*() helper family check the status of the
interface to be up. Introduce wait_for_dev() to wait for the netdevice
to appear, for example after test script does manual device bind.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 tools/testing/selftests/net/forwarding/lib.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Benjamin Poirier April 12, 2024, 8:43 p.m. UTC | #1
On 2024-04-12 17:13 +0200, Jiri Pirko wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> The existing setup_wait*() helper family check the status of the
> interface to be up. Introduce wait_for_dev() to wait for the netdevice
> to appear, for example after test script does manual device bind.
> 
> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
> ---
>  tools/testing/selftests/net/forwarding/lib.sh | 19 +++++++++++++++++++
>  1 file changed, 19 insertions(+)
> 
> diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
> index 959183b516ce..74859f969997 100644
> --- a/tools/testing/selftests/net/forwarding/lib.sh
> +++ b/tools/testing/selftests/net/forwarding/lib.sh
> @@ -746,6 +746,25 @@ setup_wait()
>  	sleep $WAIT_TIME
>  }
>  
> +wait_for_dev()
> +{
> +	local dev=$1; shift
> +	local timeout=${1:-$WAIT_TIMEOUT}; shift
> +	local max_iterations=$(($timeout * 10))
> +
> +	for ((i = 1; i <= $max_iterations; ++i)); do
> +		ip link show dev $dev up &> /dev/null
> +		if [[ $? -ne 0 ]]; then
> +			sleep 0.1
> +		else
> +			return 0
> +		fi
> +	done
> +
> +	log_test wait_for_dev ": Interface $dev did not appear."
> +	exit 1
> +}

How about rewriting the function to make use of the `slowwait` helper as
follows:

wait_for_dev()
{
	local dev=$1; shift
	local timeout=${1:-$WAIT_TIMEOUT}; shift

	slowwait $timeout ip link show dev $dev up &> /dev/null
	if (( $? )); then
		check_err 1
		log_test wait_for_dev "Interface $dev did not appear."
		exit $EXIT_STATUS
	fi
}
Jiri Pirko April 13, 2024, 1:29 p.m. UTC | #2
Fri, Apr 12, 2024 at 10:43:40PM CEST, benjamin.poirier@gmail.com wrote:
>On 2024-04-12 17:13 +0200, Jiri Pirko wrote:
>> From: Jiri Pirko <jiri@nvidia.com>
>> 
>> The existing setup_wait*() helper family check the status of the
>> interface to be up. Introduce wait_for_dev() to wait for the netdevice
>> to appear, for example after test script does manual device bind.
>> 
>> Signed-off-by: Jiri Pirko <jiri@nvidia.com>
>> ---
>>  tools/testing/selftests/net/forwarding/lib.sh | 19 +++++++++++++++++++
>>  1 file changed, 19 insertions(+)
>> 
>> diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
>> index 959183b516ce..74859f969997 100644
>> --- a/tools/testing/selftests/net/forwarding/lib.sh
>> +++ b/tools/testing/selftests/net/forwarding/lib.sh
>> @@ -746,6 +746,25 @@ setup_wait()
>>  	sleep $WAIT_TIME
>>  }
>>  
>> +wait_for_dev()
>> +{
>> +	local dev=$1; shift
>> +	local timeout=${1:-$WAIT_TIMEOUT}; shift
>> +	local max_iterations=$(($timeout * 10))
>> +
>> +	for ((i = 1; i <= $max_iterations; ++i)); do
>> +		ip link show dev $dev up &> /dev/null
>> +		if [[ $? -ne 0 ]]; then
>> +			sleep 0.1
>> +		else
>> +			return 0
>> +		fi
>> +	done
>> +
>> +	log_test wait_for_dev ": Interface $dev did not appear."
>> +	exit 1
>> +}
>
>How about rewriting the function to make use of the `slowwait` helper as
>follows:
>
>wait_for_dev()
>{
>	local dev=$1; shift
>	local timeout=${1:-$WAIT_TIMEOUT}; shift
>
>	slowwait $timeout ip link show dev $dev up &> /dev/null
>	if (( $? )); then
>		check_err 1
>		log_test wait_for_dev "Interface $dev did not appear."
>		exit $EXIT_STATUS
>	fi
>}

Sure, will redo this. Thanks!
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 959183b516ce..74859f969997 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -746,6 +746,25 @@  setup_wait()
 	sleep $WAIT_TIME
 }
 
+wait_for_dev()
+{
+	local dev=$1; shift
+	local timeout=${1:-$WAIT_TIMEOUT}; shift
+	local max_iterations=$(($timeout * 10))
+
+	for ((i = 1; i <= $max_iterations; ++i)); do
+		ip link show dev $dev up &> /dev/null
+		if [[ $? -ne 0 ]]; then
+			sleep 0.1
+		else
+			return 0
+		fi
+	done
+
+	log_test wait_for_dev ": Interface $dev did not appear."
+	exit 1
+}
+
 cmd_jq()
 {
 	local cmd=$1