Skip to contentSkip to conversation

tests/functional: Allow running TCG plugins tests on macOS

PATCH In review Philippe Mathieu-Daudé 5 participants 11 messages Feb 20, 2025 – Feb 27, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v2 cover tests/functional: Allow running TCG plugins tests on macOS

Pierrick kindly helped me to resolve this issue which ended being trivial (to him!). Not tested on Windows so far.

Since v1:
- Include Pierrick's meson fix patch (adding Fixes: tag)
- Addressed Thomas review comments (config.py, os.path.join)

Philippe Mathieu-Daudé (2):
tests/functional: Introduce the dso_suffix() helper tests/functional: Allow running TCG plugins tests on non-Linux/BSD
hosts

Pierrick Bouvier (1):
plugins: add explicit dependency in functional tests

 meson.build                                  |  1 +
 contrib/plugins/meson.build                  |  2 ++
 tests/functional/meson.build                 |  2 +-
 tests/functional/qemu_test/__init__.py       |  2 +-
 tests/functional/qemu_test/cmd.py            |  1 -
 tests/functional/qemu_test/config.py         |  6 ++++++
 tests/functional/test_aarch64_tcg_plugins.py | 11 ++++++++---
 tests/tcg/plugins/meson.build                |  2 ++
 8 files changed, 21 insertions(+), 6 deletions(-)
Signature · 1 line
2.47.1
#8 lore raw

PATCH v2 3/3 tests/functional: Allow running TCG plugins tests on non-Linux/BSD hosts

Not all platforms use the '.so' suffix for shared libraries, which is how plugins are built. Use the recently introduced dso_suffix() helper to get the proper host suffix.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2804

---
 tests/functional/test_aarch64_tcg_plugins.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
tests/functional/test_aarch64_tcg_plugins.py +8 -3
index 7e8beacc833..5736b60545a 100755
@@ -13,10 +13,11 @@
 
 import tempfile
 import mmap
+import os
 import re
 
 from qemu.machine.machine import VMLaunchFailure
-from qemu_test import LinuxKernelTest, Asset
+from qemu_test import LinuxKernelTest, Asset, dso_suffix
 
 
 class PluginKernelBase(LinuxKernelTest):
@@ -62,6 +63,10 @@ class PluginKernelNormal(PluginKernelBase):
         ('https://storage.tuxboot.com/20230331/arm64/Image'),
         'ce95a7101a5fecebe0fe630deee6bd97b32ba41bc8754090e9ad8961ea8674c7')
 
+    def plugin_file(self, plugin_name):
+        sfx = dso_suffix()
+        return os.path.join('tests', 'tcg', 'plugins', f'{plugin_name}.{sfx}')
+
     def test_aarch64_virt_insn(self):
         self.set_machine('virt')
         self.cpu='cortex-a53'
@@ -74,7 +79,7 @@ def test_aarch64_virt_insn(self):
                                                  suffix=".log")
 
         self.run_vm(kernel_path, kernel_command_line,
-                    "tests/tcg/plugins/libinsn.so", plugin_log.name,
+                    self.plugin_file('libinsn'), plugin_log.name,
                     console_pattern)
 
         with plugin_log as lf, \
@@ -100,7 +105,7 @@ def test_aarch64_virt_insn_icount(self):
                                                  suffix=".log")
 
         self.run_vm(kernel_path, kernel_command_line,
-                    "tests/tcg/plugins/libinsn.so", plugin_log.name,
+                    self.plugin_file('libinsn'), plugin_log.name,
                     console_pattern,
                     args=('-icount', 'shift=1'))
 
Signature · 1 line
2.47.1
#2 lore raw

PATCH v2 2/3 tests/functional: Introduce the dso_suffix() helper

In reply to Philippe Mathieu-Daudé

Introduce a helper to get the default shared library suffix used on the host.

---
 tests/functional/qemu_test/__init__.py | 2 +-
 tests/functional/qemu_test/cmd.py      | 1 -
 tests/functional/qemu_test/config.py   | 6 ++++++
 3 files changed, 7 insertions(+), 2 deletions(-)
tests/functional/qemu_test/__init__.py +1 -1
index 5c972843a6d..45f7befa374 100644
@@ -7,7 +7,7 @@
 
 
 from .asset import Asset
-from .config import BUILD_DIR
+from .config import BUILD_DIR, dso_suffix
 from .cmd import is_readable_executable_file, \
     interrupt_interactive_console_until_pattern, wait_for_console_pattern, \
     exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
tests/functional/qemu_test/cmd.py +0 -1
index dc5f422b77d..254e23ef748 100644
@@ -15,7 +15,6 @@
 import os
 import os.path
 
