xref: /linux/tools/testing/selftests/drivers/net/mlxsw/spectrum/resource_scale.sh (revision be239684b18e1cdcafcf8c7face4a2f562c745ad)
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4lib_dir=$(dirname $0)/../../../../net/forwarding
5
6NUM_NETIFS=6
7source $lib_dir/lib.sh
8source $lib_dir/tc_common.sh
9source devlink_lib_spectrum.sh
10
11current_test=""
12
13cleanup()
14{
15	pre_cleanup
16	if [ ! -z $current_test ]; then
17		${current_test}_cleanup
18	fi
19	devlink_sp_size_kvd_to_default
20}
21
22devlink_sp_read_kvd_defaults
23trap cleanup EXIT
24
25ALL_TESTS="
26	router
27	tc_flower
28	mirror_gre
29	tc_police
30	port
31	rif_mac_profile
32	rif_counter
33	port_range
34"
35
36for current_test in ${TESTS:-$ALL_TESTS}; do
37	RET_FIN=0
38	source ${current_test}_scale.sh
39
40	num_netifs_var=${current_test^^}_NUM_NETIFS
41	num_netifs=${!num_netifs_var:-$NUM_NETIFS}
42
43	for profile in $KVD_PROFILES; do
44		RET=0
45		devlink_sp_resource_kvd_profile_set $profile
46		if [[ $RET -gt 0 ]]; then
47			log_test "'$current_test' [$profile] setting"
48			continue
49		fi
50
51		for should_fail in 0 1; do
52			RET=0
53			target=$(${current_test}_get_target "$should_fail")
54			if ((target == 0)); then
55				log_test_skip "'$current_test' [$profile] should_fail=$should_fail test"
56				continue
57			fi
58			${current_test}_setup_prepare
59			setup_wait $num_netifs
60			# Update target in case occupancy of a certain resource
61			# changed following the test setup.
62			target=$(${current_test}_get_target "$should_fail")
63			${current_test}_test "$target" "$should_fail"
64			if [[ "$should_fail" -eq 0 ]]; then
65				log_test "'$current_test' [$profile] $target"
66
67				if ((!RET)); then
68					tt=${current_test}_traffic_test
69					if [[ $(type -t $tt) == "function" ]]
70					then
71						$tt "$target"
72						log_test "'$current_test' [$profile] $target traffic test"
73					fi
74				fi
75			else
76				log_test "'$current_test' [$profile] overflow $target"
77			fi
78			${current_test}_cleanup $target
79			RET_FIN=$(( RET_FIN || RET ))
80		done
81	done
82done
83current_test=""
84
85exit "$RET_FIN"
86