From: Peter Krempa <[email protected]> Add 'errors' field for tracking a list of errors and 'virTestDummyFDContextMarkError' function to add to the list.
Signed-off-by: Peter Krempa <[email protected]> --- tests/testutils.c | 24 ++++++++++++++++++++++++ tests/testutils.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/tests/testutils.c b/tests/testutils.c index a66a07da36..43e268578e 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -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 diff --git a/tests/testutils.h b/tests/testutils.h index a7cc0b16be..9edeb0eb84 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -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 -- 2.54.0
