xref: /linux/tools/testing/selftests/drivers/net/mlxsw/port_scale.sh (revision 02680c23d7b3febe45ea3d4f9818c2b2dc89020a)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# Test for physical ports resource. The test splits each splittable port
5# to its width and checks that eventually the number of physical ports equals
6# the maximum number of physical ports.
7
8PORT_NUM_NETIFS=0
9
10port_setup_prepare()
11{
12	:
13}
14
15port_cleanup()
16{
17	pre_cleanup
18
19	for port in "${unsplit[@]}"; do
20		devlink port unsplit $port
21		check_err $? "Did not unsplit $netdev"
22	done
23}
24
25split_all_ports()
26{
27	local should_fail=$1; shift
28	local -a unsplit
29
30	# Loop over the splittable netdevs and create tuples of netdev along
31	# with its width. For example:
32	# '$netdev1 $count1 $netdev2 $count2...', when:
33	# $netdev1-2 are splittable netdevs in the device, and
34	# $count1-2 are the netdevs width respectively.
35	while read netdev count <<<$(
36		devlink -j port show |
37		jq -r '.[][] | select(.splittable==true) | "\(.netdev) \(.lanes)"'
38		)
39		[[ ! -z $netdev ]]
40	do
41		devlink port split $netdev count $count
42		check_err $? "Did not split $netdev into $count"
43		unsplit+=( "${netdev}s0" )
44	done
45}
46
47port_test()
48{
49	local max_ports=$1; shift
50	local should_fail=$1; shift
51
52	split_all_ports $should_fail
53
54	occ=$(devlink -j resource show $DEVLINK_DEV \
55	      | jq '.[][][] | select(.name=="physical_ports") |.["occ"]')
56
57	[[ $occ -eq $max_ports ]]
58	check_err_fail $should_fail $? "Attempt to create $max_ports ports (actual result $occ)"
59
60}
61