diff mbox

[PATCHv2] validation: pktio: prevent race when using veth pair

Message ID 1426508863-20529-1-git-send-email-stuart.haslam@linaro.org
State Accepted
Commit 678923038507d20e7509fdcffb33ab79ab055602
Headers show

Commit Message

Stuart Haslam March 16, 2015, 12:27 p.m. UTC
There's a potential race condition whereby the test case could start
running before the virtual ethernet interfaces are fully brought up.
So replace the the arbitrary delay with a check for the interface's
operational state before kicking off the test.

Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
---
Changes in v2; rebased and fixed non-POSIX shell arithmetic expansion

 test/validation/odp_pktio_run | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

Comments

Maxim Uvarov March 16, 2015, 12:35 p.m. UTC | #1
For me that version works good.
Thanks,
Maxim.

On 03/16/15 15:27, Stuart Haslam wrote:
> There's a potential race condition whereby the test case could start
> running before the virtual ethernet interfaces are fully brought up.
> So replace the the arbitrary delay with a check for the interface's
> operational state before kicking off the test.
>
> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
> ---
> Changes in v2; rebased and fixed non-POSIX shell arithmetic expansion
>
>   test/validation/odp_pktio_run | 32 ++++++++++++++++++++++++++++++--
>   1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/test/validation/odp_pktio_run b/test/validation/odp_pktio_run
> index 6177caa..204b440 100755
> --- a/test/validation/odp_pktio_run
> +++ b/test/validation/odp_pktio_run
> @@ -34,6 +34,28 @@ IF1=pktio-p1
>   # exit codes expected by automake for skipped tests
>   TEST_SKIPPED=77
>   
> +# wait for a network interface's operational state to be "up"
> +wait_for_iface_up()
> +{
> +	iface=$1
> +	cnt=0
> +
> +	while [ $cnt -lt 50 ]; do
> +		read operstate < /sys/class/net/$iface/operstate
> +
> +		if [ $? != 0 ]; then
> +			break
> +		elif [ "$operstate" = "up" ]; then
> +			return 0
> +		fi
> +
> +		sleep 0.1
> +		cnt=`expr $cnt + 1`
> +	done
> +
> +	return 1
> +}
> +
>   setup_env1()
>   {
>   	ip link show $IF0 2> /dev/null
> @@ -61,8 +83,14 @@ setup_env1()
>   	ifconfig $IF0 -arp
>   	ifconfig $IF1 -arp
>   
> -	# network needs a little time to come up
> -	sleep 1
> +	# check that the interface has come up before starting the test
> +	for iface in $IF0 $IF1; do
> +		wait_for_iface_up $iface
> +		if [ $? != 0 ]; then
> +			echo "pktio: interface $iface failed to come up"
> +			exit 1
> +		fi
> +	done
>   }
>   
>   cleanup_env1()
Maxim Uvarov March 17, 2015, 10:10 a.m. UTC | #2
Merged,
Maxim.

On 03/16/15 15:27, Stuart Haslam wrote:
> There's a potential race condition whereby the test case could start
> running before the virtual ethernet interfaces are fully brought up.
> So replace the the arbitrary delay with a check for the interface's
> operational state before kicking off the test.
>
> Signed-off-by: Stuart Haslam <stuart.haslam@linaro.org>
> ---
> Changes in v2; rebased and fixed non-POSIX shell arithmetic expansion
>
>   test/validation/odp_pktio_run | 32 ++++++++++++++++++++++++++++++--
>   1 file changed, 30 insertions(+), 2 deletions(-)
>
> diff --git a/test/validation/odp_pktio_run b/test/validation/odp_pktio_run
> index 6177caa..204b440 100755
> --- a/test/validation/odp_pktio_run
> +++ b/test/validation/odp_pktio_run
> @@ -34,6 +34,28 @@ IF1=pktio-p1
>   # exit codes expected by automake for skipped tests
>   TEST_SKIPPED=77
>   
> +# wait for a network interface's operational state to be "up"
> +wait_for_iface_up()
> +{
> +	iface=$1
> +	cnt=0
> +
> +	while [ $cnt -lt 50 ]; do
> +		read operstate < /sys/class/net/$iface/operstate
> +
> +		if [ $? != 0 ]; then
> +			break
> +		elif [ "$operstate" = "up" ]; then
> +			return 0
> +		fi
> +
> +		sleep 0.1
> +		cnt=`expr $cnt + 1`
> +	done
> +
> +	return 1
> +}
> +
>   setup_env1()
>   {
>   	ip link show $IF0 2> /dev/null
> @@ -61,8 +83,14 @@ setup_env1()
>   	ifconfig $IF0 -arp
>   	ifconfig $IF1 -arp
>   
> -	# network needs a little time to come up
> -	sleep 1
> +	# check that the interface has come up before starting the test
> +	for iface in $IF0 $IF1; do
> +		wait_for_iface_up $iface
> +		if [ $? != 0 ]; then
> +			echo "pktio: interface $iface failed to come up"
> +			exit 1
> +		fi
> +	done
>   }
>   
>   cleanup_env1()
diff mbox

Patch

diff --git a/test/validation/odp_pktio_run b/test/validation/odp_pktio_run
index 6177caa..204b440 100755
--- a/test/validation/odp_pktio_run
+++ b/test/validation/odp_pktio_run
@@ -34,6 +34,28 @@  IF1=pktio-p1
 # exit codes expected by automake for skipped tests
 TEST_SKIPPED=77
 
+# wait for a network interface's operational state to be "up"
+wait_for_iface_up()
+{
+	iface=$1
+	cnt=0
+
+	while [ $cnt -lt 50 ]; do
+		read operstate < /sys/class/net/$iface/operstate
+
+		if [ $? != 0 ]; then
+			break
+		elif [ "$operstate" = "up" ]; then
+			return 0
+		fi
+
+		sleep 0.1
+		cnt=`expr $cnt + 1`
+	done
+
+	return 1
+}
+
 setup_env1()
 {
 	ip link show $IF0 2> /dev/null
@@ -61,8 +83,14 @@  setup_env1()
 	ifconfig $IF0 -arp
 	ifconfig $IF1 -arp
 
-	# network needs a little time to come up
-	sleep 1
+	# check that the interface has come up before starting the test
+	for iface in $IF0 $IF1; do
+		wait_for_iface_up $iface
+		if [ $? != 0 ]; then
+			echo "pktio: interface $iface failed to come up"
+			exit 1
+		fi
+	done
 }
 
 cleanup_env1()