diff --git a/proto/meson.build b/proto/meson.build index 58eaf71..df80334 100644 --- a/proto/meson.build +++ b/proto/meson.build @@ -1,6 +1,9 @@ -scanner = find_program('ei-scanner') -protocol_xml = files('protocol.xml') -protocol_dtd = files('protocol.dtd') +scanner_source = files('ei-scanner') +scanner = find_program(scanner_source) +protocol_xml_path = meson.current_source_dir() / 'protocol.xml' +protocol_dtd_path = meson.current_source_dir() / 'protocol.dtd' +protocol_xml = files(protocol_xml_path) +protocol_dtd = files(protocol_dtd_path) xmllint = find_program('xmllint', required: false) if xmllint.found() diff --git a/test/meson.build b/test/meson.build index 9038b42..cb2c221 100644 --- a/test/meson.build +++ b/test/meson.build @@ -149,7 +149,7 @@ if enable_pytest configuration: protocol_test_config) test('protocol-test', pytest, - args: pytest_args, + args: pytest_args + ['-k', 'TestEiProtocol'], suite: 'python', workdir: meson.project_build_root(), ) @@ -157,7 +157,7 @@ if enable_pytest env = environment() env.set('LIBEI_USE_VALGRIND', '1') test('protocol-test-valgrind', pytest, - args: pytest_args, + args: pytest_args + ['-k', 'TestEiProtocol'], suite: 'python', workdir: meson.project_build_root(), env: env @@ -174,6 +174,21 @@ if enable_pytest env: env, ) endif + + test_scanner_config = configuration_data() + test_scanner_config.set('PROTOFILE', protocol_xml_path) + + # ei-scanner can't be imported as-is in python, so we copy + rename it + configure_file(input: scanner_source, + output: 'eiscanner.py', + copy: true) + configure_file(input: 'test_scanner.py', + output: '@PLAINNAME@', + configuration: test_scanner_config) + test('scanner-pytest', pytest, + args: pytest_args + ['-k', 'TestScanner'], + suite: 'python', + workdir: meson.current_build_dir()) endif summary({'valgrind available': valgrind.found(), diff --git a/test/test_scanner.py b/test/test_scanner.py new file mode 100644 index 0000000..588664f --- /dev/null +++ b/test/test_scanner.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 + +# We can't import ei-scanner, so let's go via this route. The proper +# handling would be to have ei-scanner be the entry point for a ei_scanner +# module but.. well, one day we'll do that maybe. +import pytest + +try: + from eiscanner import parse, Protocol +except ImportError: + print("Run tests from within the build directory") + pytest.skip(allow_module_level=True) + +from pathlib import Path + +# set to the protocol file by meson +protofile = "@PROTOFILE@" + + +@pytest.fixture +def protocol_xml() -> Path: + return Path(protofile) + + +@pytest.fixture +def protocol(protocol_xml: Path, component: str) -> Protocol: + print(f"protocol for component {component}") + return parse(protocol_xml, component) + + +@pytest.mark.skipif( + protofile.startswith("@"), + reason="Protocol XML file path invalid, run tests in the build dir", +) +class TestScanner: + @pytest.mark.parametrize("component", ("eis", "ei", "brei")) + def test_ei_names(self, component: str, protocol: Protocol): + for interface in protocol.interfaces: + assert interface.name.startswith(component) + assert not interface.plainname.startswith(component) + assert not interface.plainname.startswith("ei_") + + # just some manual checks + assert "handshake" in [i.plainname for i in protocol.interfaces] + assert "connection" in [i.plainname for i in protocol.interfaces] + assert "button" in [i.plainname for i in protocol.interfaces]