Skip to content

Commit d83013b

Browse files
matttbePaolo Abeni
authored andcommitted
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: multipath-tcp/mptcp_net-next#368 Fixes: 048d19d ("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>
1 parent d328fe8 commit d83013b

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

tools/testing/selftests/net/mptcp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh \
99

1010
TEST_GEN_FILES = mptcp_connect pm_nl_ctl mptcp_sockopt mptcp_inq
1111

12-
TEST_FILES := settings
12+
TEST_FILES := mptcp_lib.sh settings
1313

1414
EXTRA_CLEAN := *.pcap
1515

tools/testing/selftests/net/mptcp/mptcp_connect.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4+
. "$(dirname "${0}")/mptcp_lib.sh"
5+
46
time_start=$(date +%s)
57

68
optstring="S:R:d:e:l:r:h4cm:f:tC"
@@ -141,6 +143,8 @@ cleanup()
141143
done
142144
}
143145

146+
mptcp_lib_check_mptcp
147+
144148
ip -Version > /dev/null 2>&1
145149
if [ $? -ne 0 ];then
146150
echo "SKIP: Could not run test without ip tool"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

0 commit comments

Comments
 (0)