File: test-db.py

package info (click to toggle)
xr-hardware 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 220 kB
  • sloc: python: 244; makefile: 40
file content (35 lines) | stat: -rwxr-xr-x 1,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# Copyright 2019-2024, Collabora, Ltd.
# SPDX-License-Identifier: BSL-1.0
#
# Original Author: Rylie Pavlik <rylie.pavlik@collabora.com>
"""XR Hardware device database consistency test."""
from xrhardware.db import get_devices

if __name__ == "__main__":
    print("Testing device database entries' consistency and uniqueness")
    known = set()
    import re

    hexstring = re.compile(r"[0-9a-fA-F]{4}")
    for dev in get_devices():
        print("Checking entry for:", dev.extended_description)

        # Duplicate ID?
        for dev_id in dev.yield_hwdb_identification():
            assert dev_id not in known
            known.add(dev_id)

        # Must be at least one of these
        assert dev.usb or dev.bluetooth

        # VID/PID must fit the expected format
        if dev.pid:
            assert hexstring.match(dev.pid)
            # prefer lowercase for compatibility
            assert dev.pid == dev.pid.lower()
        if dev.vid:
            assert hexstring.match(dev.vid)
            # prefer lowercase for compatibility
            assert dev.vid == dev.vid.lower()
    print("Success!")