1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
#! /bin/sh
# SPDX-License-Identifier: BSD-3-Clause
# Minimal mptcpd start/stop test.
#
# Copyright (c) 2018, 2019, 2021, 2022, Intel Corporation
if [ -z "$TEST_PLUGIN_DIR" ]; then
echo TEST_PLUGIN_DIR environment variable is not set.
exit 1 # failure
fi
# An exit status of 77 causes the Automake test driver to consider the
# test as skipped.
skip_exit_status=77
# Skip the test if we're not using a kernel supporting MPTCP.
if [ ! -d /proc/sys/net/mptcp ]; then
echo Not running a kernel supporting MPTCP, skipping the test
exit $skip_exit_status
fi
# Only run the individual enabled/disabled MPTCP test cases if the
# "enabled" value can be set non-interactively, i.e. sudo can be
# executed without a password. This is mostly useful for automated
# builds.
echo Running non-interactive sudo check...
if ! sudo -n echo " succeeded"; then
echo " fail, skipping the test"
exit $skip_exit_status
fi
# Detect MPTCP "enabled" sysctl variable name and value.
# upstream: net.mptcp.enabled
# multipath-tcp.org: net.mptcp.mptcp_enabled
variable=`sysctl --names --pattern 'mptcp.(|mptcp_)enabled' net.mptcp`
old_value=`sysctl --values $variable`
disable_value=0
enable_value=1
# "Disabled" value is always 0, but the "enabled" value could be 1 or
# 2, depending on the kernel in use. For example, the
# multipath-tcp.org kernel "enabled" value could be 1 or 2. Use the
# old "enabled" value in case it is 2 instead of 1.
if [ $old_value -ne 0 ]
then
enable_value=$old_value
fi
# @todo It would be better to have some sort of indication that
# mptcpd is fully up and running rather than timeout after a
# fixed amount of time like this.
command="timeout --preserve-status \
--signal=TERM \
--kill-after=5s \
1s ../src/mptcpd --plugin-dir=$TEST_PLUGIN_DIR"
# Exit status/code
status=0
for value in $disable_value $enable_value
do
sudo -n sysctl -qw $variable=$value
$command
command_exit=$?
echo -n "TEST CASE: $variable = $value ..."
if ([ $value -eq $disable_value ] && [ $command_exit -eq 0 ]) \
|| ([ $value -eq $enable_value ] && [ $command_exit -ne 0 ])
then
echo failed
status=1 # failure
else
echo passed
fi
done
# Reset the "enabled" value to its original value.
sudo -n sysctl -qw $variable=$old_value
exit $status
|