tools/testing/selftests/net/lib/py/ksft.py

Source file repositories/reference/linux-study-clean/tools/testing/selftests/net/lib/py/ksft.py

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/net/lib/py/ksft.py
Extension
.py
Size
12766 bytes
Lines
469
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

# SPDX-License-Identifier: GPL-2.0

import fnmatch
import functools
import getopt
import inspect
import os
import signal
import sys
import time
import traceback
from collections import namedtuple
from .consts import KSFT_MAIN_NAME
from . import utils

KSFT_RESULT = None
KSFT_RESULT_ALL = True
KSFT_DISRUPTIVE = True


class KsftFailEx(Exception):
    pass


class KsftSkipEx(Exception):
    pass


class KsftXfailEx(Exception):
    pass


class KsftTerminate(KeyboardInterrupt):
    pass


class _KsftArgs:
    def __init__(self):
        self.list_tests = False
        self.filters = []

        try:
            opts, _ = getopt.getopt(sys.argv[1:], 'hlt:T:')
        except getopt.GetoptError as e:
            print(e, file=sys.stderr)
            sys.exit(1)

        for opt, val in opts:
            if opt == '-h':
                print(f"Usage: {sys.argv[0]} [-h|-l] [-t|-T name]\n"
                      f"\t-h       print help\n"
                      f"\t-l       list tests (filtered, if filters were specified)\n"
                      f"\t-t name  include test\n"
                      f"\t-T name  exclude test",
                      file=sys.stderr)
                sys.exit(0)
            elif opt == '-l':
                self.list_tests = True
            elif opt == '-t':
                self.filters.append((True, val))
            elif opt == '-T':
                self.filters.append((False, val))


@functools.lru_cache()
def _ksft_supports_color():
    if os.environ.get("NO_COLOR") is not None:
        return False
    if not hasattr(sys.stdout, "isatty") or not sys.stdout.isatty():
        return False

Annotation

Implementation Notes