-
 def which(tool):
     """ looks up the full path for @tool, returns None if not found
         or if @tool does not have executable permissions.
tests/functional/qemu_test/config.py +6 -0
index edd75b7fd06..0eab1baa541 100644
@@ -13,6 +13,7 @@
 
 import os
 from pathlib import Path
+import platform
 
 
 def _source_dir():
@@ -34,3 +35,8 @@ def _build_dir():
     raise Exception("Cannot identify build dir, set QEMU_BUILD_ROOT")
 
 BUILD_DIR = _build_dir()
+
+def dso_suffix():
+    '''Return the dynamic libraries suffix for the current platform'''
+    DSO_SUFFIXES = { 'Linux': 'so', 'Darwin': 'dylib', 'Windows': 'dll' }
+    return DSO_SUFFIXES[platform.system()]
Signature · 1 line
2.47.1
#1 lore raw

PATCH v2 1/3 plugins: add explicit dependency in functional tests

In reply to Philippe Mathieu-Daudé

From: Pierrick Bouvier <[email protected]>

./tests/functional/test_aarch64_tcg_plugins.py needs to have plugin libinsn built. However, it's not listed as a dependency, so meson can't know it needs to be built.

Thus, we keep track of all plugins, and add them as an explicit dependency.

Fixes 4c134d07b9e ("tests: add a new set of tests to exercise plugins")
---
 meson.build                   | 1 +
 contrib/plugins/meson.build   | 2 ++
 tests/functional/meson.build  | 2 +-
 tests/tcg/plugins/meson.build | 2 ++
 4 files changed, 6 insertions(+), 1 deletion(-)
meson.build +1 -0
index 0ee79c664d3..4588bfd8642 100644
@@ -3657,6 +3657,7 @@ qtest_module_ss = ss.source_set()
 
 modules = {}
 target_modules = {}
+plugin_modules = []
 hw_arch = {}
 target_arch = {}
 target_system_arch = {}
contrib/plugins/meson.build +2 -0
index 484b9a808c8..fa8a426c8b5 100644
@@ -26,3 +26,5 @@ if t.length() > 0
 else
   run_target('contrib-plugins', command: find_program('true'))
 endif
+
+plugin_modules += t
tests/functional/meson.build +1 -1
index b516d21cba1..2d41908c0a8 100644
@@ -362,7 +362,7 @@ foreach speed : ['quick', 'thorough']
       # 'run_target' logic below & in Makefile.include
       test('func-' + testname,
            python,
-           depends: [test_deps, test_emulator, emulator_modules],
+           depends: [test_deps, test_emulator, emulator_modules, plugin_modules],
            env: test_env,
            args: [testpath],
            protocol: 'tap',
tests/tcg/plugins/meson.build +2 -0
index 87a17d67bd4..c8cb0626a6d 100644
@@ -19,3 +19,5 @@ if t.length() > 0
 else
   run_target('test-plugins', command: find_program('true'))
 endif
+
+plugin_modules += t
Signature · 1 line
2.47.1
#3 lore raw

Re: [PATCH v2 2/3] tests/functional: Introduce the dso_suffix() helper

In reply to Philippe Mathieu-Daudé
Quoted 18 lines · Philippe Mathieu-Daudé

Introduce a helper to get the default shared library suffix used on the host.

---
  tests/functional/qemu_test/__init__.py | 2 +-
  tests/functional/qemu_test/cmd.py      | 1 -
  tests/functional/qemu_test/config.py   | 6 ++++++
  3 files changed, 7 insertions(+), 2 deletions(-)
tests/functional/qemu_test/cmd.py +0 -0
index dc5f422b77d..254e23ef748 100644

tests/functional/qemu_test/cmd.py line 18

Quoted 4 lines
tests/functional/qemu_test/cmd.py +0 -1
@@ -15,7 +15,6 @@
  import os
  import os.path
 
-

Oops, Alex, should I respin a v3 removing this change?

Quoted 3 lines
tests/functional/qemu_test/cmd.py +0 -0
  def which(tool):
      """ looks up the full path for @tool, returns None if not found
          or if @tool does not have executable permissions.
Reviewed-by on v2 2/3
#4 lore raw

Re: [PATCH v2 2/3] tests/functional: Introduce the dso_suffix() helper

In reply to Philippe Mathieu-Daudé
Quoted 30 lines · Philippe Mathieu-Daudé

Introduce a helper to get the default shared library suffix used on the host.

---
  tests/functional/qemu_test/__init__.py | 2 +-
  tests/functional/qemu_test/cmd.py      | 1 -
  tests/functional/qemu_test/config.py   | 6 ++++++
  3 files changed, 7 insertions(+), 2 deletions(-)
tests/functional/qemu_test/__init__.py +1 -1
index 5c972843a6d..45f7befa374 100644
@@ -7,7 +7,7 @@
 
 
  from .asset import Asset
