selftests: mlxsw: Add helpers for skipping selftests
authorPetr Machata <petrm@nvidia.com>
Sun, 24 Oct 2021 07:19:09 +0000 (10:19 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 25 Oct 2021 13:10:11 +0000 (14:10 +0100)
commitb8bfafe43481e0b053694227bb013150f10db3ae
tree2acad50d3772f88890040c61e53c8955d4516a4c
parent71de5b234c3be9f5a58082a2fd43627fba6aa86b
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: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/drivers/net/mlxsw/devlink_trap_control.sh
tools/testing/selftests/drivers/net/mlxsw/mlxsw_lib.sh
tools/testing/selftests/drivers/net/mlxsw/sch_red_core.sh
tools/testing/selftests/drivers/net/mlxsw/spectrum-2/resource_scale.sh
tools/testing/selftests/drivers/net/mlxsw/spectrum/devlink_lib_spectrum.sh
tools/testing/selftests/drivers/net/mlxsw/tc_restrictions.sh
tools/testing/selftests/drivers/net/mlxsw/tc_sample.sh
tools/testing/selftests/net/forwarding/lib.sh