1#!/bin/bash 2# SPDX-License-Identifier: GPL-2.0-or-later 3 4set -e 5 6TESTNAME=set_pcie_speed 7 8declare -a PCIELINKSPEED=( 9 "2.5 GT/s PCIe" 10 "5.0 GT/s PCIe" 11 "8.0 GT/s PCIe" 12 "16.0 GT/s PCIe" 13 "32.0 GT/s PCIe" 14 "64.0 GT/s PCIe" 15) 16 17# Kselftest framework requirement - SKIP code is 4. 18ksft_skip=4 19retval=0 20 21coolingdev="$1" 22statefile="$coolingdev/cur_state" 23maxfile="$coolingdev/max_state" 24linkspeedfile="$2" 25 26oldstate=`cat $statefile` 27maxstate=`cat $maxfile` 28 29set_state() 30{ 31 local state=$1 32 local linkspeed 33 local expected_linkspeed 34 35 echo $state > $statefile 36 37 sleep 1 38 39 linkspeed="`cat $linkspeedfile`" 40 expected_linkspeed=$((maxstate-state)) 41 expected_str="${PCIELINKSPEED[$expected_linkspeed]}" 42 if [ ! "${expected_str}" = "${linkspeed}" ]; then 43 echo "$TESTNAME failed: expected: ${expected_str}; got ${linkspeed}" 44 retval=1 45 fi 46} 47 48cleanup_skip () 49{ 50 set_state $oldstate 51 exit $ksft_skip 52} 53 54trap cleanup_skip EXIT 55 56echo "$TESTNAME: testing states $maxstate .. $oldstate with $coolingdev" 57for i in $(seq $maxstate -1 $oldstate); do 58 set_state "$i" 59done 60 61trap EXIT 62if [ $retval -eq 0 ]; then 63 echo "$TESTNAME [PASS]" 64else 65 echo "$TESTNAME [FAIL]" 66fi 67exit $retval 68