|
1 | 1 | #!/usr/bin/env python3
|
2 | 2 | # SPDX-License-Identifier: GPL-2.0
|
3 | 3 |
|
| 4 | +import errno |
4 | 5 | from lib.py import ksft_run, ksft_exit, ksft_pr
|
5 | 6 | from lib.py import ksft_ge, ksft_eq, ksft_in, ksft_true, ksft_raises, KsftSkipEx, KsftXfailEx
|
6 | 7 | from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
|
7 | 8 | from lib.py import NetDrvEnv
|
| 9 | +from lib.py import ip, defer |
8 | 10 |
|
9 | 11 | ethnl = EthtoolFamily()
|
10 | 12 | netfam = NetdevFamily()
|
@@ -133,9 +135,30 @@ def qstat_by_ifindex(cfg) -> None:
|
133 | 135 | ksft_eq(cm.exception.nl_msg.extack['bad-attr'], '.ifindex')
|
134 | 136 |
|
135 | 137 |
|
| 138 | +def check_down(cfg) -> None: |
| 139 | + try: |
| 140 | + qstat = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0] |
| 141 | + except NlError as e: |
| 142 | + if e.error == errno.EOPNOTSUPP: |
| 143 | + raise KsftSkipEx("qstats not supported by the device") |
| 144 | + raise |
| 145 | + |
| 146 | + ip(f"link set dev {cfg.dev['ifname']} down") |
| 147 | + defer(ip, f"link set dev {cfg.dev['ifname']} up") |
| 148 | + |
| 149 | + qstat2 = netfam.qstats_get({"ifindex": cfg.ifindex}, dump=True)[0] |
| 150 | + for k, v in qstat.items(): |
| 151 | + ksft_ge(qstat2[k], qstat[k], comment=f"{k} went backwards on device down") |
| 152 | + |
| 153 | + # exercise per-queue API to make sure that "device down" state |
| 154 | + # is handled correctly and doesn't crash |
| 155 | + netfam.qstats_get({"ifindex": cfg.ifindex, "scope": "queue"}, dump=True) |
| 156 | + |
| 157 | + |
136 | 158 | def main() -> None:
|
137 | 159 | with NetDrvEnv(__file__) as cfg:
|
138 |
| - ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex], |
| 160 | + ksft_run([check_pause, check_fec, pkt_byte_sum, qstat_by_ifindex, |
| 161 | + check_down], |
139 | 162 | args=(cfg, ))
|
140 | 163 | ksft_exit()
|
141 | 164 |
|
|
0 commit comments