summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/net/mptcp/mptcp_lib.sh
diff options
context:
space:
mode:
authorGeliang Tang <tanggeliang@kylinos.cn>2024-03-01 21:18:33 +0300
committerDavid S. Miller <davem@davemloft.net>2024-03-04 16:07:46 +0300
commit2d0c1d27ea4eced07bd841d1cfccb838b437dfae (patch)
tree4d0d1af6decae3347c918f9852ac490c7a8d453d /tools/testing/selftests/net/mptcp/mptcp_lib.sh
parent950c332125f66d7419a24fc933f05606ae199b40 (diff)
downloadlinux-2d0c1d27ea4eced07bd841d1cfccb838b437dfae.tar.xz
selftests: mptcp: add mptcp_lib_check_output helper
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> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/testing/selftests/net/mptcp/mptcp_lib.sh')
-rw-r--r--tools/testing/selftests/net/mptcp/mptcp_lib.sh23
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index 108a1e12436c..438f557aac90 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -319,3 +319,26 @@ mptcp_lib_wait_local_port_listen() {
sleep 0.1
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
+}