~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/hid/tests/conftest.py

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/env python3
  2 # SPDX-License-Identifier: GPL-2.0
  3 # -*- coding: utf-8 -*-
  4 #
  5 # Copyright (c) 2017 Benjamin Tissoires <benjamin.tissoires@gmail.com>
  6 # Copyright (c) 2017 Red Hat, Inc.
  7 
  8 import platform
  9 import pytest
 10 import re
 11 import resource
 12 import subprocess
 13 from .base import HIDTestUdevRule
 14 from pathlib import Path
 15 
 16 
 17 # See the comment in HIDTestUdevRule, this doesn't set up but it will clean
 18 # up once the last test exited.
 19 @pytest.fixture(autouse=True, scope="session")
 20 def udev_rules_session_setup():
 21     with HIDTestUdevRule.instance():
 22         yield
 23 
 24 
 25 @pytest.fixture(autouse=True, scope="session")
 26 def setup_rlimit():
 27     resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
 28 
 29 
 30 @pytest.fixture(autouse=True, scope="session")
 31 def start_udevd(pytestconfig):
 32     if pytestconfig.getoption("udevd"):
 33         import subprocess
 34 
 35         with subprocess.Popen("/usr/lib/systemd/systemd-udevd") as proc:
 36             yield
 37             proc.kill()
 38     else:
 39         yield
 40 
 41 
 42 def pytest_configure(config):
 43     config.addinivalue_line(
 44         "markers",
 45         "skip_if_uhdev(condition, message): mark test to skip if the condition on the uhdev device is met",
 46     )
 47 
 48 
 49 # Generate the list of modules and modaliases
 50 # for the tests that need to be parametrized with those
 51 def pytest_generate_tests(metafunc):
 52     if "usbVidPid" in metafunc.fixturenames:
 53         modules = (
 54             Path("/lib/modules/")
 55             / platform.uname().release
 56             / "kernel"
 57             / "drivers"
 58             / "hid"
 59         )
 60 
 61         modalias_re = re.compile(r"alias:\s+hid:b0003g.*v([0-9a-fA-F]+)p([0-9a-fA-F]+)")
 62 
 63         params = []
 64         ids = []
 65         for module in modules.glob("*.ko"):
 66             p = subprocess.run(
 67                 ["modinfo", module], capture_output=True, check=True, encoding="utf-8"
 68             )
 69             for line in p.stdout.split("\n"):
 70                 m = modalias_re.match(line)
 71                 if m is not None:
 72                     vid, pid = m.groups()
 73                     vid = int(vid, 16)
 74                     pid = int(pid, 16)
 75                     params.append([module.name.replace(".ko", ""), vid, pid])
 76                     ids.append(f"{module.name} {vid:04x}:{pid:04x}")
 77         metafunc.parametrize("usbVidPid", params, ids=ids)
 78 
 79 
 80 def pytest_addoption(parser):
 81     parser.addoption("--udevd", action="store_true", default=False)

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php