selftests: net: Add tests to verify team driver option set and get.
Subsystems (4)
PATCH v2 1/1 selftests: net: Add tests to verify team driver option set and get.
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.
---
Changes in v2:
- Fixed shellcheck failures.
- Fixed test failing in vng by adding a config option to enable the
team driver's active backup mode.
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
.../selftests/drivers/net/team/Makefile | 6 +- .../testing/selftests/drivers/net/team/config | 1 + .../selftests/drivers/net/team/options.sh | 192 ++++++++++++++++++ 3 files changed, 197 insertions(+), 2 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/team/options.sh
tools/testing/selftests/drivers/net/team/Makefile +4 -2
@@ -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
tools/testing/selftests/drivers/net/team/config +1 -0
@@ -3,4 +3,5 @@ CONFIG_IPV6=y CONFIG_MACVLAN=y CONFIG_NETDEVSIM=m CONFIG_NET_TEAM=y +CONFIG_NET_TEAM_MODE_ACTIVEBACKUP=y CONFIG_NET_TEAM_MODE_LOADBALANCE=y
tools/testing/selftests/drivers/net/team/options.sh new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
2.51.0.338.gd7d06c2dae-goog
Quoted 34 lines · Marc Harvey
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 <[email protected]>---
Changes in v2:
- Fixed shellcheck failures.
- Fixed test failing in vng by adding a config option to enable the
team driver's active backup mode.
- Link to v1: https://lore.kernel.org/netdev/[email protected]/.../selftests/drivers/net/team/Makefile | 6 +- .../testing/selftests/drivers/net/team/config | 1 + .../selftests/drivers/net/team/options.sh | 192 ++++++++++++++++++ 3 files changed, 197 insertions(+), 2 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/team/options.shtools/testing/selftests/drivers/net/team/Makefile +0
-0@@ -1,11 +1,13 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for net selftests
tools/testing/selftests/drivers/net/team/Makefile line 11
Quoted 10 lines
tools/testing/selftests/drivers/net/team/Makefile +4
-2-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 \
Where is defer used? Also no backslash at last line.
Quoted 90 lines
tools/testing/selftests/drivers/net/team/Makefile +0
-0include ../../../lib.mktools/testing/selftests/drivers/net/team/config +1
-0@@ -3,4 +3,5 @@ CONFIG_IPV6=y CONFIG_MACVLAN=y CONFIG_NETDEVSIM=m CONFIG_NET_TEAM=y +CONFIG_NET_TEAM_MODE_ACTIVEBACKUP=y CONFIG_NET_TEAM_MODE_LOADBALANCE=ytools/testing/selftests/drivers/net/team/options.sh new file +72
-0@@ -0,0 +1,192 @@ +#!/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" __subprocess + exit $? +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 dummy + ip 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_get + + if ! value_from_get=$(teamnl "${TEAM_PORT}" getoption "${option_name}" \ + "${port_flag}"); then + echo "Could not get option '${option_name}'" >&2 + return 1 + fi + + if [[ "${value_from_get}" != "${expected_value}" ]]; then + echo "Incorrect value for option '${option_name}'" >&2 + echo "get (${value_from_get}) != set (${expected_value})" >&2 + return 1 + fi +} + +set_and_check_get() +{ + local option_name="$1" + local option_value="$2" + local port_flag="$3" + + local value_from_get + + if ! teamnl "${TEAM_PORT}" setoption "${option_name}" "${option_value}" \ + "${port_flag}"; then + echo "'setoption ${option_name} ${option_value}' failed" >&2 + return 1 + fi + + get_and_check_value "${option_name}" "${option_value}" "${port_flag}" + return $? +} + +# Get a "port flag" to pass to the `teamnl` command. +# E.g. $1="dummy0" -> "port=dummy0", +# $1="" -> "" +get_port_flag() +{
tools/testing/selftests/drivers/net/team/options.sh line 82
Quoted 10 lines
tools/testing/selftests/drivers/net/team/options.sh new file +10
-0+ local port_name="$1" + + if [[ -n "${port_name}" ]]; then + echo "--port=${port_name}" + fi +} + +attach_port_if_specified() +{ + local port_name="${1}"
nit: parentheses around single character variable. Inconsistent.
Quoted 18 lines
tools/testing/selftests/drivers/net/team/options.sh new file +18
-0+ + if [[ -n "${port_name}" ]]; then + ip link set dev "${port_name}" master "${TEAM_PORT}" + return $? + fi +} + +detach_port_if_specified() +{ + local port_name="${1}" + + if [[ -n "${port_name}" ]]; then + ip link set dev "${port_name}" nomaster + return $? + fi +} + +#######################################
tools/testing/selftests/drivers/net/team/options.sh line 110
Quoted 10 lines
tools/testing/selftests/drivers/net/team/options.sh new file +10
-0+# 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. +#######################################
Just curious: is this a standard documentation format?
Quoted 5 lines
tools/testing/selftests/drivers/net/team/options.sh new file +5
-0+team_test_option() +{ + local option_name="$1" + local value_1="$2" + local value_2="$3"
tools/testing/selftests/drivers/net/team/options.sh line 125
Quoted 10 lines
tools/testing/selftests/drivers/net/team/options.sh new file +10
-0+ local possible_values="$2 $3 $2" + local port_name="$4" + local port_flag + + RET=0 + + echo "Setting '${option_name}' to '${value_1}' and '${value_2}'" + + attach_port_if_specified "${port_name}" + check_err $? "Couldn't attach ${port_name} to master"
Can the rest of the test continue if this command failed?
Quoted 13 lines
tools/testing/selftests/drivers/net/team/options.sh new file +13
-0+ port_flag=$(get_port_flag "${port_name}") + + # Set and get both possible values. + for value in ${possible_values}; do + set_and_check_get "${option_name}" "${value}" "${port_flag}" + check_err $? "Failed to set '${option_name}' to '${value}'" + done + + detach_port_if_specified "${port_name}" + check_err $? "Couldn't detach ${port_name} from its master" + + log_test "Set + Get '${option_name}' test" +}
Quoted 10 lines
tools/testing/selftests/drivers/net/team/Makefile line 11
Quoted 8 lines
TEST_INCLUDES := \ ../bonding/lag_lib.sh \ ../../../net/forwarding/lib.sh \tools/testing/selftests/drivers/net/team/Makefile +3
-1- ../../../net/lib.sh + ../../../net/lib.sh \ + ../../../net/in_netns.sh \ + ../../../net/lib/sh/defer.sh \Where is defer used? Also no backslash at last line.
Thank you for the review Willem.
Acknowledged for the backslash, will add in next iteration.
Defer is used by net/lib.sh. If defer.sh isn't included here, then the test won't build correctly.
Quoted 5 lines
tools/testing/selftests/drivers/net/team/options.sh line 82
Quoted 3 lines
tools/testing/selftests/drivers/net/team/options.sh new file +3
-0+attach_port_if_specified() +{ + local port_name="${1}"nit: parentheses around single character variable. Inconsistent.
Acknowledged, will add in the next iteration.
Quoted 5 lines
Quoted 5 lines
tools/testing/selftests/drivers/net/team/options.sh new file +5
-0+####################################### +# 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.
Quoted 8 lines
tools/testing/selftests/drivers/net/team/options.sh line 110
Quoted 6 lines
tools/testing/selftests/drivers/net/team/options.sh new file +6
-0+# 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. +#######################################Just curious: is this a standard documentation format?
https://google.github.io/styleguide/shellguide.html#function-comments
But I will make these fit in better with the rest of the selftests.
Quoted 10 lines
Quoted 10 lines
tools/testing/selftests/drivers/net/team/options.sh new file +9
-0+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_flag +
Quoted 8 lines
tools/testing/selftests/drivers/net/team/options.sh line 125
Quoted 6 lines
tools/testing/selftests/drivers/net/team/options.sh new file +6
-0+ RET=0 + + echo "Setting '${option_name}' to '${value_1}' and '${value_2}'" + + attach_port_if_specified "${port_name}" + check_err $? "Couldn't attach ${port_name} to master"Can the rest of the test continue if this command failed?
The test will fail, but the rest of the test will still run. That being said, only the first error message is printed by the check_err function.
Quoted 15 lines
Quoted 14 lines
tools/testing/selftests/drivers/net/team/options.sh new file +13
-0+ port_flag=$(get_port_flag "${port_name}") + + # Set and get both possible values. + for value in ${possible_values}; do + set_and_check_get "${option_name}" "${value}" "${port_flag}" + check_err $? "Failed to set '${option_name}' to '${value}'" + done + + detach_port_if_specified "${port_name}" + check_err $? "Couldn't detach ${port_name} from its master" + + log_test "Set + Get '${option_name}' test" +}