[Concept,03/17] ulib: test: Add localqemu marker to skip tests in lab

Message ID 20260216013511.4079770-4-sjg@u-boot.org
State New
Headers
Series ulib: Add multi-arch demo and EFI app support |

Commit Message

Simon Glass Feb. 16, 2026, 1:34 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Some tests launch their own QEMU process via subprocess rather than
using the lab's managed U-Boot instance. In lab mode the locally
launched QEMU produces empty output, causing assertion failures.

There isn't really any point in running these tests on the lab since
they run happily in CI.

Add a 'localqemu' pytest marker and the corresponding setup_localqemu()
hook in conftest.py that skips marked tests when ubconfig.role is set.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 doc/develop/pytest/usage.rst |  9 +++++++++
 test/py/conftest.py          | 15 +++++++++++++++
 test/py/pytest.ini           |  1 +
 test/py/tests/test_ulib.py   |  1 +
 4 files changed, 26 insertions(+)
  

Patch

diff --git a/doc/develop/pytest/usage.rst b/doc/develop/pytest/usage.rst
index 9ba6ed429a9..32037d47dcd 100644
--- a/doc/develop/pytest/usage.rst
+++ b/doc/develop/pytest/usage.rst
@@ -596,3 +596,12 @@  option not to be set. The following annotation requires CONFIG_RISCV=n:
 .. code-block:: python
 
     @pytest.mark.notbuildconfigspec('riscv')
+
+The localqemu marker indicates that a test launches its own QEMU process
+rather than using the lab's managed U-Boot instance. Tests with this marker
+are automatically skipped when running in lab mode (i.e. when ``--role`` is
+set), since the locally launched QEMU is not available in that environment:
+
+.. code-block:: python
+
+    @pytest.mark.localqemu
diff --git a/test/py/conftest.py b/test/py/conftest.py
index eb64f2a82be..b7a03669751 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -818,6 +818,20 @@  def setup_role(item):
     if required_roles and ubconfig.role not in required_roles:
         pytest.skip(f'board "{ubconfig.role}" not supported')
 
+def setup_localqemu(item):
+    """Process any 'localqemu' marker for a test.
+
+    Skip this test if running in lab mode (i.e. role is set), since the
+    test launches its own QEMU rather than using the lab's U-Boot.
+
+    Args:
+        item (pytest.Item): The pytest test item
+    """
+    for _ in item.iter_markers('localqemu'):
+        if ubconfig.role:
+            pytest.skip('test requires local QEMU (not supported in lab)')
+        return
+
 def start_test_section(item):
     anchors[item.name] = log.start_section(item.name)
 
@@ -840,6 +854,7 @@  def pytest_runtest_setup(item):
     setup_requiredtool(item)
     setup_singlethread(item)
     setup_role(item)
+    setup_localqemu(item)
 
 def pytest_runtest_protocol(item, nextitem):
     """pytest hook: Called to execute a test.
diff --git a/test/py/pytest.ini b/test/py/pytest.ini
index 0a0268ec247..bebb22cd3d6 100644
--- a/test/py/pytest.ini
+++ b/test/py/pytest.ini
@@ -14,3 +14,4 @@  markers =
     slow: U-Boot: Specific test will run slowly.
     singlethread: Cannot run in parallel
     role: U-Boot: Indicates the lab 'role' which can execute this test
+    localqemu: U-Boot: Test launches its own QEMU, skip in lab mode
diff --git a/test/py/tests/test_ulib.py b/test/py/tests/test_ulib.py
index aff586c4d79..16af47fd840 100644
--- a/test/py/tests/test_ulib.py
+++ b/test/py/tests/test_ulib.py
@@ -210,6 +210,7 @@  def test_ulib_api_header(ubman):
     assert 'ub_snprintf(char *buf, size_t size, const char *fmt, ...)' in out
     assert 'ub_vprintf(const char *fmt, va_list args)' in out
 
+@pytest.mark.localqemu
 @pytest.mark.boardspec('qemu-x86')
 @pytest.mark.buildconfigspec("examples")
 def test_ulib_demo_rom(ubman):