tools/testing/selftests/drivers/net/stats.py

Source file repositories/reference/linux-study-clean/tools/testing/selftests/drivers/net/stats.py

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/drivers/net/stats.py
Extension
.py
Size
10872 bytes
Lines
322
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: tools
Status
atlas-only

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0

"""
Tests related to standard netdevice statistics.
"""

import errno
import subprocess
import time
from lib.py import ksft_run, ksft_exit, ksft_pr
from lib.py import ksft_ge, ksft_eq, ksft_is, ksft_in, ksft_lt, ksft_true, ksft_raises
from lib.py import KsftSkipEx, KsftFailEx
from lib.py import ksft_disruptive
from lib.py import EthtoolFamily, NetdevFamily, RtnlFamily, NlError
from lib.py import NetDrvEnv
from lib.py import cmd, ip, defer

ethnl = EthtoolFamily()
netfam = NetdevFamily()
rtnl = RtnlFamily()


def check_pause(cfg) -> None:
    """
    Check that drivers which support Pause config also report standard
    pause stats.
    """

    try:
        ethnl.pause_get({"header": {"dev-index": cfg.ifindex}})
    except NlError as e:
        if e.error == errno.EOPNOTSUPP:
            raise KsftSkipEx("pause not supported by the device") from e
        raise

    data = ethnl.pause_get({"header": {"dev-index": cfg.ifindex,
                                       "flags": {'stats'}}})
    ksft_true(data['stats'], "driver does not report stats")


def check_fec(cfg) -> None:
    """
    Check that drivers which support FEC config also report standard
    FEC stats.
    """

    try:
        ethnl.fec_get({"header": {"dev-index": cfg.ifindex}})
    except NlError as e:
        if e.error == errno.EOPNOTSUPP:
            raise KsftSkipEx("FEC not supported by the device") from e
        raise

    data = ethnl.fec_get({"header": {"dev-index": cfg.ifindex,
                                     "flags": {'stats'}}})
    ksft_true(data['stats'], "driver does not report stats")


def check_fec_hist(cfg) -> None:
    """
    Check that drivers which support FEC histogram statistics report
    reasonable values.
    """

    try:
        data = ethnl.fec_get({"header": {"dev-index": cfg.ifindex,
                                         "flags": {'stats'}}})
    except NlError as e:
        if e.error == errno.EOPNOTSUPP:

Annotation

Implementation Notes