[PATCH net-next 03/13] selftests: mptcp: add mptcp_lib_check_output helper

Matthieu Baerts (NGI0) posted 13 patches 1 year, 11 months ago
There is a newer version of this series
[PATCH net-next 03/13] selftests: mptcp: add mptcp_lib_check_output helper
Posted by Matthieu Baerts (NGI0) 1 year, 11 months ago
From: Geliang Tang <tanggeliang@kylinos.cn>

Extract the main part of check() in pm_netlink.sh into a new helper
named mptcp_lib_check_output in mptcp_lib.sh.

This helper will be used for userspace dump addresses tests.

Co-developed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 tools/testing/selftests/net/mptcp/mptcp_lib.sh | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index b1fe354cfe96..ed86bb0bab49 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -373,3 +373,26 @@ mptcp_lib_check_tools() {
 		esac
 	done
 }
+
+mptcp_lib_check_output() {
+	local err="${1}"
+	local cmd="${2}"
+	local expected="${3}"
+	local cmd_ret=0
+	local out
+
+	if ! out=$(${cmd} 2>"${err}"); then
+		cmd_ret=${?}
+	fi
+
+	if [ ${cmd_ret} -ne 0 ]; then
+		mptcp_lib_print_err "[FAIL] command execution '${cmd}' stderr"
+		cat "${err}"
+		return 2
+	elif [ "${out}" = "${expected}" ]; then
+		return 0
+	else
+		mptcp_lib_print_err "[FAIL] expected '${expected}' got '${out}'"
+		return 1
+	fi
+}

-- 
2.43.0
Re: [PATCH net-next 03/13] selftests: mptcp: add mptcp_lib_check_output helper
Posted by Matthieu Baerts 1 year, 11 months ago
Hello,

On 05/03/2024 11:42, Matthieu Baerts (NGI0) wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Extract the main part of check() in pm_netlink.sh into a new helper
> named mptcp_lib_check_output in mptcp_lib.sh.
> 
> This helper will be used for userspace dump addresses tests.

Arf, I just noticed that when the MPTCP tree got rebased on top of
net-next, Git didn't drop this patch, but resolved the conflicts by
duplicating mptcp_lib_check_output() function. Of course, redefining the
function is OK in Bash, and I didn't notice the issue when running the
tests...

I will resend this series without this patch tomorrow.

Sorry for the noise :-/

pw-bot: changes-requested

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