2 # SPDX-License-Identifier: GPL-2.0
3 # -*- coding: utf-8 -*-
5 # Copyright (c) 2017 Benjamin Tissoires <benjamin.tissoires@gmail.com>
6 # Copyright (c) 2017 Red Hat, Inc.
13 from .base
import HIDTestUdevRule
14 from pathlib
import Path
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():
25 @pytest.fixture(autouse
=True, scope
="session")
27 resource
.setrlimit(resource
.RLIMIT_CORE
, (0, 0))
30 @pytest.fixture(autouse
=True, scope
="session")
31 def start_udevd(pytestconfig
):
32 if pytestconfig
.getoption("udevd"):
35 with subprocess
.Popen("/usr/lib/systemd/systemd-udevd") as proc
:
42 def pytest_configure(config
):
43 config
.addinivalue_line(
45 "skip_if_uhdev(condition, message): mark test to skip if the condition on the uhdev device is met",
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
:
55 / platform
.uname().release
61 modalias_re
= re
.compile(r
"alias:\s+hid:b0003g.*v([0-9a-fA-F]+)p([0-9a-fA-F]+)")
65 for module
in modules
.glob("*.ko"):
67 ["modinfo", module
], capture_output
=True, check
=True, encoding
="utf-8"
69 for line
in p
.stdout
.split("\n"):
70 m
= modalias_re
.match(line
)
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
)
80 def pytest_addoption(parser
):
81 parser
.addoption("--udevd", action
="store_true", default
=False)