0001
0002
0003
0004 source ethtool-common.sh
0005
0006 function get_value {
0007 local query="${SETTINGS_MAP[$1]}"
0008
0009 echo $(ethtool -c $NSIM_NETDEV | \
0010 awk -F':' -v pattern="$query:" '$0 ~ pattern {gsub(/[ \t]/, "", $2); print $2}')
0011 }
0012
0013 function update_current_settings {
0014 for key in ${!SETTINGS_MAP[@]}; do
0015 CURRENT_SETTINGS[$key]=$(get_value $key)
0016 done
0017 echo ${CURRENT_SETTINGS[@]}
0018 }
0019
0020 if ! ethtool -h | grep -q coalesce; then
0021 echo "SKIP: No --coalesce support in ethtool"
0022 exit 4
0023 fi
0024
0025 NSIM_NETDEV=$(make_netdev)
0026
0027 set -o pipefail
0028
0029 declare -A SETTINGS_MAP=(
0030 ["rx-frames-low"]="rx-frame-low"
0031 ["tx-frames-low"]="tx-frame-low"
0032 ["rx-frames-high"]="rx-frame-high"
0033 ["tx-frames-high"]="tx-frame-high"
0034 ["rx-usecs"]="rx-usecs"
0035 ["rx-frames"]="rx-frames"
0036 ["rx-usecs-irq"]="rx-usecs-irq"
0037 ["rx-frames-irq"]="rx-frames-irq"
0038 ["tx-usecs"]="tx-usecs"
0039 ["tx-frames"]="tx-frames"
0040 ["tx-usecs-irq"]="tx-usecs-irq"
0041 ["tx-frames-irq"]="tx-frames-irq"
0042 ["stats-block-usecs"]="stats-block-usecs"
0043 ["pkt-rate-low"]="pkt-rate-low"
0044 ["rx-usecs-low"]="rx-usecs-low"
0045 ["tx-usecs-low"]="tx-usecs-low"
0046 ["pkt-rate-high"]="pkt-rate-high"
0047 ["rx-usecs-high"]="rx-usecs-high"
0048 ["tx-usecs-high"]="tx-usecs-high"
0049 ["sample-interval"]="sample-interval"
0050 )
0051
0052 declare -A CURRENT_SETTINGS=(
0053 ["rx-frames-low"]=""
0054 ["tx-frames-low"]=""
0055 ["rx-frames-high"]=""
0056 ["tx-frames-high"]=""
0057 ["rx-usecs"]=""
0058 ["rx-frames"]=""
0059 ["rx-usecs-irq"]=""
0060 ["rx-frames-irq"]=""
0061 ["tx-usecs"]=""
0062 ["tx-frames"]=""
0063 ["tx-usecs-irq"]=""
0064 ["tx-frames-irq"]=""
0065 ["stats-block-usecs"]=""
0066 ["pkt-rate-low"]=""
0067 ["rx-usecs-low"]=""
0068 ["tx-usecs-low"]=""
0069 ["pkt-rate-high"]=""
0070 ["rx-usecs-high"]=""
0071 ["tx-usecs-high"]=""
0072 ["sample-interval"]=""
0073 )
0074
0075 declare -A EXPECTED_SETTINGS=(
0076 ["rx-frames-low"]=""
0077 ["tx-frames-low"]=""
0078 ["rx-frames-high"]=""
0079 ["tx-frames-high"]=""
0080 ["rx-usecs"]=""
0081 ["rx-frames"]=""
0082 ["rx-usecs-irq"]=""
0083 ["rx-frames-irq"]=""
0084 ["tx-usecs"]=""
0085 ["tx-frames"]=""
0086 ["tx-usecs-irq"]=""
0087 ["tx-frames-irq"]=""
0088 ["stats-block-usecs"]=""
0089 ["pkt-rate-low"]=""
0090 ["rx-usecs-low"]=""
0091 ["tx-usecs-low"]=""
0092 ["pkt-rate-high"]=""
0093 ["rx-usecs-high"]=""
0094 ["tx-usecs-high"]=""
0095 ["sample-interval"]=""
0096 )
0097
0098
0099 for key in ${!SETTINGS_MAP[@]}; do
0100 EXPECTED_SETTINGS[$key]=$(get_value $key)
0101 done
0102
0103
0104 for key in ${!SETTINGS_MAP[@]}; do
0105 value=$((RANDOM % $((2**32-1))))
0106
0107 ethtool -C $NSIM_NETDEV "$key" "$value"
0108
0109 EXPECTED_SETTINGS[$key]="$value"
0110 expected=${EXPECTED_SETTINGS[@]}
0111 current=$(update_current_settings)
0112
0113 check $? "$current" "$expected"
0114 set +x
0115 done
0116
0117
0118 ethtool -C $NSIM_NETDEV adaptive-rx on
0119 s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: off")
0120 check $? "$s" ""
0121
0122 ethtool -C $NSIM_NETDEV adaptive-tx on
0123 s=$(ethtool -c $NSIM_NETDEV | grep -q "Adaptive RX: on TX: on")
0124 check $? "$s" ""
0125
0126 if [ $num_errors -eq 0 ]; then
0127 echo "PASSED all $((num_passes)) checks"
0128 exit 0
0129 else
0130 echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
0131 exit 1
0132 fi