-from .config import BUILD_DIR
+from .config import BUILD_DIR, dso_suffix
  from .cmd import is_readable_executable_file, \
      interrupt_interactive_console_until_pattern, wait_for_console_pattern, \
      exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
tests/functional/qemu_test/cmd.py +0 -0
index dc5f422b77d..254e23ef748 100644

tests/functional/qemu_test/cmd.py line 20

Quoted 7 lines
tests/functional/qemu_test/cmd.py +0 -1
@@ -15,7 +15,6 @@
  import os
  import os.path
 
-
  def which(tool):
      """ looks up the full path for @tool, returns None if not found
          or if @tool does not have executable permissions.

Please drop the change to cmd.py now.
With that fixed:

Reviewed-by on v2 3/3
#9 lore raw

Re: [PATCH v2 3/3] tests/functional: Allow running TCG plugins tests on non-Linux/BSD hosts

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Not all platforms use the '.so' suffix for shared libraries, which is how plugins are built. Use the recently introduced dso_suffix() helper to get the proper host suffix.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2804

---

#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 15 lines · Philippe Mathieu-Daudé

Pierrick kindly helped me to resolve this issue which ended being trivial (to him!). Not tested on Windows so far.

Since v1:
- Include Pierrick's meson fix patch (adding Fixes: tag)
- Addressed Thomas review comments (config.py, os.path.join)

Philippe Mathieu-Daudé (2):
tests/functional: Introduce the dso_suffix() helper tests/functional: Allow running TCG plugins tests on non-Linux/BSD
hosts

Pierrick Bouvier (1):
plugins: add explicit dependency in functional tests

Quoted 9 lines
 meson.build                                  |  1 +
 contrib/plugins/meson.build                  |  2 ++
 tests/functional/meson.build                 |  2 +-
 tests/functional/qemu_test/__init__.py       |  2 +-
 tests/functional/qemu_test/cmd.py            |  1 -
 tests/functional/qemu_test/config.py         |  6 ++++++
 tests/functional/test_aarch64_tcg_plugins.py | 11 ++++++++---
 tests/tcg/plugins/meson.build                |  2 ++
 8 files changed, 21 insertions(+), 6 deletions(-)

Queued to testing/next (I fixed the cmd.py whitespace change), thanks.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#5 lore raw

Re: [PATCH v2 2/3] tests/functional: Introduce the dso_suffix() helper

In reply to Philippe Mathieu-Daudé
Quoted 50 lines · Philippe Mathieu-Daudé

Introduce a helper to get the default shared library suffix used on the host.

---
  tests/functional/qemu_test/__init__.py | 2 +-
  tests/functional/qemu_test/cmd.py      | 1 -
  tests/functional/qemu_test/config.py   | 6 ++++++
  3 files changed, 7 insertions(+), 2 deletions(-)
tests/functional/qemu_test/__init__.py +1 -1
index 5c972843a6d..45f7befa374 100644
@@ -7,7 +7,7 @@
 
 
  from .asset import Asset
-from .config import BUILD_DIR
+from .config import BUILD_DIR, dso_suffix
  from .cmd import is_readable_executable_file, \
      interrupt_interactive_console_until_pattern, wait_for_console_pattern, \
      exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
tests/functional/qemu_test/cmd.py +0 -1
index dc5f422b77d..254e23ef748 100644
@@ -15,7 +15,6 @@
  import os
  import os.path
 
-
  def which(tool):
      """ looks up the full path for @tool, returns None if not found
          or if @tool does not have executable permissions.
tests/functional/qemu_test/config.py +1 -0
index edd75b7fd06..0eab1baa541 100644
@@ -13,6 +13,7 @@
 
  import os
  from pathlib import Path
+import platform
 
 
  def _source_dir():

tests/functional/qemu_test/config.py def _build_dir(): · line 41

Quoted 7 lines
tests/functional/qemu_test/config.py +4 -0
@@ -34,3 +35,8 @@ def _build_dir():
      raise Exception("Cannot identify build dir, set QEMU_BUILD_ROOT")
 
  BUILD_DIR = _build_dir()
+
+def dso_suffix():
+    '''Return the dynamic libraries suffix for the current platform'''
+    DSO_SUFFIXES = { 'Linux': 'so', 'Darwin': 'dylib', 'Windows': 'dll' }> +    return DSO_SUFFIXES[platform.system()]

It may be too late to comment, but:
I'm a bit worried that this can break tests on platforms (BSDs?) not listed here though I don't know if plugin tests work on BSDs in the first place.

#6 lore raw

Re: [PATCH v2 2/3] tests/functional: Introduce the dso_suffix() helper

Quoted 47 lines · Akihiko Odaki
Quoted 46 lines · Philippe Mathieu-Daudé

