Path: blob/master/tools/testing/selftests/drivers/net/team/options.sh
29271 views
#!/bin/bash1# SPDX-License-Identifier: GPL-2.023# These tests verify basic set and get functionality of the team4# driver options over netlink.56# Run in private netns.7test_dir="$(dirname "$0")"8if [[ $# -eq 0 ]]; then9"${test_dir}"/../../../net/in_netns.sh "$0" __subprocess10exit $?11fi1213ALL_TESTS="14team_test_options15"1617source "${test_dir}/../../../net/lib.sh"1819TEAM_PORT="team0"20MEMBER_PORT="dummy0"2122setup()23{24ip link add name "${MEMBER_PORT}" type dummy25ip link add name "${TEAM_PORT}" type team26}2728get_and_check_value()29{30local option_name="$1"31local expected_value="$2"32local port_flag="$3"3334local value_from_get3536if ! value_from_get=$(teamnl "${TEAM_PORT}" getoption "${option_name}" \37"${port_flag}"); then38echo "Could not get option '${option_name}'" >&239return 140fi4142if [[ "${value_from_get}" != "${expected_value}" ]]; then43echo "Incorrect value for option '${option_name}'" >&244echo "get (${value_from_get}) != set (${expected_value})" >&245return 146fi47}4849set_and_check_get()50{51local option_name="$1"52local option_value="$2"53local port_flag="$3"5455local value_from_get5657if ! teamnl "${TEAM_PORT}" setoption "${option_name}" \58"${option_value}" "${port_flag}"; then59echo "'setoption ${option_name} ${option_value}' failed" >&260return 161fi6263get_and_check_value "${option_name}" "${option_value}" "${port_flag}"64return $?65}6667# Get a "port flag" to pass to the `teamnl` command.68# E.g. $1="dummy0" -> "port=dummy0",69# $1="" -> ""70get_port_flag()71{72local port_name="$1"7374if [[ -n "${port_name}" ]]; then75echo "--port=${port_name}"76fi77}7879attach_port_if_specified()80{81local port_name="$1"8283if [[ -n "${port_name}" ]]; then84ip link set dev "${port_name}" master "${TEAM_PORT}"85return $?86fi87}8889detach_port_if_specified()90{91local port_name="$1"9293if [[ -n "${port_name}" ]]; then94ip link set dev "${port_name}" nomaster95return $?96fi97}9899# Test that an option's get value matches its set value.100# Globals:101# RET - Used by testing infra like `check_err`.102# EXIT_STATUS - Used by `log_test` for whole script exit value.103# Arguments:104# option_name - The name of the option.105# value_1 - The first value to try setting.106# value_2 - The second value to try setting.107# port_name - The (optional) name of the attached port.108team_test_option()109{110local option_name="$1"111local value_1="$2"112local value_2="$3"113local possible_values="$2 $3 $2"114local port_name="$4"115local port_flag116117RET=0118119echo "Setting '${option_name}' to '${value_1}' and '${value_2}'"120121attach_port_if_specified "${port_name}"122check_err $? "Couldn't attach ${port_name} to master"123port_flag=$(get_port_flag "${port_name}")124125# Set and get both possible values.126for value in ${possible_values}; do127set_and_check_get "${option_name}" "${value}" "${port_flag}"128check_err $? "Failed to set '${option_name}' to '${value}'"129done130131detach_port_if_specified "${port_name}"132check_err $? "Couldn't detach ${port_name} from its master"133134log_test "Set + Get '${option_name}' test"135}136137# Test that getting a non-existant option fails.138# Globals:139# RET - Used by testing infra like `check_err`.140# EXIT_STATUS - Used by `log_test` for whole script exit value.141# Arguments:142# option_name - The name of the option.143# port_name - The (optional) name of the attached port.144team_test_get_option_fails()145{146local option_name="$1"147local port_name="$2"148local port_flag149150RET=0151152attach_port_if_specified "${port_name}"153check_err $? "Couldn't attach ${port_name} to master"154port_flag=$(get_port_flag "${port_name}")155156# Just confirm that getting the value fails.157teamnl "${TEAM_PORT}" getoption "${option_name}" "${port_flag}"158check_fail $? "Shouldn't be able to get option '${option_name}'"159160detach_port_if_specified "${port_name}"161162log_test "Get '${option_name}' fails"163}164165team_test_options()166{167# Wrong option name behavior.168team_test_get_option_fails fake_option1169team_test_get_option_fails fake_option2 "${MEMBER_PORT}"170171# Correct set and get behavior.172team_test_option mode activebackup loadbalance173team_test_option notify_peers_count 0 5174team_test_option notify_peers_interval 0 5175team_test_option mcast_rejoin_count 0 5176team_test_option mcast_rejoin_interval 0 5177team_test_option enabled true false "${MEMBER_PORT}"178team_test_option user_linkup true false "${MEMBER_PORT}"179team_test_option user_linkup_enabled true false "${MEMBER_PORT}"180team_test_option priority 10 20 "${MEMBER_PORT}"181team_test_option queue_id 0 1 "${MEMBER_PORT}"182}183184require_command teamnl185setup186tests_run187exit "${EXIT_STATUS}"188189190