[PATCH mptcp-net 08/13] selftests: mptcp: lib: skip if missing symbol

Matthieu Baerts posted 13 patches 2 years, 10 months ago
Maintainers: Matthieu Baerts <matthieu.baerts@tessares.net>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Shuah Khan <shuah@kernel.org>, Florian Westphal <fw@strlen.de>, Christoph Paasch <cpaasch@apple.com>, Mat Martineau <mathew.j.martineau@linux.intel.com>, Kishen Maloor <kishen.maloor@intel.com>, Dmytro Shytyi <dmytro@shytyi.net>, Geliang Tang <geliang.tang@suse.com>
There is a newer version of this series
[PATCH mptcp-net 08/13] selftests: mptcp: lib: skip if missing symbol
Posted by Matthieu Baerts 2 years, 10 months ago
Selftests are supposed to run on any kernels, including the old ones not
supporting all MPTCP features.

New functions are now available to easily detect if a feature is
missing. It is going to be used in the following commits. In order to
ease the backport of such future patches, it would be good if this
present commit is backported up to the introduction of MPTCP selftests,
hence the Fixes tag below: this type of check was supposed to be done
from the beginning.

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/368
Fixes: 048d19d444be ("mptcp: add basic kselftest for mptcp")
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
---
 tools/testing/selftests/net/mptcp/config       |  1 +
 tools/testing/selftests/net/mptcp/mptcp_lib.sh | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/tools/testing/selftests/net/mptcp/config b/tools/testing/selftests/net/mptcp/config
index 38021a0dd527..6032f9b23c4c 100644
--- a/tools/testing/selftests/net/mptcp/config
+++ b/tools/testing/selftests/net/mptcp/config
@@ -1,3 +1,4 @@
+CONFIG_KALLSYMS=y
 CONFIG_MPTCP=y
 CONFIG_IPV6=y
 CONFIG_MPTCP_IPV6=y
diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
index eb0feb76e2ab..c84eb40abd1f 100644
--- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh
+++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh
@@ -1,6 +1,7 @@
 #! /bin/bash
 # SPDX-License-Identifier: GPL-2.0
 
+readonly KSFT_FAIL=1
 readonly KSFT_SKIP=4
 
 mptcp_lib_check_mptcp() {
@@ -9,3 +10,25 @@ mptcp_lib_check_mptcp() {
 		exit ${KSFT_SKIP}
 	fi
 }
+
+mptcp_lib_check_kallsyms() {
+	if [ ! -f /proc/kallsyms ]; then
+		echo "SKIP: CONFIG_KALLSYMS is missing"
+		exit ${KSFT_SKIP}
+	fi
+}
+
+# $1: part of a symbol to look at, add '$' at the end for full name
+mptcp_lib_kallsyms_has() {
+	local sym="${1}"
+
+	if ! grep -q " ${sym}" /proc/kallsyms; then
+		# We want our CI to complain if a symbol is not found
+		if [ "${SELFTESTS_MPTCP_LIB_EXTRA_CHECKS:-}" = "1" ]; then
+			echo "ERROR: ${sym} symbol has not been found"
+			exit ${KSFT_FAIL}
+		fi
+
+		return 1
+	fi
+}

-- 
2.39.2