]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuTestCapsCacheInsertImpl: Require that callers always pass capabilities
authorPeter Krempa <pkrempa@redhat.com>
Fri, 3 Mar 2023 11:42:05 +0000 (12:42 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 6 Mar 2023 19:55:50 +0000 (20:55 +0100)
There's just one case when we're populating the cache with empty caps so
that can allocate a dummy virQEMUCaps object rather than having the
logic inside qemuTestCapsCacheInsertImpl.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tests/testutilsqemu.c

index d88b21b9878ff8e4b29f375aa73271afebf0bf32..7dd7caf5096d2c0e0c028912f122a1400a505704 100644 (file)
@@ -495,7 +495,7 @@ qemuTestCapsCacheInsertImpl(virFileCache *cache,
 {
     size_t i;
 
-    if (caps && virQEMUCapsGetArch(caps) != VIR_ARCH_NONE) {
+    if (virQEMUCapsGetArch(caps) != VIR_ARCH_NONE) {
         /* all tests using real caps or arcitecture are expected to call:
          *
          *  virFileCacheClear(driver.qemuCapsCache);
@@ -534,10 +534,7 @@ qemuTestCapsCacheInsertImpl(virFileCache *cache,
             if (qemu_emulators[i] == NULL)
                 continue;
 
-            if (caps)
-                tmp = virQEMUCapsNewCopy(caps);
-            else
-                tmp = virQEMUCapsNew();
+            tmp = virQEMUCapsNewCopy(caps);
 
             qemuTestCapsPopulateFakeMachines(tmp, i, hostOS);
 
@@ -573,6 +570,7 @@ int qemuTestDriverInit(virQEMUDriver *driver)
     virSecurityManager *mgr = NULL;
     char statedir[] = STATEDIRTEMPLATE;
     char configdir[] = CONFIGDIRTEMPLATE;
+    g_autoptr(virQEMUCaps) emptyCaps = NULL;
 
     memset(driver, 0, sizeof(*driver));
 
@@ -643,7 +641,9 @@ int qemuTestDriverInit(virQEMUDriver *driver)
     if (!driver->xmlopt)
         goto error;
 
-    if (qemuTestCapsCacheInsert(driver->qemuCapsCache, NULL) < 0)
+    /* Populate the capabilities cache with fake empty caps */
+    emptyCaps = virQEMUCapsNew();
+    if (qemuTestCapsCacheInsert(driver->qemuCapsCache, emptyCaps) < 0)
         goto error;
 
     if (!(mgr = virSecurityManagerNew("none", "qemu",