testutils: Turn 'virTestDummyFDContext' into a proper type

'virTestDummyFDContext' was a copy of GHashTable to be able to register
a cleanup function. Upcoming patches will want to track more data
together with the hash table so turn virTestDummyFDContext into a proper
struct which contains the hash table.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa committed 2026-06-10 11:23:52 +02:00
1 parent 856077138a
commit b23765a58f
4 files changed
+24 -10

No files matched your search

+1 -1
View File
@@ -919,7 +919,7 @@ testCompareXMLToArgv(const void *data)
if (testCompareXMLToArgvValidateSchema(cmd, info) < 0)
goto cleanup;
testCompareXMLToArgvStabilizeArgs(cmd, info->fdsubsts);
testCompareXMLToArgvStabilizeArgs(cmd, info->fdsubsts->hints);
if (virCommandToStringBuf(cmd, &actualBuf, true, false) < 0)
goto cleanup;
+16 -7
View File
@@ -298,7 +298,12 @@ static virTestDummyFDContext *dummyFDContext;
void
virTestDummyFDContextFree(virTestDummyFDContext *ctxt G_GNUC_UNUSED)
{
g_clear_pointer(&dummyFDContext, g_hash_table_unref);
if (!dummyFDContext)
return;
g_clear_pointer(&dummyFDContext->hints, g_hash_table_unref);
g_clear_pointer(&dummyFDContext, g_free);
}
@@ -307,9 +312,7 @@ virTestDummyFDContextFree(virTestDummyFDContext *ctxt G_GNUC_UNUSED)
*
* Create a new context for marking dummy FDs so that they can be later
* cross-referenced and stripped from test output. Marked FDs are recorded
* in the returned GHashTable (virTestDummyFDContext type is a direct alias
* of GHashTable, allowing for registering custom autoptr cleanup function
* so that the context can be properly disposed), where keys are stringified
* in the returned context's 'hints' field, where keys are stringified
* FD numbers and the passed 'hint' strings are recorded as values.
*
* The context uses a global variable 'dummyFDContext' so that mocked functions
@@ -322,7 +325,13 @@ virTestDummyFDContextFree(virTestDummyFDContext *ctxt G_GNUC_UNUSED)
virTestDummyFDContext *
virTestDummyFDContextNew(void)
{
return dummyFDContext = virHashNew(g_free);
if (dummyFDContext)
return dummyFDContext;
dummyFDContext = g_new0(virTestDummyFDContext, 1);
dummyFDContext->hints = virHashNew(g_free);
return dummyFDContext;
}
@@ -342,7 +351,7 @@ virTestDummyFDContextMarkFD(int fd,
return;
}
g_hash_table_insert(dummyFDContext, g_strdup_printf("%d", fd), hint);
g_hash_table_insert(dummyFDContext->hints, g_strdup_printf("%d", fd), hint);
}
@@ -366,7 +375,7 @@ virTestMakeDummyMarkDup(int newfd,
oldlabel = g_strdup_printf("%d", oldfd);
if (!(oldhint = g_hash_table_lookup(dummyFDContext, oldlabel)))
if (!(oldhint = g_hash_table_lookup(dummyFDContext->hints, oldlabel)))
return;
virTestDummyFDContextMarkFD(newfd, g_strdup_printf("%s-dup", oldhint));
+4 -1
View File
@@ -106,8 +106,11 @@ const char *virTestCounterNext(void);
char *virTestFakeRootDirInit(void);
void virTestFakeRootDirCleanup(char *fakerootdir);
struct _virTestDummyFDContext {
GHashTable *hints;
};
typedef GHashTable virTestDummyFDContext;
typedef struct _virTestDummyFDContext virTestDummyFDContext;
void virTestDummyFDContextFree(virTestDummyFDContext *ctxt);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virTestDummyFDContext, virTestDummyFDContextFree);
+3 -1
View File
@@ -22,6 +22,8 @@
#include "qemu/qemu_capabilities.h"
#include "qemu/qemu_conf.h"
#include "testutils.h"
#define TEST_QEMU_CAPS_PATH abs_srcdir "/qemucapabilitiesdata"
#define TEST_TPM_ENV_VAR "VIR_TEST_MOCK_FAKE_TPM_VERSION"
#define TPM_VER_1_2 "1.2"
@@ -119,7 +121,7 @@ struct _testQemuInfo {
struct testQemuArgs args;
struct testQemuConf *conf;
GHashTable *fdsubsts;
virTestDummyFDContext *fdsubsts;
};
typedef struct _testQemuInfo testQemuInfo;