[PATCH 05/10] testutilsqemu: Introduce 'testQemuInsertRealCaps' helper

Peter Krempa pkrempa at redhat.com
Tue Jul 4 13:40:14 UTC 2023


'testQemuInsertRealCaps' looks up and inserts real capabilities into the
capability 'file cache' for testing purposes. Effectively this helper
replaces following steps:

1) testQemuGetRealCaps
2) virFileCacheClear
3) qemuTestCapsCacheInsert

This helper doesn't copy the capabilities that are borrowed from it's
internal cache thus they must not be modified afterwards in contrast to
the above steps.

The use of this helper is in simple tests which require some form of
capabilities to parse a definition but don't care about doctoring them
in any way.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tests/testutilsqemu.c | 45 +++++++++++++++++++++++++++++++++++++++++++
 tests/testutilsqemu.h | 10 ++++++++++
 2 files changed, 55 insertions(+)

diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 0a42e59c59..e0b58b1d5d 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -976,6 +976,51 @@ testQemuGetRealCaps(const char *arch,
 }


+/**
+ * testQemuInsertRealCaps:
+ *
+ * @arch: architecture to fetch caps for
+ * @version: qemu version to fetch caps for ("latest" for fetching the latest version from @capsLatestFiles)
+ * @variant: capabilities variant to fetch caps for
+ * @capsLatestFiles: hash table containing latest version of capabilities for the  @arch+ at variant tuple
+ * @capsCache: hash table filled with the cache of capabilities
+ * @schemaCache: hash table for caching QMP schemas (may be NULL, see below)
+ * @schema: Filled with the QMP schema (hash table) (may be NULL, see below)
+ *
+ * Fetches and inserts into the test capability cache the appropriate virQEMUCaps
+ * for the @arch+ at version+@variant tuple. Note that the data inserted into
+ * the cache is borrowed from the cache thus must not be further modified.
+ *
+ * If @schemaCache and @schema are non-NULL, @schema is filled with with a
+ * pointer (borrowed from the cache) to the hash table representing the QEMU QMP
+ * schema used for validation of the monitor traffic.
+ */
+int
+testQemuInsertRealCaps(virFileCache *cache,
+                       const char *arch,
+                       const char *version,
+                       const char *variant,
+                       GHashTable *capsLatestFiles,
+                       GHashTable *capsCache,
+                       GHashTable *schemaCache,
+                       GHashTable **schema)
+{
+    virQEMUCaps *cachedcaps;
+
+    virFileCacheClear(cache);
+
+    if (!(cachedcaps = testQemuGetRealCapsInternal(arch, version, variant,
+                                                  capsLatestFiles, capsCache,
+                                                  schemaCache, schema)))
+        return -1;
+
+    if (qemuTestCapsCacheInsertData(cache, virQEMUCapsGetBinary(cachedcaps), cachedcaps) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 int
 testQemuInfoInitArgs(struct testQemuInfo *info)
 {
diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h
index 1e6611daa3..e0d116336e 100644
--- a/tests/testutilsqemu.h
+++ b/tests/testutilsqemu.h
@@ -160,4 +160,14 @@ testQemuGetRealCaps(const char *arch,
                     GHashTable *capsCache,
                     GHashTable *schemaCache,
                     GHashTable **schema);
+
+int
+testQemuInsertRealCaps(virFileCache *cache,
+                       const char *arch,
+                       const char *version,
+                       const char *variant,
+                       GHashTable *capsLatestFiles,
+                       GHashTable *capsCache,
+                       GHashTable *schemaCache,
+                       GHashTable **schema);
 #endif
-- 
2.41.0



More information about the libvir-list mailing list