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 $lib_dir/devlink_lib.sh
10source ../mlxsw_lib.sh
11
12mlxsw_only_on_spectrum 2+ || exit 1
13
14current_test=""
15
16cleanup()
17{
18	pre_cleanup
19	if [ ! -z $current_test ]; then
20		${current_test}_cleanup
21	fi
22	# Need to reload in order to avoid router abort.
23	devlink_reload
24}
25
26trap cleanup EXIT
27
28ALL_TESTS="
29	router
30	tc_flower
31	mirror_gre
32	tc_police
33	port
34	rif_mac_profile
35	rif_counter
36	port_range
37"
38
39for current_test in ${TESTS:-$ALL_TESTS}; do
40	RET_FIN=0
41	source ${current_test}_scale.sh
42
43	num_netifs_var=${current_test^^}_NUM_NETIFS
44	num_netifs=${!num_netifs_var:-$NUM_NETIFS}
45
46	for should_fail in 0 1; do
47		RET=0
48		target=$(${current_test}_get_target "$should_fail")
49		if ((target == 0)); then
50			log_test_skip "'$current_test' should_fail=$should_fail test"
51			continue
52		fi
53
54		${current_test}_setup_prepare
55		setup_wait $num_netifs
56		# Update target in case occupancy of a certain resource changed
57		# following the test setup.
58		target=$(${current_test}_get_target "$should_fail")
59		${current_test}_test "$target" "$should_fail"
60		if [[ "$should_fail" -eq 0 ]]; then
61			log_test "'$current_test' $target"
62
63			if ((!RET)); then
64				tt=${current_test}_traffic_test
65				if [[ $(type -t $tt) == "function" ]]; then
66					$tt "$target"
67					log_test "'$current_test' $target traffic test"
68				fi
69			fi
70		else
71			log_test "'$current_test' overflow $target"
72		fi
73		${current_test}_cleanup $target
74		devlink_reload
75		RET_FIN=$(( RET_FIN || RET ))
76	done
77done
78current_test=""
79
80exit "$RET_FIN"
81