All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH mptcp-next v2] selftests: mptcp: add invert check in check_transfer
@ 2022-01-16  7:22 Geliang Tang
  2022-01-19  0:20 ` Mat Martineau
  0 siblings, 1 reply; 2+ messages in thread
From: Geliang Tang @ 2022-01-16  7:22 UTC (permalink / raw)
  To: mptcp; +Cc: Geliang Tang

This patch added the invert bytes check for the output data in
check_transfer().

Instead of the file mismatch error:

  [ FAIL ] file received by server does not match (in, out):
  -rw------- 1 root root 45643832 Jan 16 15:04 /tmp/tmp.9xpM6Paivv
  Trailing bytes are:
  MPTCP_TEST_FILE_END_MARKER
  -rw------- 1 root root 45643832 Jan 16 15:04 /tmp/tmp.wnz1Yp4u7Z
  Trailing bytes are:
  MPTCP_TEST_FILE_END_MARKER

Print out the inverted bytes like this:

  file received by server has inverted bytes at 7454789 (in, out)
  file received by server has inverted bytes at 7454790 (in, out)
  file received by server has inverted bytes at 7454791 (in, out)
  file received by server has inverted bytes at 7454792 (in, out)

Signed-off-by: Geliang Tang <geliang.tang@suse.com>
---
 v2:
 - instead of adding a new function is_invert, add the invert bytes
   check in check_transfer().
---
 .../testing/selftests/net/mptcp/mptcp_join.sh | 23 ++++++++++++-------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
index 2be3cad4b52b..de6589d1c541 100755
--- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
@@ -193,15 +193,22 @@ check_transfer()
 	out=$2
 	what=$3
 
-	cmp "$in" "$out" > /dev/null 2>&1
-	if [ $? -ne 0 ] ;then
-		echo "[ FAIL ] $what does not match (in, out):"
-		print_file_err "$in"
-		print_file_err "$out"
-		ret=1
+	cmp -l "$in" "$out" | while read line; do
+		local arr=($line)
+
+		let sum=${arr[1]}+${arr[2]}
+		# Octal 377 is 0xFF
+		if [ $sum -ne 377 ]; then
+			echo "[ FAIL ] $what does not match (in, out):"
+			print_file_err "$in"
+			print_file_err "$out"
+			ret=1
 
-		return 1
-	fi
+			return 1
+		else
+			echo "$what has inverted bytes at ${arr[0]} (in, out)"
+		fi
+	done
 
 	return 0
 }
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH mptcp-next v2] selftests: mptcp: add invert check in check_transfer
  2022-01-16  7:22 [PATCH mptcp-next v2] selftests: mptcp: add invert check in check_transfer Geliang Tang
@ 2022-01-19  0:20 ` Mat Martineau
  0 siblings, 0 replies; 2+ messages in thread
From: Mat Martineau @ 2022-01-19  0:20 UTC (permalink / raw)
  To: Geliang Tang; +Cc: mptcp

On Sun, 16 Jan 2022, Geliang Tang wrote:

> This patch added the invert bytes check for the output data in
> check_transfer().
>
> Instead of the file mismatch error:
>
>  [ FAIL ] file received by server does not match (in, out):
>  -rw------- 1 root root 45643832 Jan 16 15:04 /tmp/tmp.9xpM6Paivv
>  Trailing bytes are:
>  MPTCP_TEST_FILE_END_MARKER
>  -rw------- 1 root root 45643832 Jan 16 15:04 /tmp/tmp.wnz1Yp4u7Z
>  Trailing bytes are:
>  MPTCP_TEST_FILE_END_MARKER
>
> Print out the inverted bytes like this:
>
>  file received by server has inverted bytes at 7454789 (in, out)
>  file received by server has inverted bytes at 7454790 (in, out)
>  file received by server has inverted bytes at 7454791 (in, out)
>  file received by server has inverted bytes at 7454792 (in, out)
>

Thanks Geliang! This is really close to what I was looking for. Can you 
also make sure the bit flips are only allowed in the few tests where they 
are expected?

> Signed-off-by: Geliang Tang <geliang.tang@suse.com>
> ---
> v2:
> - instead of adding a new function is_invert, add the invert bytes
>   check in check_transfer().
> ---
> .../testing/selftests/net/mptcp/mptcp_join.sh | 23 ++++++++++++-------
> 1 file changed, 15 insertions(+), 8 deletions(-)
>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_join.sh b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> index 2be3cad4b52b..de6589d1c541 100755
> --- a/tools/testing/selftests/net/mptcp/mptcp_join.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_join.sh
> @@ -193,15 +193,22 @@ check_transfer()
> 	out=$2
> 	what=$3
>
> -	cmp "$in" "$out" > /dev/null 2>&1
> -	if [ $? -ne 0 ] ;then
> -		echo "[ FAIL ] $what does not match (in, out):"
> -		print_file_err "$in"
> -		print_file_err "$out"
> -		ret=1
> +	cmp -l "$in" "$out" | while read line; do
> +		local arr=($line)
> +
> +		let sum=${arr[1]}+${arr[2]}

bash is interpreting the values as decimal here, would be best to 
interpret them as octal by adding a leading '0' to each value:

let sum=0${arr[1]}+0${arr[2]}

> +		# Octal 377 is 0xFF
> +		if [ $sum -ne 377 ]; then

Can also change this to use hexadecimal directly:

if [ $sum -ne $((0xff)) ]; then


> +			echo "[ FAIL ] $what does not match (in, out):"
> +			print_file_err "$in"
> +			print_file_err "$out"
> +			ret=1
>
> -		return 1
> -	fi
> +			return 1
> +		else
> +			echo "$what has inverted bytes at ${arr[0]} (in, out)"

What's the meaning of "(in, out)" here?


-Mat

> +		fi
> +	done
>
> 	return 0
> }
> -- 
> 2.31.1
>
>
>

--
Mat Martineau
Intel

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-19  0:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-16  7:22 [PATCH mptcp-next v2] selftests: mptcp: add invert check in check_transfer Geliang Tang
2022-01-19  0:20 ` Mat Martineau

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.