Skip to content

Commit

Permalink
Merge branch 'selftests-mptcp-skip-tests-not-supported-by-old-kernels…
Browse files Browse the repository at this point in the history
…-part-1'

Matthieu Baerts says:

====================
selftests: mptcp: skip tests not supported by old kernels (part 1)

After a few years of increasing test coverage in the MPTCP selftests, we
realised [1] the last version of the selftests is supposed to run on old
kernels without issues.

Supporting older versions is not that easy for this MPTCP case: these
selftests are often validating the internals by checking packets that
are exchanged, when some MIB counters are incremented after some
actions, how connections are getting opened and closed in some cases,
etc. In other words, it is not limited to the socket interface between
the userspace and the kernelspace. In addition, the current selftests
run a lot of different sub-tests but the TAP13 protocol used in the
selftests don't support sub-tests: in other words, one failure in
sub-tests implies that the whole selftest is seen as failed at the end
because sub-tests are not tracked. It is then important to skip
sub-tests not supported by old kernels.

To minimise the modifications and reduce the complexity to support old
versions, the idea is to look at external signs and skip the whole
selftests or just some sub-tests before starting them.

This first part focuses on marking the different selftests as skipped
if MPTCP is not even supported. That's what is done in patches 2 to 8.
Patch 2/8 introduces a new file (mptcp_lib.sh) to be able to re-use some
helpers in the different selftests. The first MPTCP selftest has been
introduced in v5.6.

Patch 1/8 is a bit different but still linked: it modifies mptcp_join.sh
selftest not to use 'cmp --bytes' which is not supported by the BusyBox
implementation. It is apparently quite common to use BusyBox in CI
environments. This tool is needed for a subtest introduced in v6.1.

Link: https://lore.kernel.org/stable/CA+G9fYtDGpgT4dckXD-y-N92nqUxuvue_7AtDdBcHrbOMsDZLg@mail.gmail.com/ [1]
Link: multipath-tcp/mptcp_net-next#368
====================

Link: https://lore.kernel.org/r/20230528-upstream-net-20230528-mptcp-selftests-support-old-kernels-part-1-v1-0-a32d85577fc6@tessares.net
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
Paolo Abeni committed May 30, 2023
2 parents 1919b39 + 6321260 commit 7ba0732
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tools/testing/selftests/net/mptcp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ TEST_PROGS := mptcp_connect.sh pm_netlink.sh mptcp_join.sh diag.sh \

TEST_GEN_FILES = mptcp_connect pm_nl_ctl mptcp_sockopt mptcp_inq

TEST_FILES := settings
TEST_FILES := mptcp_lib.sh settings

EXTRA_CLEAN := *.pcap

Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/net/mptcp/diag.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(dirname "${0}")/mptcp_lib.sh"

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns="ns1-$rndh"
Expand Down Expand Up @@ -31,6 +33,8 @@ cleanup()
ip netns del $ns
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_connect.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(dirname "${0}")/mptcp_lib.sh"

time_start=$(date +%s)

optstring="S:R:d:e:l:r:h4cm:f:tC"
Expand Down Expand Up @@ -141,6 +143,8 @@ cleanup()
done
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
Expand Down
17 changes: 15 additions & 2 deletions tools/testing/selftests/net/mptcp/mptcp_join.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
# because it's invoked by variable name, see how the "tests" array is used
#shellcheck disable=SC2317

. "$(dirname "${0}")/mptcp_lib.sh"

ret=0
sin=""
sinfail=""
sout=""
cin=""
cinfail=""
cinsent=""
tmpfile=""
cout=""
capout=""
ns1=""
Expand Down Expand Up @@ -136,6 +139,8 @@ cleanup_partial()

check_tools()
{
mptcp_lib_check_mptcp

if ! ip -Version &> /dev/null; then
echo "SKIP: Could not run test without ip tool"
exit $ksft_skip
Expand Down Expand Up @@ -175,6 +180,7 @@ cleanup()
{
rm -f "$cin" "$cout" "$sinfail"
rm -f "$sin" "$sout" "$cinsent" "$cinfail"
rm -f "$tmpfile"
rm -rf $evts_ns1 $evts_ns2
cleanup_partial
}
Expand Down Expand Up @@ -383,9 +389,16 @@ check_transfer()
fail_test
return 1
fi
bytes="--bytes=${bytes}"

# note: BusyBox's "cmp" command doesn't support --bytes
tmpfile=$(mktemp)
head --bytes="$bytes" "$in" > "$tmpfile"
mv "$tmpfile" "$in"
head --bytes="$bytes" "$out" > "$tmpfile"
mv "$tmpfile" "$out"
tmpfile=""
fi
cmp -l "$in" "$out" ${bytes} | while read -r i a b; do
cmp -l "$in" "$out" | while read -r i a b; do
local sum=$((0${a} + 0${b}))
if [ $check_invert -eq 0 ] || [ $sum -ne $((0xff)) ]; then
echo "[ FAIL ] $what does not match (in, out):"
Expand Down
40 changes: 40 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_lib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0

readonly KSFT_FAIL=1
readonly KSFT_SKIP=4

# SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES env var can be set when validating all
# features using the last version of the kernel and the selftests to make sure
# a test is not being skipped by mistake.
mptcp_lib_expect_all_features() {
[ "${SELFTESTS_MPTCP_LIB_EXPECT_ALL_FEATURES:-}" = "1" ]
}

# $1: msg
mptcp_lib_fail_if_expected_feature() {
if mptcp_lib_expect_all_features; then
echo "ERROR: missing feature: ${*}"
exit ${KSFT_FAIL}
fi

return 1
}

# $1: file
mptcp_lib_has_file() {
local f="${1}"

if [ -f "${f}" ]; then
return 0
fi

mptcp_lib_fail_if_expected_feature "${f} file not found"
}

mptcp_lib_check_mptcp() {
if ! mptcp_lib_has_file "/proc/sys/net/mptcp/enabled"; then
echo "SKIP: MPTCP support is not available"
exit ${KSFT_SKIP}
fi
}
4 changes: 4 additions & 0 deletions tools/testing/selftests/net/mptcp/mptcp_sockopt.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(dirname "${0}")/mptcp_lib.sh"

ret=0
sin=""
sout=""
Expand Down Expand Up @@ -84,6 +86,8 @@ cleanup()
rm -f "$sin" "$sout"
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/net/mptcp/pm_netlink.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(dirname "${0}")/mptcp_lib.sh"

ksft_skip=4
ret=0

Expand Down Expand Up @@ -34,6 +36,8 @@ cleanup()
ip netns del $ns1
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/net/mptcp/simult_flows.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(dirname "${0}")/mptcp_lib.sh"

sec=$(date +%s)
rndh=$(printf %x $sec)-$(mktemp -u XXXXXX)
ns1="ns1-$rndh"
Expand Down Expand Up @@ -34,6 +36,8 @@ cleanup()
done
}

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Could not run test without ip tool"
Expand Down
4 changes: 4 additions & 0 deletions tools/testing/selftests/net/mptcp/userspace_pm.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0

. "$(dirname "${0}")/mptcp_lib.sh"

mptcp_lib_check_mptcp

ip -Version > /dev/null 2>&1
if [ $? -ne 0 ];then
echo "SKIP: Cannot not run test without ip tool"
Expand Down

0 comments on commit 7ba0732

Please sign in to comment.