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()
+
+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

-- 
2.55.0.543.g5ebe2ebe4ea8


Reply via email to