1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0-only
3
4source ethtool-common.sh
5
6# Bail if ethtool is too old
7if ! ethtool -h | grep include-stat 2>&1 >/dev/null; then
8    echo "SKIP: No --include-statistics support in ethtool"
9    exit 4
10fi
11
12NSIM_NETDEV=$(make_netdev)
13
14set -o pipefail
15
16echo n > $NSIM_DEV_DFS/ethtool/pause/report_stats_tx
17echo n > $NSIM_DEV_DFS/ethtool/pause/report_stats_rx
18
19s=$(ethtool --json -a $NSIM_NETDEV | jq '.[].statistics')
20check $? "$s" "null"
21
22s=$(ethtool -I --json -a $NSIM_NETDEV | jq '.[].statistics')
23check $? "$s" "{}"
24
25echo y > $NSIM_DEV_DFS/ethtool/pause/report_stats_tx
26
27s=$(ethtool -I --json -a $NSIM_NETDEV | jq '.[].statistics | length')
28check $? "$s" "1"
29
30s=$(ethtool -I --json -a $NSIM_NETDEV | jq '.[].statistics.tx_pause_frames')
31check $? "$s" "2"
32
33echo y > $NSIM_DEV_DFS/ethtool/pause/report_stats_rx
34
35s=$(ethtool -I --json -a $NSIM_NETDEV | jq '.[].statistics | length')
36check $? "$s" "2"
37
38s=$(ethtool -I --json -a $NSIM_NETDEV | jq '.[].statistics.rx_pause_frames')
39check $? "$s" "1"
40s=$(ethtool -I --json -a $NSIM_NETDEV | jq '.[].statistics.tx_pause_frames')
41check $? "$s" "2"
42
43if [ $num_errors -eq 0 ]; then
44    echo "PASSED all $((num_passes)) checks"
45    exit 0
46else
47    echo "FAILED $num_errors/$((num_errors+num_passes)) checks"
48    exit 1
49fi
50