[PATCH mptcp-next] selftests: mptcp: info: hide 'grep: write error' warnings

Matthieu Baerts (NGI0) posted 1 patch 8 months, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/20250410-selftests-mptcp-grep-close-v1-1-3c360279a856@kernel.org
tools/testing/selftests/net/mptcp/mptcp_lib.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
[PATCH mptcp-next] selftests: mptcp: info: hide 'grep: write error' warnings
Posted by Matthieu Baerts (NGI0) 8 months, 1 week ago
mptcp_lib_get_info_value() will only print the first entry that match
the filter because of the ';q' at the end. As a consequence, the 'sed'
command could finish before the previous 'grep' one and print a 'write
error' warning because it is trying to write data to the closed pipe.

Such warnings are not interesting, they can be hidden by muting stderr
here for grep.

While at it, clearly indicate that mptcp_lib_get_info_value() will only
print the first matched entry to avoid confusions later on.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 tools/testing/selftests/net/mptcp/mptcp_lib.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index 051e289d79676c5feb9f46da67a08116548f4b47..99c87cd6e25563e220263c813223206ef6f4b311 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -331,12 +331,15 @@ mptcp_lib_result_print_all_tap() {
 
 # get the value of keyword $1 in the line marked by keyword $2
 mptcp_lib_get_info_value() {
-	grep "${2}" | sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q'
+	grep "${2}" 2>/dev/null |
+		sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q'
+		# the ';q' at the end limits to the first matched entry.
 }
 
 # $1: info name ; $2: evts_ns ; [$3: event type; [$4: addr]]
 mptcp_lib_evts_get_info() {
-	grep "${4:-}" "${2}" | mptcp_lib_get_info_value "${1}" "^type:${3:-1},"
+	grep "${4:-}" "${2}" 2>/dev/null |
+		mptcp_lib_get_info_value "${1}" "^type:${3:-1},"
 }
 
 # $1: PID

---
base-commit: 244c301d3de6bf2e1bdc5cf7291159cd8e342942
change-id: 20250410-selftests-mptcp-grep-close-9e4ac9b41a94

Best regards,
-- 
Matthieu Baerts (NGI0) <matttbe@kernel.org>
Re: [PATCH mptcp-next] selftests: mptcp: info: hide 'grep: write error' warnings
Posted by Mat Martineau 8 months, 1 week ago
On Thu, 10 Apr 2025, Matthieu Baerts (NGI0) wrote:

> mptcp_lib_get_info_value() will only print the first entry that match
> the filter because of the ';q' at the end. As a consequence, the 'sed'
> command could finish before the previous 'grep' one and print a 'write
> error' warning because it is trying to write data to the closed pipe.
>
> Such warnings are not interesting, they can be hidden by muting stderr
> here for grep.
>
> While at it, clearly indicate that mptcp_lib_get_info_value() will only
> print the first matched entry to avoid confusions later on.
>
> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>

Hi Matthieu -

Looks good to me:

Reviewed-by: Mat Martineau <martineau@kernel.org>

> ---
> tools/testing/selftests/net/mptcp/mptcp_lib.sh | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> index 051e289d79676c5feb9f46da67a08116548f4b47..99c87cd6e25563e220263c813223206ef6f4b311 100644
> --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
> @@ -331,12 +331,15 @@ mptcp_lib_result_print_all_tap() {
>
> # get the value of keyword $1 in the line marked by keyword $2
> mptcp_lib_get_info_value() {
> -	grep "${2}" | sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q'
> +	grep "${2}" 2>/dev/null |
> +		sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q'
> +		# the ';q' at the end limits to the first matched entry.
> }
>
> # $1: info name ; $2: evts_ns ; [$3: event type; [$4: addr]]
> mptcp_lib_evts_get_info() {
> -	grep "${4:-}" "${2}" | mptcp_lib_get_info_value "${1}" "^type:${3:-1},"
> +	grep "${4:-}" "${2}" 2>/dev/null |
> +		mptcp_lib_get_info_value "${1}" "^type:${3:-1},"
> }
>
> # $1: PID
>
> ---
> base-commit: 244c301d3de6bf2e1bdc5cf7291159cd8e342942
> change-id: 20250410-selftests-mptcp-grep-close-9e4ac9b41a94
>
> Best regards,
> -- 
> Matthieu Baerts (NGI0) <matttbe@kernel.org>
>
>
>
Re: [PATCH mptcp-next] selftests: mptcp: info: hide 'grep: write error' warnings
Posted by Matthieu Baerts 8 months, 1 week ago
Hi Mat,

On 12/04/2025 02:06, Mat Martineau wrote:
> On Thu, 10 Apr 2025, Matthieu Baerts (NGI0) wrote:
> 
>> mptcp_lib_get_info_value() will only print the first entry that match
>> the filter because of the ';q' at the end. As a consequence, the 'sed'
>> command could finish before the previous 'grep' one and print a 'write
>> error' warning because it is trying to write data to the closed pipe.
>>
>> Such warnings are not interesting, they can be hidden by muting stderr
>> here for grep.
>>
>> While at it, clearly indicate that mptcp_lib_get_info_value() will only
>> print the first matched entry to avoid confusions later on.
>>
>> Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
> 
> Hi Matthieu -
> 
> Looks good to me:
> 
> Reviewed-by: Mat Martineau <martineau@kernel.org>

Thank you for the review, now in our tree (feat. for next):

New patches for t/upstream:
- 2c2fc8bfbe27: selftests: mptcp: info: hide 'grep: write error' warnings
- Results: 008c13709fce..f1e32c11be27 (export)

Tests are now in progress:

- export:
https://github.com/multipath-tcp/mptcp_net-next/commit/b802c3e109fa6c57925267d8da01cdbc27eaa181/checks

Cheers,
Matt
-- 
Sponsored by the NGI0 Core fund.