Introduce a helper to get the default shared library suffix used on the host.

---
  tests/functional/qemu_test/__init__.py | 2 +-
  tests/functional/qemu_test/cmd.py      | 1 -
  tests/functional/qemu_test/config.py   | 6 ++++++
  3 files changed, 7 insertions(+), 2 deletions(-)
tests/functional/qemu_test/__init__.py +1 -1
index 5c972843a6d..45f7befa374 100644
@@ -7,7 +7,7 @@
      from .asset import Asset
-from .config import BUILD_DIR
+from .config import BUILD_DIR, dso_suffix
  from .cmd import is_readable_executable_file, \
      interrupt_interactive_console_until_pattern, wait_for_console_pattern, \
      exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
tests/functional/qemu_test/cmd.py +0 -0
index dc5f422b77d..254e23ef748 100644
@@ -15,7 +15,6 @@
  import os
  import os.path
  -
  def which(tool):
      """ looks up the full path for @tool, returns None if not found
          or if @tool does not have executable permissions.
tests/functional/qemu_test/config.py +2 -0
index edd75b7fd06..0eab1baa541 100644
@@ -13,6 +13,7 @@
    import os
  from pathlib import Path
+import platform
      def _source_dir():
@@ -34,3 +35,8 @@ def _build_dir():
      raise Exception("Cannot identify build dir, set QEMU_BUILD_ROOT")
    BUILD_DIR = _build_dir()
+
Quoted 8 lines

tests/functional/qemu_test/config.py def _build_dir():

Quoted 3 lines
tests/functional/qemu_test/config.py +3 -0
+def dso_suffix():
+    '''Return the dynamic libraries suffix for the current platform'''
+    DSO_SUFFIXES = { 'Linux': 'so', 'Darwin': 'dylib', 'Windows': 'dll' }> +    return DSO_SUFFIXES[platform.system()]

It may be too late to comment, but:
I'm a bit worried that this can break tests on platforms (BSDs?) not listed here though I don't know if plugin tests work on BSDs in the first place.

Currently we don't run any of the check-tcg tests on BSD. Mostly because I couldn't find cross compilers packaged for BSD (and there is no docker-like thing to bring them in) and for the "native" cross compiler we currently block clang - although there are some fixes for that in my current maintainer series.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#7 lore raw

Re: [PATCH v2 2/3] tests/functional: Introduce the dso_suffix() helper

In reply to Philippe Mathieu-Daudé
Quoted 50 lines · Philippe Mathieu-Daudé

Introduce a helper to get the default shared library suffix used on the host.

---
 tests/functional/qemu_test/__init__.py | 2 +-
 tests/functional/qemu_test/cmd.py      | 1 -
 tests/functional/qemu_test/config.py   | 6 ++++++
 3 files changed, 7 insertions(+), 2 deletions(-)
tests/functional/qemu_test/__init__.py +1 -1
index 5c972843a6d..45f7befa374 100644
@@ -7,7 +7,7 @@
 
 
 from .asset import Asset
-from .config import BUILD_DIR
+from .config import BUILD_DIR, dso_suffix
 from .cmd import is_readable_executable_file, \
     interrupt_interactive_console_until_pattern, wait_for_console_pattern, \
     exec_command, exec_command_and_wait_for_pattern, get_qemu_img, which
tests/functional/qemu_test/cmd.py +0 -1
index dc5f422b77d..254e23ef748 100644
@@ -15,7 +15,6 @@
 import os
 import os.path
 
-
 def which(tool):
     """ looks up the full path for @tool, returns None if not found
         or if @tool does not have executable permissions.
tests/functional/qemu_test/config.py +1 -0
index edd75b7fd06..0eab1baa541 100644
@@ -13,6 +13,7 @@
 
 import os
 from pathlib import Path
+import platform
 
 
 def _source_dir():

tests/functional/qemu_test/config.py def _build_dir(): · line 42

Quoted 8 lines
tests/functional/qemu_test/config.py +5 -0
@@ -34,3 +35,8 @@ def _build_dir():
     raise Exception("Cannot identify build dir, set QEMU_BUILD_ROOT")
 
 BUILD_DIR = _build_dir()
+
+def dso_suffix():
+    '''Return the dynamic libraries suffix for the current platform'''
+    DSO_SUFFIXES = { 'Linux': 'so', 'Darwin': 'dylib', 'Windows': 'dll' }
+    return DSO_SUFFIXES[platform.system()]

Windows and Darwin are the two odd-ball platforms we target, Linux and all the BSDs use .so, so it makes sense to use .so as the general fallback, at which point I'm not sure the lookup table is worthwhile compared to:

if platform.system() == "Darwin"
return "dylib"
elif platform.system() == "Windows"
return "dll"
else
return "so"

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|