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"
34
35for current_test in ${TESTS:-$ALL_TESTS}; do
36	RET_FIN=0
37	source ${current_test}_scale.sh
38
39	num_netifs_var=${current_test^^}_NUM_NETIFS
40	num_netifs=${!num_netifs_var:-$NUM_NETIFS}
41
42	for profile in $KVD_PROFILES; do
43		RET=0
44		devlink_sp_resource_kvd_profile_set $profile
45		if [[ $RET -gt 0 ]]; then
46			log_test "'$current_test' [$profile] setting"
47			continue
48		fi
49
50		for should_fail in 0 1; do
51			RET=0
52			target=$(${current_test}_get_target "$should_fail")
53			if ((target == 0)); then
54				log_test_skip "'$current_test' [$profile] should_fail=$should_fail test"
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