335 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03#4# In addition to the common variables, user might use:5# LC_SLOT - If not set, all probed line cards are going to be tested,6# with an exception of the "activation_16x100G_test".7# It set, only the selected line card is going to be used8# for tests, including "activation_16x100G_test".9 10lib_dir=$(dirname $0)/../../../net/forwarding11 12ALL_TESTS="13 unprovision_test14 provision_test15 activation_16x100G_test16"17 18NUM_NETIFS=019 20source $lib_dir/lib.sh21source $lib_dir/devlink_lib.sh22 23until_lc_state_is()24{25 local state=$1; shift26 local current=$("$@")27 28 echo "$current"29 [ "$current" == "$state" ]30}31 32until_lc_state_is_not()33{34 ! until_lc_state_is "$@"35}36 37lc_state_get()38{39 local lc=$140 41 devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].state"42}43 44lc_wait_until_state_changes()45{46 local lc=$147 local state=$248 local timeout=$3 # ms49 50 busywait "$timeout" until_lc_state_is_not "$state" lc_state_get "$lc"51}52 53lc_wait_until_state_becomes()54{55 local lc=$156 local state=$257 local timeout=$3 # ms58 59 busywait "$timeout" until_lc_state_is "$state" lc_state_get "$lc"60}61 62until_lc_port_count_is()63{64 local port_count=$1; shift65 local current=$("$@")66 67 echo "$current"68 [ $current == $port_count ]69}70 71lc_port_count_get()72{73 local lc=$174 75 devlink port -j | jq -e -r ".[][] | select(.lc==$lc) | .port" | wc -l76}77 78lc_wait_until_port_count_is()79{80 local lc=$181 local port_count=$282 local timeout=$3 # ms83 84 busywait "$timeout" until_lc_port_count_is "$port_count" lc_port_count_get "$lc"85}86 87lc_nested_devlink_dev_get()88{89 local lc=$190 91 devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].nested_devlink"92}93 94PROV_UNPROV_TIMEOUT=8000 # ms95POST_PROV_ACT_TIMEOUT=2000 # ms96PROV_PORTS_INSTANTIATION_TIMEOUT=15000 # ms97 98unprovision_one()99{100 local lc=$1101 local state102 103 state=$(lc_state_get $lc)104 check_err $? "Failed to get state of linecard $lc"105 if [[ "$state" == "unprovisioned" ]]; then106 return107 fi108 109 log_info "Unprovisioning linecard $lc"110 111 devlink lc set $DEVLINK_DEV lc $lc notype112 check_err $? "Failed to trigger linecard $lc unprovisioning"113 114 state=$(lc_wait_until_state_changes $lc "unprovisioning" \115 $PROV_UNPROV_TIMEOUT)116 check_err $? "Failed to unprovision linecard $lc (timeout)"117 118 [ "$state" == "unprovisioned" ]119 check_err $? "Failed to unprovision linecard $lc (state=$state)"120}121 122provision_one()123{124 local lc=$1125 local type=$2126 local state127 128 log_info "Provisioning linecard $lc"129 130 devlink lc set $DEVLINK_DEV lc $lc type $type131 check_err $? "Failed trigger linecard $lc provisioning"132 133 state=$(lc_wait_until_state_changes $lc "provisioning" \134 $PROV_UNPROV_TIMEOUT)135 check_err $? "Failed to provision linecard $lc (timeout)"136 137 [ "$state" == "provisioned" ] || [ "$state" == "active" ]138 check_err $? "Failed to provision linecard $lc (state=$state)"139 140 provisioned_type=$(devlink lc show $DEVLINK_DEV lc $lc -j | jq -e -r ".[][][].type")141 [ "$provisioned_type" == "$type" ]142 check_err $? "Wrong provision type returned for linecard $lc (got \"$provisioned_type\", expected \"$type\")"143 144 # Wait for possible activation to make sure the state145 # won't change after return from this function.146 state=$(lc_wait_until_state_becomes $lc "active" \147 $POST_PROV_ACT_TIMEOUT)148}149 150unprovision_test()151{152 RET=0153 local lc154 155 lc=$LC_SLOT156 unprovision_one $lc157 log_test "Unprovision"158}159 160LC_16X100G_TYPE="16x100G"161LC_16X100G_PORT_COUNT=16162 163supported_types_check()164{165 local lc=$1166 local supported_types_count167 local type_index168 local lc_16x100_found=false169 170 supported_types_count=$(devlink lc show $DEVLINK_DEV lc $lc -j | \171 jq -e -r ".[][][].supported_types | length")172 [ $supported_types_count != 0 ]173 check_err $? "No supported types found for linecard $lc"174 for (( type_index=0; type_index<$supported_types_count; type_index++ ))175 do176 type=$(devlink lc show $DEVLINK_DEV lc $lc -j | \177 jq -e -r ".[][][].supported_types[$type_index]")178 if [[ "$type" == "$LC_16X100G_TYPE" ]]; then179 lc_16x100_found=true180 break181 fi182 done183 [ $lc_16x100_found = true ]184 check_err $? "16X100G not found between supported types of linecard $lc"185}186 187ports_check()188{189 local lc=$1190 local expected_port_count=$2191 local port_count192 193 port_count=$(lc_wait_until_port_count_is $lc $expected_port_count \194 $PROV_PORTS_INSTANTIATION_TIMEOUT)195 [ $port_count != 0 ]196 check_err $? "No port associated with linecard $lc"197 [ $port_count == $expected_port_count ]198 check_err $? "Unexpected port count linecard $lc (got $port_count, expected $expected_port_count)"199}200 201lc_dev_info_provisioned_check()202{203 local lc=$1204 local nested_devlink_dev=$2205 local fixed_hw_revision206 local running_ini_version207 208 fixed_hw_revision=$(devlink dev info $nested_devlink_dev -j | \209 jq -e -r '.[][].versions.fixed."hw.revision"')210 check_err $? "Failed to get linecard $lc fixed.hw.revision"211 log_info "Linecard $lc fixed.hw.revision: \"$fixed_hw_revision\""212 running_ini_version=$(devlink dev info $nested_devlink_dev -j | \213 jq -e -r '.[][].versions.running."ini.version"')214 check_err $? "Failed to get linecard $lc running.ini.version"215 log_info "Linecard $lc running.ini.version: \"$running_ini_version\""216}217 218provision_test()219{220 RET=0221 local lc222 local type223 local state224 local nested_devlink_dev225 226 lc=$LC_SLOT227 supported_types_check $lc228 state=$(lc_state_get $lc)229 check_err $? "Failed to get state of linecard $lc"230 if [[ "$state" != "unprovisioned" ]]; then231 unprovision_one $lc232 fi233 provision_one $lc $LC_16X100G_TYPE234 ports_check $lc $LC_16X100G_PORT_COUNT235 236 nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)237 check_err $? "Failed to get nested devlink handle of linecard $lc"238 lc_dev_info_provisioned_check $lc $nested_devlink_dev239 240 log_test "Provision"241}242 243ACTIVATION_TIMEOUT=20000 # ms244 245interface_check()246{247 ip link set $h1 up248 ip link set $h2 up249 ifaces_upped=true250 setup_wait251}252 253lc_dev_info_active_check()254{255 local lc=$1256 local nested_devlink_dev=$2257 local fixed_device_fw_psid258 local running_device_fw259 260 fixed_device_fw_psid=$(devlink dev info $nested_devlink_dev -j | \261 jq -e -r ".[][].versions.fixed" | \262 jq -e -r '."fw.psid"')263 check_err $? "Failed to get linecard $lc fixed fw PSID"264 log_info "Linecard $lc fixed.fw.psid: \"$fixed_device_fw_psid\""265 266 running_device_fw=$(devlink dev info $nested_devlink_dev -j | \267 jq -e -r ".[][].versions.running.fw")268 check_err $? "Failed to get linecard $lc running.fw.version"269 log_info "Linecard $lc running.fw: \"$running_device_fw\""270}271 272activation_16x100G_test()273{274 RET=0275 local lc276 local type277 local state278 local nested_devlink_dev279 280 lc=$LC_SLOT281 type=$LC_16X100G_TYPE282 283 unprovision_one $lc284 provision_one $lc $type285 state=$(lc_wait_until_state_becomes $lc "active" \286 $ACTIVATION_TIMEOUT)287 check_err $? "Failed to get linecard $lc activated (timeout)"288 289 interface_check290 291 nested_devlink_dev=$(lc_nested_devlink_dev_get $lc)292 check_err $? "Failed to get nested devlink handle of linecard $lc"293 lc_dev_info_active_check $lc $nested_devlink_dev294 295 log_test "Activation 16x100G"296}297 298setup_prepare()299{300 local lc_num=$(devlink lc show -j | jq -e -r ".[][\"$DEVLINK_DEV\"] |length")301 if [[ $? -ne 0 ]] || [[ $lc_num -eq 0 ]]; then302 echo "SKIP: No linecard support found"303 exit $ksft_skip304 fi305 306 if [ -z "$LC_SLOT" ]; then307 echo "SKIP: \"LC_SLOT\" variable not provided"308 exit $ksft_skip309 fi310 311 # Interfaces are not present during the script start,312 # that's why we define NUM_NETIFS here so dummy313 # implicit veth pairs are not created.314 NUM_NETIFS=2315 h1=${NETIFS[p1]}316 h2=${NETIFS[p2]}317 ifaces_upped=false318}319 320cleanup()321{322 if [ "$ifaces_upped" = true ] ; then323 ip link set $h1 down324 ip link set $h2 down325 fi326}327 328trap cleanup EXIT329 330setup_prepare331 332tests_run333 334exit $EXIT_STATUS335