xref: /linux/tools/testing/selftests/drivers/net/mlxsw/spectrum/resource_scale.sh (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
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				continue
56			fi
57			${current_test}_setup_prepare
58			setup_wait $num_netifs
59			# Update target in case occupancy of a certain resource
60			# changed following the test setup.
61			target=$(${current_test}_get_target "$should_fail")
62			${current_test}_test "$target" "$should_fail"
63			if [[ "$should_fail" -eq 0 ]]; then
64				log_test "'$current_test' [$profile] $target"
65
66				if ((!RET)); then
67					tt=${current_test}_traffic_test
68					if [[ $(type -t $tt) == "function" ]]
69					then
70						$tt "$target"
71						log_test "'$current_test' [$profile] $target traffic test"
72					fi
73				fi
74			else
75				log_test "'$current_test' [$profile] overflow $target"
76			fi
77			${current_test}_cleanup $target
78			RET_FIN=$(( RET_FIN || RET ))
79		done
80	done
81done
82current_test=""
83
84exit "$RET_FIN"
85