Hi!

On 07/09/2026 12.30, Marc-André Lureau wrote:
Read config-host.h and skip tests that rely on some CONFIG_*
values.

Signed-off-by: Marc-André Lureau <[email protected]>
---
  tests/functional/qemu_test/__init__.py   |  2 +-
  tests/functional/qemu_test/decorators.py | 25 +++++++++++++++++++++++++
  2 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/tests/functional/qemu_test/__init__.py 
b/tests/functional/qemu_test/__init__.py
index 03e5c73d39dc..e21fa8279281 100644
--- a/tests/functional/qemu_test/__init__.py
+++ b/tests/functional/qemu_test/__init__.py
@@ -16,7 +16,7 @@
  from .decorators import skipIfMissingCommands, skipIfNotMachine, \
      skipFlakyTest, skipUntrustedTest, skipBigDataTest, skipSlowTest, \
      skipIfMissingImports, skipIfOperatingSystem, skipUnlessOperatingSystem, \
-    skipLockedMemoryTest, skipIfMissingEnv
+    skipLockedMemoryTest, skipIfMissingEnv, skipUnlessConfig
  from .archive import archive_extract
  from .uncompress import uncompress
  from .gdb import GDB
diff --git a/tests/functional/qemu_test/decorators.py 
b/tests/functional/qemu_test/decorators.py
index aa135acc7857..7a7d30503440 100644
--- a/tests/functional/qemu_test/decorators.py
+++ b/tests/functional/qemu_test/decorators.py
@@ -10,6 +10,7 @@
  from unittest import skipIf, skipUnless
from .cmd import which
+from .config import BUILD_DIR
def skipIfMissingEnv(*vars_):
@@ -162,6 +163,30 @@ def skipIfMissingImports(*args):
      return skipUnless(has_imports, 'required import(s) "%s" not installed' %
                                     ", ".join(args))
+def _read_config_host():
+    config = set()
+    with open(BUILD_DIR / "config-host.h", "r") as f:
+        for line in f:
+            if line.startswith("#define CONFIG_"):
+                name = line.split()[1].removeprefix("CONFIG_")
+                config.add(name)
+    return config
+
+_CONFIG_HOST = _read_config_host()

This always reads in config-host.h, also for tests that don't need the decorator ... could you change it so that the file is only read (once) if a test calls the skipUnlessConfig decorator?

Also I'm a little bit torn whether we really need a decorator for this or whether we should rather fence the tests in meson.build instead (similar to what we do in tests/qtest/meson.build with config_all_devices.has_key('...') already). What do others think about this?

 Thomas


+def skipUnlessConfig(*args):
+    '''
+    Decorator to skip execution of a test if the QEMU build
+    does not have the required CONFIG_* options enabled.
+    Example:
+
+      @skipUnlessConfig("PIXMAN")
+    '''
+    missing = [a for a in args if a not in _CONFIG_HOST]
+    return skipUnless(len(missing) == 0,
+                      'missing build config(s): %s' %
+                      ', '.join('CONFIG_' + m for m in missing))
+
  def skipLockedMemoryTest(locked_memory):
      '''
      Decorator to skip execution of a test if the system's



Reply via email to