[PATCH 2/2] tests: Deduplicate some WITH_* checks

Michal Privoznik mprivozn at redhat.com
Mon Apr 25 10:37:34 UTC 2022


When constructing mock_libs array it is firstly initialized to a
static set of mocks followed by couple of WITH_* checks to append
driver specific mocks. These checks are then repeated when
filling some other variables (e.g. supplementary helpers,
libraries, tests, etc.). Dissolve the former in the latter since
we are already doing that, partially, for qemu (qemucapsprobemock
and qemuhotplugmock)

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tests/meson.build | 92 +++++++++++++++++++++--------------------------
 1 file changed, 40 insertions(+), 52 deletions(-)

diff --git a/tests/meson.build b/tests/meson.build
index 8d613d23f2..9b9fcaa622 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -84,40 +84,6 @@ if host_machine.system() == 'linux'
   ]
 endif
 
-if conf.has('WITH_BHYVE')
-  mock_libs += [
-    { 'name': 'bhyveargv2xmlmock' },
-    { 'name': 'bhyvexml2argvmock' },
-  ]
-endif
-
-if conf.has('WITH_LIBXL')
-  mock_libs += [
-    { 'name': 'xlmock', 'sources': [ 'libxlmock.c' ], 'deps': [ libxl_dep ] },
-  ]
-endif
-
-if conf.has('WITH_NSS')
-  mock_libs += [
-    { 'name': 'nssmock' },
-  ]
-endif
-
-if conf.has('WITH_QEMU')
-  mock_libs += [
-    { 'name': 'qemucaps2xmlmock' },
-    { 'name': 'qemucpumock' },
-    { 'name': 'qemuxml2argvmock' },
-    { 'name': 'virhostidmock' },
-  ]
-endif
-
-if conf.has('WITH_SECDRIVER_SELINUX')
-  mock_libs += [
-    { 'name': 'securityselinuxhelper' },
-  ]
-endif
-
 
 # build libraries used by tests
 
@@ -139,6 +105,10 @@ if conf.has('WITH_LIBXL')
     link_whole: [ libxl_driver_imp ],
     link_with: [ libvirt_lib ],
   )
+
+  mock_libs += [
+    { 'name': 'xlmock', 'sources': [ 'libxlmock.c' ], 'deps': [ libxl_dep ] },
+  ]
 else
   test_utils_xen_lib = []
   test_xen_driver_lib = []
@@ -176,8 +146,12 @@ if conf.has('WITH_QEMU')
   )
 
   mock_libs += [
+    { 'name': 'qemucaps2xmlmock' },
     { 'name': 'qemucapsprobemock', 'link_with': [ test_qemu_driver_lib ] },
+    { 'name': 'qemucpumock' },
     { 'name': 'qemuhotplugmock', 'link_with': [ test_utils_qemu_lib, test_utils_lib ] },
+    { 'name': 'qemuxml2argvmock' },
+    { 'name': 'virhostidmock' },
   ]
 else
   test_qemu_driver_lib = []
@@ -192,24 +166,6 @@ test_file_wrapper_lib = static_library(
 )
 
 tests_deps = []
-foreach mock : mock_libs
-  tests_deps += shared_library(
-    mock['name'],
-    mock.get('sources', [ '@0 at .c'.format(mock['name']) ]),
-    override_options: [
-     'b_asneeded=false',
-     'b_lundef=false',
-    ],
-    dependencies: [
-      tests_dep,
-      mock.get('deps', []),
-    ],
-    link_with: [
-      libvirt_lib,
-      mock.get('link_with', []),
-    ],
-  )
-endforeach
 
 # build helpers used by tests
 
@@ -367,6 +323,11 @@ if conf.has('WITH_BHYVE')
     { 'name': 'bhyvexml2argvtest', 'link_with': [ bhyve_driver_impl ] },
     { 'name': 'bhyvexml2xmltest', 'link_with': [ bhyve_driver_impl ] },
   ]
+
+  mock_libs += [
+    { 'name': 'bhyveargv2xmlmock' },
+    { 'name': 'bhyvexml2argvmock' },
+  ]
 endif
 
 if conf.has('WITH_ESX')
@@ -428,6 +389,10 @@ if conf.has('WITH_NSS')
       'link_with': [ nss_libvirt_guest_impl ],
     },
   ]
+
+  mock_libs += [
+    { 'name': 'nssmock' },
+  ]
 endif
 
 if conf.has('WITH_NWFILTER')
@@ -506,6 +471,10 @@ if conf.has('WITH_SECDRIVER_SELINUX')
       ]
     endif
   endif
+
+  mock_libs += [
+    { 'name': 'securityselinuxhelper' },
+  ]
 endif
 
 if conf.has('WITH_STORAGE')
@@ -556,6 +525,25 @@ if conf.has('WITH_YAJL')
   ]
 endif
 
+foreach mock : mock_libs
+  tests_deps += shared_library(
+    mock['name'],
+    mock.get('sources', [ '@0 at .c'.format(mock['name']) ]),
+    override_options: [
+     'b_asneeded=false',
+     'b_lundef=false',
+    ],
+    dependencies: [
+      tests_dep,
+      mock.get('deps', []),
+    ],
+    link_with: [
+      libvirt_lib,
+      mock.get('link_with', []),
+    ],
+  )
+endforeach
+
 foreach data : tests
   test_sources = '@0 at .c'.format(data['name'])
   test_bin = executable(
-- 
2.35.1



More information about the libvir-list mailing list