diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2023-03-20 09:17:39 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2023-03-23 12:13:23 +1000 |
commit | dcea3653731cab70f4c7a5129e6f6a5ec1438a4d (patch) | |
tree | 316bb3872ffdacbd18fbb7973f6da8b175bd88c6 | |
parent | ec0041f116ea63fd842dc45b4c9c1ba419a4ba7c (diff) | |
download | libinput-dcea3653731cab70f4c7a5129e6f6a5ec1438a4d.tar.gz |
test: add a quicks file validation test
Now that we're Python ConfigParser compatible (again), we can check our
quirks file for things our actual parser doesn't care about, but that we
should honour. Right now that means that bustypes and vid/pid matches are
all spelled consistently.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r-- | meson.build | 7 | ||||
-rwxr-xr-x | test/test_quirks_files.py | 64 |
2 files changed, 71 insertions, 0 deletions
diff --git a/meson.build b/meson.build index 2d69d22c..58b900c5 100644 --- a/meson.build +++ b/meson.build @@ -478,6 +478,13 @@ test('validate-quirks', suite : ['all'] ) +quirks_file_tester = find_program('test/test_quirks_files.py') +test('validate-quirks-files', + quirks_file_tester, + suite : ['all'], + env: ['MESON_SOURCE_ROOT=@0@'.format(meson.project_source_root())], + ) + libinput_list_devices_sources = [ 'tools/libinput-list-devices.c' ] libinput_list_devices = executable('libinput-list-devices', libinput_list_devices_sources, diff --git a/test/test_quirks_files.py b/test/test_quirks_files.py new file mode 100755 index 00000000..91f00740 --- /dev/null +++ b/test/test_quirks_files.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# +# This file is formatted with Python Black +# +# Run with pytest + +from pathlib import Path + +import configparser +import os +import pytest +import re + + +def quirksdir(): + return Path(os.getenv("MESON_SOURCE_ROOT") or ".") / "quirks" + + +def pytest_generate_tests(metafunc): + # for any function that takes a "quirksfile" argument return the path to + # a quirks file + if "quirksfile" in metafunc.fixturenames: + metafunc.parametrize("quirksfile", [f for f in quirksdir().glob("*.quirks")]) + + +def test_matches_are_valid(quirksfile): + quirks = configparser.ConfigParser(strict=True) + # Don't convert to lowercase + quirks.optionxform = lambda option: option # type: ignore + quirks.read(quirksfile) + + for name, section in filter(lambda n: n != "DEFAULT", quirks.items()): + bus = section.get("MatchBus") + if bus is not None: + assert bus in ("ps2", "usb", "bluetooth", "i2c", "spi") + + vid = section.get("MatchVendor") + if vid is not None: + assert re.match( + "0x[0-9A-F]{4}", vid + ), f"{quirksfile}: {name}: {vid} must be uppercase hex (0xAB12)" + + pid = section.get("MatchProduct") + if pid is not None: + assert re.match( + "0x[0-9A-F]{4}", pid + ), f"{quirksfile}: {name}: {pid} must be uppercase hex (0xAB12)" + + +def main(): + args = [__file__] + try: + import xdist # noqa + + ncores = os.environ.get("FDO_CI_CONCURRENT", "auto") + args += ["-n", ncores] + except ImportError: + pass + + return pytest.main(args) + + +if __name__ == "__main__": + raise SystemExit(main()) |