On Tue, Sep 2, 2025 at 4:55 PM Marc Harvey marcharvey@google.com wrote:
There are currently no kernel tests that verify setting and getting options of the team driver.
In the future, options may be added that implicitly change other options, which will make it useful to have tests like these that show nothing breaks. There will be a follow up patch to this that adds new "rx_enabled" and "tx_enabled" options, which will implicitly affect the "enabled" option value and vice versa.
The tests use teamnl to first set options to specific values and then gets them to compare to the set values.
Signed-off-by: Marc Harvey marcharvey@google.com
.../selftests/drivers/net/team/Makefile | 6 +- .../selftests/drivers/net/team/options.sh | 194 ++++++++++++++++++ 2 files changed, 198 insertions(+), 2 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/team/options.sh
diff --git a/tools/testing/selftests/drivers/net/team/Makefile b/tools/testing/selftests/drivers/net/team/Makefile index eaf6938f100e..8b00b70ce67f 100644 --- a/tools/testing/selftests/drivers/net/team/Makefile +++ b/tools/testing/selftests/drivers/net/team/Makefile @@ -1,11 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for net selftests
-TEST_PROGS := dev_addr_lists.sh propagation.sh +TEST_PROGS := dev_addr_lists.sh propagation.sh options.sh
TEST_INCLUDES := \ ../bonding/lag_lib.sh \ ../../../net/forwarding/lib.sh \
../../../net/lib.sh
../../../net/lib.sh \../../../net/in_netns.sh \../../../net/lib/sh/defer.sh \include ../../../lib.mk diff --git a/tools/testing/selftests/drivers/net/team/options.sh b/tools/testing/selftests/drivers/net/team/options.sh new file mode 100755 index 000000000000..b9c7aa357ad5 --- /dev/null +++ b/tools/testing/selftests/drivers/net/team/options.sh @@ -0,0 +1,194 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0
+# These tests verify basic set and get functionality of the team +# driver options over netlink.
+# Run in private netns. +test_dir="$(dirname "$0")" +if [[ $# -eq 0 ]]; then
"${test_dir}"/../../../net/in_netns.sh "$0" __subprocessexit $?+fi
+ALL_TESTS="
team_test_options+"
+source "${test_dir}/../../../net/lib.sh"
+TEAM_PORT="team0" +MEMBER_PORT="dummy0"
+setup() +{
ip link add name "${MEMBER_PORT}" type dummyip link add name "${TEAM_PORT}" type team+}
+get_and_check_value() +{
local option_name="$1"local expected_value="$2"local port_flag="$3"local value_from_getvalue_from_get=$(teamnl "${TEAM_PORT}" getoption "${option_name}" \"${port_flag}")if [[ $? != 0 ]]; then
I'm aware of the shellcheck errors. Will wait to send v2 tomorrow for the 24 hour rule.
echo "Could not get option '${option_name}'" >&2return 1fiif [[ "${value_from_get}" != "${expected_value}" ]]; thenecho "Incorrect value for option '${option_name}'" >&2echo "get (${value_from_get}) != set (${expected_value})" >&2return 1fi+}
+set_and_check_get() +{
local option_name="$1"local option_value="$2"local port_flag="$3"local value_from_getteamnl "${TEAM_PORT}" setoption "${option_name}" "${option_value}" \"${port_flag}"if [[ $? != 0 ]]; thenecho "'setoption ${option_name} ${option_value}' failed" >&2return 1figet_and_check_value "${option_name}" "${option_value}" "${port_flag}"return $?+}
+# Get a "port flag" to pass to the `teamnl` command. +# E.g. $?="dummy0" -> "port=dummy0", +# $?="" -> "" +get_port_flag() +{
local port_name="$1"if [[ -n "${port_name}" ]]; thenecho "--port=${port_name}"fi+}
+attach_port_if_specified() +{
local port_name="${1}"if [[ -n "${port_name}" ]]; thenip link set dev "${port_name}" master "${TEAM_PORT}"return $?fi+}
+detach_port_if_specified() +{
local port_name="${1}"if [[ -n "${port_name}" ]]; thenip link set dev "${port_name}" nomasterreturn $?fi+}
+####################################### +# Test that an option's get value matches its set value. +# Globals: +# RET - Used by testing infra like `check_err`. +# EXIT_STATUS - Used by `log_test` to whole script exit value. +# Arguments: +# option_name - The name of the option. +# value_1 - The first value to try setting. +# value_2 - The second value to try setting. +# port_name - The (optional) name of the attached port. +####################################### +team_test_option() +{
local option_name="$1"local value_1="$2"local value_2="$3"local possible_values="$2 $3 $2"local port_name="$4"local port_flagRET=0echo "Setting '${option_name}' to '${value_1}' and '${value_2}'"attach_port_if_specified "${port_name}"check_err $? "Couldn't attach ${port_name} to master"port_flag=$(get_port_flag "${port_name}")# Set and get both possible values.for value in ${possible_values}; doset_and_check_get "${option_name}" "${value}" "${port_flag}"check_err $? "Failed to set '${option_name}' to '${value}'"donedetach_port_if_specified "${port_name}"check_err $? "Couldn't detach ${port_name} from its master"log_test "Set + Get '${option_name}' test"+}
+####################################### +# Test that getting a non-existant option fails. +# Globals: +# RET - Used by testing infra like `check_err`. +# EXIT_STATUS - Used by `log_test` to whole script exit value. +# Arguments: +# option_name - The name of the option. +# port_name - The (optional) name of the attached port. +####################################### +team_test_get_option_fails() +{
local option_name="$1"local port_name="$2"local port_flagRET=0attach_port_if_specified "${port_name}"check_err $? "Couldn't attach ${port_name} to master"port_flag=$(get_port_flag "${port_name}")# Just confirm that getting the value fails.teamnl "${TEAM_PORT}" getoption "${option_name}" "${port_flag}"check_fail $? "Shouldn't be able to get option '${option_name}'"detach_port_if_specified "${port_name}"log_test "Get '${option_name}' fails"+}
+team_test_options() +{
# Wrong option name behavior.team_test_get_option_fails fake_option1team_test_get_option_fails fake_option2 "${MEMBER_PORT}"# Correct set and get behavior.team_test_option mode activebackup loadbalanceteam_test_option notify_peers_count 0 5team_test_option notify_peers_interval 0 5team_test_option mcast_rejoin_count 0 5team_test_option mcast_rejoin_interval 0 5team_test_option enabled true false "${MEMBER_PORT}"team_test_option user_linkup true false "${MEMBER_PORT}"team_test_option user_linkup_enabled true false "${MEMBER_PORT}"team_test_option priority 10 20 "${MEMBER_PORT}"team_test_option queue_id 0 1 "${MEMBER_PORT}"+}
+require_command teamnl +setup +tests_run
+exit "${EXIT_STATUS}"
2.51.0.355.g5224444f11-goog