Skip to content

Commit

Permalink
mpflash test: dump port listing in CI environment
Browse files Browse the repository at this point in the history
Signed-off-by: Jos Verlinde <Jos.Verlinde@microsoft.com>
  • Loading branch information
Josverl committed Dec 16, 2024
1 parent 4b15e4d commit 85e598b
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mpflash/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Shared Pytest configuration and fixtures for mpflash tests."""

import sys
from pathlib import Path

import pytest
Expand All @@ -9,3 +10,15 @@
def test_fw_path():
"""Return the path to the test firmware folder."""
return Path(__file__).parent / "data" / "firmware"


# --------------------------------------
# https://docs.pytest.org/en/stable/example/markers.html#marking-platform-specific-tests-with-pytest
ALL_OS = set("win32 linux darwin".split())


def pytest_runtest_setup(item):
supported_platforms = ALL_OS.intersection(mark.name for mark in item.iter_markers())
platform = sys.platform
if supported_platforms and platform not in supported_platforms:
pytest.skip("cannot run on platform {}".format(platform))
41 changes: 41 additions & 0 deletions src/mpflash/tests/test_filtered_comports.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,44 @@
"""


ci_linux_ports_json = """
[
{"description": "n/a", "device": "/dev/ttyS0", "device_path": "/sys/devices/pnp0/00:03/00:03:0/00:03:0.0", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS0", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS1", "device_path": "/sys/devices/pnp0/00:04/00:04:0/00:04:0.0", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS1", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS2", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.2", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS2", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS3", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.3", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS3", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS4", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.4", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS4", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS5", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.5", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS5", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS6", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.6", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS6", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS7", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.7", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS7", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS8", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.8", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS8", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS9", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.9", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS9", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS10", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.10", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS10", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS11", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.11", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS11", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS12", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.12", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS12", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS13", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.13", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS13", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS14", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.14", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS14", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS15", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.15", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS15", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS16", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.16", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS16", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS17", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.17", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS17", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS18", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.18", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS18", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS19", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.19", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS19", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS20", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.20", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS20", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS21", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.21", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS21", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS22", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.22", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS22", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS23", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.23", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS23", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS24", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.24", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS24", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS25", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.25", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS25", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS26", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.26", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS26", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS27", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.27", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS27", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS28", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.28", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS28", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS29", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.29", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS29", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS30", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.30", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS30", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null},
{"description": "n/a", "device": "/dev/ttyS31", "device_path": "/sys/devices/platform/serial8250/serial8250:0/serial8250:0.31", "hwid": "n/a", "interface": null, "location": null, "manufacturer": null, "name": "ttyS31", "pid": null, "product": null, "serial_number": null, "subsystem": "serial-base", "usb_device_path": null, "usb_interface_path": null, "vid": null}
]
"""


@pytest.mark.parametrize(
"id, include, ignore, bluetooth, expected",
[
Expand All @@ -57,6 +95,7 @@
("36-include-over", ["COM8", "COM9"], ["COM*"], False, ["COM8", "COM9"]),
],
)
@pytest.mark.win32
def test_filtered_comports_windows(id, include, ignore, bluetooth, expected, mocker):
windows_ports = jsons.loads(windows_ports_json, List[ListPortInfo])
mocker.patch("mpflash.common.list_ports.comports", return_value=windows_ports)
Expand All @@ -73,6 +112,7 @@ def test_filtered_comports_windows(id, include, ignore, bluetooth, expected, moc
("10-ignore", ["*"], ["/dev/tty001"], False, ["/dev/tty002"]),
],
)
@pytest.mark.linux
def test_filtered_comports_linux(id, include, ignore, bluetooth, expected, mocker):
linux_ports = [
ListPortInfo(device="/dev/tty001", skip_link_detection=True),
Expand All @@ -89,6 +129,7 @@ def test_filtered_comports_linux(id, include, ignore, bluetooth, expected, mocke
assert all([(d in expected) for d in devices])


@pytest.mark.linux
def test_skip_bogus_comports_linux(mocker):
linux_ports = [
ListPortInfo(device="/dev/tty001", skip_link_detection=True),
Expand Down

0 comments on commit 85e598b

Please sign in to comment.