[PATCH mptcp-net 3/3] selftests: mptcp: print trailing bytes with hexdump

Matthieu Baerts (NGI0) posted 3 patches 4 weeks, 1 day ago
There is a newer version of this series
[PATCH mptcp-net 3/3] selftests: mptcp: print trailing bytes with hexdump
Posted by Matthieu Baerts (NGI0) 4 weeks, 1 day ago
If hexdump or busybox hexdump is available.

This is better than printing random bytes in the terminal.

Suggested-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 tools/testing/selftests/net/mptcp/mptcp_lib.sh | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index 09cd24b2ae466205dacbdf8289eb86c08534c475..20ce95c9d35538a03c1c3cac843657d258fc9715 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -382,9 +382,19 @@ mptcp_lib_make_file() {
 
 # $1: file
 mptcp_lib_print_file_err() {
+	local end
+
 	ls -l "${1}" 1>&2
 	echo "Trailing bytes are: "
-	tail -c 27 "${1}"
+	end=$(tail -c 32 "${1}")
+	if command -v hexdump >/dev/null; then
+		echo "${end}" | hexdump -C | head -n2
+	elif busybox hexdump --help 2>/dev/null; then
+		echo "${end}" | busybox hexdump -C | head -n2
+	else
+		echo "${end}"
+		echo
+	fi
 }
 
 # $1: input file ; $2: output file ; $3: what kind of file

-- 
2.50.0
Re: [PATCH mptcp-net 3/3] selftests: mptcp: print trailing bytes with hexdump
Posted by Mat Martineau 3 weeks, 5 days ago
On Tue, 19 Aug 2025, Matthieu Baerts (NGI0) wrote:

> If hexdump or busybox hexdump is available.
>
> This is better than printing random bytes in the terminal.
>
> Suggested-by: Jakub Kicinski <kuba@kernel.org>
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> ---
> tools/testing/selftests/net/mptcp/mptcp_lib.sh | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index 09cd24b2ae466205dacbdf8289eb86c08534c475..20ce95c9d35538a03c1c3cac843657d258fc9715 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -382,9 +382,19 @@ mptcp_lib_make_file() {
>
> # $1: file
> mptcp_lib_print_file_err() {
> +	local end
> +
> 	ls -l "${1}" 1>&2
> 	echo "Trailing bytes are: "
> -	tail -c 27 "${1}"
> +	end=$(tail -c 32 "${1}")
> +	if command -v hexdump >/dev/null; then

Hi Matthieu -

How about:

tail -c 32 "${1}" | od -t x1

'od' is in the posix spec so it should be on more systems than hexdump 
(it's in coreutils along with 'tail', for example). Also, today I learned 
that 'od' can format hexadecimal...


> +		echo "${end}" | hexdump -C | head -n2
> +	elif busybox hexdump --help 2>/dev/null; then
> +		echo "${end}" | busybox hexdump -C | head -n2
> +	else
> +		echo "${end}"

Would be best to avoid fallback to raw binary (hence the 'od' suggestion 
above).

- Mat


> +		echo
> +	fi
> }
>
> # $1: input file ; $2: output file ; $3: what kind of file
>
> -- 
> 2.50.0
>
>
>