Lines Matching +full:self +full:- +full:test

2 # SPDX-License-Identifier: GPL-2.0
3 # -*- coding: utf-8 -*-
21 logger = logging.getLogger("hidtools.test.base")
138 def __init__(self, name, application, rdesc_str=None, rdesc=None, input_info=None): argument
140 self.application_matches = application_matches
142 name = f"uhid test {self.__class__.__name__}"
143 if not name.startswith("uhid test "):
144 name = "uhid test " + self.name
145 self.name = name
156 # List of kernel modules to load before starting the test
157 # if any module is not available (not compiled), the test will skip.
159 # for example ("playstation", "hid-playstation")
162 # List of in kernel HID-BPF object files to load
163 # before starting the test
164 # Any existing pre-loaded HID-BPF module will be removed
167 # for example '("xppen-ArtistPro16Gen2.bpf.o", True)'
168 # If 'rdesc_fixup_present' is True, the test needs to wait
173 def assertInputEventsIn(self, expected_events, effective_events): argument
180 def assertInputEvents(self, expected_events, effective_events): argument
181 remaining = self.assertInputEventsIn(expected_events, effective_events)
215 def create_device(self): argument
218 def _load_kernel_module(self, kernel_driver, kernel_module): argument
225 sysfs_path = Path("/sys/module") / kernel_module.replace("-", "_")
230 f"module {kernel_module} could not be loaded, skipping the test"
234 def load_kernel_module(self): argument
235 for kernel_driver, kernel_module in self.kernel_modules:
236 self._load_kernel_module(kernel_driver, kernel_module)
239 def load_hid_bpfs(self): argument
244 udev_hid_bpf = shutil.which("udev-hid-bpf")
246 pytest.skip("udev-hid-bpf not found in $PATH, skipping")
249 for _, rdesc_fixup in self.hid_bpfs:
253 for hid_bpf, _ in self.hid_bpfs:
254 # We need to start `udev-hid-bpf` in the background
259 "udev-hid-bpf",
260 "--verbose",
262 str(self.uhdev.sys_path),
267 self.uhdev.dispatch(1)
271 f"Couldn't insert hid-bpf program '{hid_bpf}', marking the test as failed"
275 # the HID-BPF program exports a rdesc fixup, so it needs to be
278 # uhid loading, and then the reload from HID-BPF)
280 while self.uhdev.kernel_ready_count < 2 and time.time() - now < 2:
281 self.uhdev.dispatch(1)
283 if self.uhdev.kernel_ready_count < 2:
285 f"Couldn't insert hid-bpf programs, marking the test as failed"
288 def unload_hid_bpfs(self): argument
290 ["udev-hid-bpf", "--verbose", "remove", str(self.uhdev.sys_path)],
294 f"Couldn't unload hid-bpf programs, marking the test as failed"
298 def new_uhdev(self, load_kernel_module): argument
299 return self.create_device()
301 def assertName(self, uhdev): argument
306 def context(self, new_uhdev, request): argument
309 with new_uhdev as self.uhdev:
311 test, message, *rest = skip_cond.args
313 if test(self.uhdev):
316 self.uhdev.create_kernel_device()
318 while not self.uhdev.is_ready() and time.time() - now < 5:
319 self.uhdev.dispatch(1)
321 if self.hid_bpfs:
322 self.load_hid_bpfs()
324 if self.uhdev.get_evdev() is None:
326 … f"available list of input nodes: (default application is '{self.uhdev.application}')"
328 logger.warning(self.uhdev.input_nodes)
330 if self.hid_bpfs:
331 self.unload_hid_bpfs()
332 self.uhdev = None
337 def check_taint(self): argument
346 def test_creation(self): argument
352 uhdev = self.uhdev
355 self.assertName(uhdev)
363 A context-manager compatible class that sets up our udev rules file and
366 This class is tailored to our test setup: it only sets up the udev rule
369 the session once, then once for each test (the first of which will
370 trigger the udev rule) and once the last test exited and the session
374 def __init__(self): argument
375 self.refs = 0
376 self.rulesfile = None
378 def __enter__(self): argument
379 self.refs += 1
380 if self.refs == 2 and self.rulesfile is None:
381 self.create_udev_rule()
382 self.reload_udev_rules()
384 def __exit__(self, exc_type, exc_value, traceback): argument
385 self.refs -= 1
386 if self.refs == 0 and self.rulesfile:
387 os.remove(self.rulesfile.name)
388 self.reload_udev_rules()
390 def reload_udev_rules(self): argument
391 subprocess.run("udevadm control --reload-rules".split())
392 subprocess.run("systemd-hwdb update".split())
394 def create_udev_rule(self): argument
399 prefix="91-uhid-test-device-REMOVEME-",
407 KERNELS=="*input*", ATTRS{name}=="*uhid test *", ENV{LIBINPUT_IGNORE_DEVICE}="1"
408 KERNELS=="*hid*", ENV{HID_NAME}=="*uhid test *", ENV{HID_BPF_IGNORE_DEVICE}="1"
409 KERNELS=="*input*", ATTRS{name}=="*uhid test * System Multi Axis", ENV{ID_INPUT_TOUCHSCREEN}="", EN…
412 self.rulesfile = f