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: Petr Machata <petrm@nvidia.com> Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
64 lines
1.2 KiB
Bash
64 lines
1.2 KiB
Bash
#!/bin/bash
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
|
|
##############################################################################
|
|
# Defines
|
|
|
|
if [[ ! -v MLXSW_CHIP ]]; then
|
|
MLXSW_CHIP=$(devlink -j dev info $DEVLINK_DEV | jq -r '.[][]["driver"]')
|
|
if [ -z "$MLXSW_CHIP" ]; then
|
|
echo "SKIP: Device $DEVLINK_DEV doesn't support devlink info command"
|
|
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
|
|
}
|