Commit b8bfafe4 authored by Petr Machata's avatar Petr Machata Committed by David S. Miller
Browse files

selftests: mlxsw: Add helpers for skipping selftests



A number of mlxsw-specific selftests currently detect whether they are run
on a compatible machine, and bail out silently when not. These tests are
however done in a somewhat impenetrable manner by directly comparing PCI
IDs against a blacklist or a whitelist, and bailing out silently if the
machine is not compatible.

Instead, add a helper, mlxsw_only_on_spectrum(), which allows specifying
the supported machines in a human-readable manner. If the current machine
is incompatible, the helper emits a SKIP message and returns an error code,
based on which the caller can gracefully bail out in a suitable way. This
allows a more readable conditions such as:

	mlxsw_only_on_spectrum 2+ || return

Convert all existing open-coded guards to the new helper. Also add two new
guards to do_mark_test() and do_drop_test(), which are supported only on
Spectrum-2+, but the corresponding check was not there.

Signed-off-by: default avatarPetr Machata <petrm@nvidia.com>
Signed-off-by: default avatarIdo Schimmel <idosch@nvidia.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 71de5b23
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ ALL_TESTS="
NUM_NETIFS=4
source $lib_dir/lib.sh
source $lib_dir/devlink_lib.sh
source mlxsw_lib.sh

h1_create()
{
@@ -626,8 +627,7 @@ ipv6_redirect_test()

ptp_event_test()
{
	# PTP is only supported on Spectrum-1, for now.
	[[ "$DEVLINK_VIDDID" != "15b3:cb84" ]] && return
	mlxsw_only_on_spectrum 1 || return

	# PTP Sync (0)
	devlink_trap_stats_test "PTP Time-Critical Event Message" "ptp_event" \
@@ -638,8 +638,7 @@ ptp_event_test()

ptp_general_test()
{
	# PTP is only supported on Spectrum-1, for now.
	[[ "$DEVLINK_VIDDID" != "15b3:cb84" ]] && return
	mlxsw_only_on_spectrum 1 || return

	# PTP Announce (b)
	devlink_trap_stats_test "PTP General Message" "ptp_general" \
+50 −0
Original line number Diff line number Diff line
@@ -11,3 +11,53 @@ if [[ ! -v MLXSW_CHIP ]]; then
		exit 1
	fi
fi

MLXSW_SPECTRUM_REV=$(case $MLXSW_CHIP in
			     mlxsw_spectrum)
				     echo 1 ;;
			     mlxsw_spectrum*)
				     echo ${MLXSW_CHIP#mlxsw_spectrum} ;;
			     *)
				     echo "Couldn't determine Spectrum chip revision." \
					  > /dev/stderr ;;
		     esac)

mlxsw_on_spectrum()
{
	local rev=$1; shift
	local op="=="
	local rev2=${rev%+}

	if [[ $rev2 != $rev ]]; then
		op=">="
	fi

	((MLXSW_SPECTRUM_REV $op rev2))
}

__mlxsw_only_on_spectrum()
{
	local rev=$1; shift
	local caller=$1; shift
	local src=$1; shift

	if ! mlxsw_on_spectrum "$rev"; then
		log_test_skip $src:$caller "(Spectrum-$rev only)"
		return 1
	fi
}

mlxsw_only_on_spectrum()
{
	local caller=${FUNCNAME[1]}
	local src=${BASH_SOURCE[1]}
	local rev

	for rev in "$@"; do
		if __mlxsw_only_on_spectrum "$rev" "$caller" "$src"; then
			return 0
		fi
	done

	return 1
}
+6 −4
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ CHECK_TC="yes"
lib_dir=$(dirname $0)/../../../net/forwarding
source $lib_dir/lib.sh
source $lib_dir/devlink_lib.sh
source mlxsw_lib.sh
source qos_lib.sh

ipaddr()
@@ -479,10 +480,7 @@ do_ecn_test_perband()
	local vlan=$1; shift
	local limit=$1; shift

	# Per-band ECN counters are not supported on Spectrum-1 and Spectrum-2.
	[[ "$DEVLINK_VIDDID" == "15b3:cb84" ||
	   "$DEVLINK_VIDDID" == "15b3:cf6c" ]] && return

	mlxsw_only_on_spectrum 3+ || return
	__do_ecn_test get_qdisc_nmarked "$vlan" "$limit" "per-band ECN"
}

@@ -584,6 +582,8 @@ do_mark_test()
	local should_fail=$1; shift
	local base

	mlxsw_only_on_spectrum 2+ || return

	RET=0

	start_tcp_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) \
@@ -632,6 +632,8 @@ do_drop_test()
	local base
	local now

	mlxsw_only_on_spectrum 2+ || return

	RET=0

	start_traffic $h1.$vlan $(ipaddr 1 $vlan) $(ipaddr 3 $vlan) $h3_mac
+2 −5
Original line number Diff line number Diff line
@@ -7,12 +7,9 @@ NUM_NETIFS=6
source $lib_dir/lib.sh
source $lib_dir/tc_common.sh
source $lib_dir/devlink_lib.sh
source ../mlxsw_lib.sh

if [[ "$DEVLINK_VIDDID" != "15b3:cf6c" && \
	"$DEVLINK_VIDDID" != "15b3:cf70" ]]; then
	echo "SKIP: test is tailored for Mellanox Spectrum-2 and Spectrum-3"
	exit 1
fi
mlxsw_only_on_spectrum 2+ || exit 1

current_test=""

+2 −4
Original line number Diff line number Diff line
@@ -2,11 +2,9 @@
# SPDX-License-Identifier: GPL-2.0

source "../../../../net/forwarding/devlink_lib.sh"
source ../mlxsw_lib.sh

if [ "$DEVLINK_VIDDID" != "15b3:cb84" ]; then
	echo "SKIP: test is tailored for Mellanox Spectrum"
	exit 1
fi
mlxsw_only_on_spectrum 1 || exit 1

# Needed for returning to default
declare -A KVD_DEFAULTS
Loading