]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virTestDummyFDContext: Add fields to track errors and 'virTestDummyFDContextMarkError'
authorPeter Krempa <pkrempa@redhat.com>
Mon, 25 May 2026 15:15:54 +0000 (17:15 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 10 Jun 2026 09:23:52 +0000 (11:23 +0200)
Add 'errors' field for tracking a list of errors and
'virTestDummyFDContextMarkError' function to add to the list.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tests/testutils.c
tests/testutils.h

index a66a07da364adf8abf3e08f030c604bef5d9702a..43e268578ecd8af67311a1d4a0c6b4920bea2aff 100644 (file)
@@ -302,6 +302,7 @@ virTestDummyFDContextFree(virTestDummyFDContext *ctxt G_GNUC_UNUSED)
         return;
 
     g_clear_pointer(&dummyFDContext->hints, g_hash_table_unref);
+    g_slist_free_full(g_steal_pointer(&dummyFDContext->errors), g_free);
 
     g_clear_pointer(&dummyFDContext, g_free);
 }
@@ -315,6 +316,9 @@ virTestDummyFDContextFree(virTestDummyFDContext *ctxt G_GNUC_UNUSED)
  * in the returned context's 'hints' field, where keys are stringified
  * FD numbers and the passed 'hint' strings are recorded as values.
  *
+ * The 'errors' GSList is a list of error strings that can be added if the test
+ * case notices invalid operations with FDs.
+ *
  * The context uses a global variable 'dummyFDContext' so that mocked functions
  * which don't allow custom data can use this infrastructure.
  *
@@ -382,6 +386,26 @@ virTestMakeDummyMarkDup(int newfd,
 }
 
 
+/**
+ * virTestDummyFDContextMarkError:
+ * @error: error message to record against the global 'dummyFDContext'
+ *
+ * Records @error in list of errors the global 'dummyFDContext' object
+ */
+void
+virTestDummyFDContextMarkError(char *error)
+{
+    if (!dummyFDContext) {
+        g_free(error);
+        return;
+    }
+
+    dummyFDContext->errors = g_slist_prepend(dummyFDContext->errors, error);
+}
+
+void virTestDummyFDContextMarkError(char *error);
+
+
 /**
  * virTestMakeDummyFD:
  * @hint: name for the FD to record into @hints
index a7cc0b16be57a357f7e1a2154cf5541d66db8dc0..9edeb0eb8401dc7d15613c111a89e36b74b482a2 100644 (file)
@@ -108,6 +108,7 @@ void virTestFakeRootDirCleanup(char *fakerootdir);
 
 struct _virTestDummyFDContext {
     GHashTable *hints;
+    GSList *errors;
 };
 
 typedef struct _virTestDummyFDContext virTestDummyFDContext;
@@ -123,6 +124,8 @@ void virTestDummyFDContextMarkFD(int fd,
 void virTestMakeDummyMarkDup(int newfd,
                              int oldfd);
 
+void virTestDummyFDContextMarkError(char *error);
+
 int virTestMakeDummyFD(char *hint);
 
 /* VIR_TEST_MAKE_DUMMY_FD_INSTALL_DUP_MOCK installs a mock for dup() that