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"
37
38for current_test in ${TESTS:-$ALL_TESTS}; do
39	RET_FIN=0
40	source ${current_test}_scale.sh
41
42	num_netifs_var=${current_test^^}_NUM_NETIFS
43	num_netifs=${!num_netifs_var:-$NUM_NETIFS}
44
45	for should_fail in 0 1; do
46		RET=0
47		target=$(${current_test}_get_target "$should_fail")
48		if ((target == 0)); then
49			log_test_skip "'$current_test' should_fail=$should_fail test"
50			continue
51		fi
52
53		${current_test}_setup_prepare
54		setup_wait $num_netifs
55		# Update target in case occupancy of a certain resource changed
56		# following the test setup.
57		target=$(${current_test}_get_target "$should_fail")
58		${current_test}_test "$target" "$should_fail"
59		if [[ "$should_fail" -eq 0 ]]; then
60			log_test "'$current_test' $target"
61
62			if ((!RET)); then
63				tt=${current_test}_traffic_test
64				if [[ $(type -t $tt) == "function" ]]; then
65					$tt "$target"
66					log_test "'$current_test' $target traffic test"
67				fi
68			fi
69		else
70			log_test "'$current_test' overflow $target"
71		fi
72		${current_test}_cleanup $target
73		devlink_reload
74		RET_FIN=$(( RET_FIN || RET ))
75	done
76done
77current_test=""
78
79exit "$RET_FIN"
80