Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: mptcp: connect: skip if MPTCP is not supported

Selftests are supposed to run on any kernels, including the old ones not
supporting MPTCP.

A new check is then added to make sure MPTCP is supported. If not, the
test stops and is marked as "skipped". Note that this check can also
mark the test as failed if 'SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES' env
var is set to 1: by doing that, we can make sure a test is not being
skipped by mistake.

A new shared file is added here to be able to re-used the same check in
the different selftests we have.

Link: https://github.com/multipath-tcp/mptcp_net-next/issues/368
Fixes: 048d19d444be ("mptcp: add basic kselftest for mptcp")
Cc: stable@vger.kernel.org
Acked-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Matthieu Baerts <matthieu.baerts@tessares.net>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Matthieu Baerts and committed by
Paolo Abeni
d83013bd d328fe87

+45 -1
+1 -1
tools/testing/selftests/net/mptcp/Makefile
··· 9 9 10 10 TEST_GEN_FILES = mptcp_connect pm_nl_ctl mptcp_sockopt mptcp_inq 11 11 12 - TEST_FILES := settings 12 + TEST_FILES := mptcp_lib.sh settings 13 13 14 14 EXTRA_CLEAN := *.pcap 15 15
+4
tools/testing/selftests/net/mptcp/mptcp_connect.sh
··· 1 1 #!/bin/bash 2 2 # SPDX-License-Identifier: GPL-2.0 3 3 4 + . "$(dirname "${0}")/mptcp_lib.sh" 5 + 4 6 time_start=$(date +%s) 5 7 6 8 optstring="S:R:d:e:l:r:h4cm:f:tC" ··· 142 140 rm -f /tmp/$netns.{nstat,out} 143 141 done 144 142 } 143 + 144 + mptcp_lib_check_mptcp 145 145 146 146 ip -Version > /dev/null 2>&1 147 147 if [ $? -ne 0 ];then
+40
tools/testing/selftests/net/mptcp/mptcp_lib.sh
··· 1 + #! /bin/bash 2 + # SPDX-License-Identifier: GPL-2.0 3 + 4 + readonly KSFT_FAIL=1 5 + readonly KSFT_SKIP=4 6 + 7 + # SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES env var can be set when validating all 8 + # features using the last version of the kernel and the selftests to make sure 9 + # a test is not being skipped by mistake. 10 + mptcp_lib_expect_all_features() { 11 + [ "${SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES:-}" = "1" ] 12 + } 13 + 14 + # $1: msg 15 + mptcp_lib_fail_if_expected_feature() { 16 + if mptcp_lib_expect_all_features; then 17 + echo "ERROR: missing feature: ${*}" 18 + exit ${KSFT_FAIL} 19 + fi 20 + 21 + return 1 22 + } 23 + 24 + # $1: file 25 + mptcp_lib_has_file() { 26 + local f="${1}" 27 + 28 + if [ -f "${f}" ]; then 29 + return 0 30 + fi 31 + 32 + mptcp_lib_fail_if_expected_feature "${f} file not found" 33 + } 34 + 35 + mptcp_lib_check_mptcp() { 36 + if ! mptcp_lib_has_file "/proc/sys/net/mptcp/enabled"; then 37 + echo "SKIP: MPTCP support is not available" 38 + exit ${KSFT_SKIP} 39 + fi 40 + }