mdevctl 'stop' and 'undefine' commands take the same uuid parameter, so
refactor the test infrastructure to share common implementation for both
of these commands. The 'undefine' command will be introduced in a
following patch.
Signed-off-by: Jonathon Jongsma <jjongsma(a)redhat.com>
---
tests/nodedevmdevctltest.c | 48 +++++++++++++++++++++++++++++++-------
1 file changed, 40 insertions(+), 8 deletions(-)
diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c
index 6162d593ec..4be4ba82c0 100644
--- a/tests/nodedevmdevctltest.c
+++ b/tests/nodedevmdevctltest.c
@@ -12,7 +12,9 @@
typedef enum {
MDEVCTL_CMD_START,
+ MDEVCTL_CMD_STOP,
MDEVCTL_CMD_DEFINE,
+ MDEVCTL_CMD_UNDEFINE
} MdevctlCmd;
struct startTestInfo {
@@ -135,20 +137,22 @@ testMdevctlStartOrDefineHelper(const void *data)
mdevxml, cmdlinefile, jsonfile);
}
+typedef virCommandPtr (*GetStopUndefineCmdFunc)(const char *uuid, char **errbuf);
+struct UuidCommandTestInfo {
+ const char *uuid;
+ MdevctlCmd command;
+};
+
static int
-testMdevctlStop(const void *data)
+testMdevctlUuidCommand(const char *uuid, GetStopUndefineCmdFunc func, const char
*outfile)
{
- const char *uuid = data;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const char *actualCmdline = NULL;
int ret = -1;
g_autoptr(virCommand) cmd = NULL;
g_autofree char *errmsg = NULL;
- g_autofree char *cmdlinefile =
- g_strdup_printf("%s/nodedevmdevctldata/mdevctl-stop.argv",
- abs_srcdir);
- cmd = nodeDeviceGetMdevctlStopCommand(uuid, &errmsg);
+ cmd = func(uuid, &errmsg);
if (!cmd)
goto cleanup;
@@ -160,7 +164,7 @@ testMdevctlStop(const void *data)
if (!(actualCmdline = virBufferCurrentContent(&buf)))
goto cleanup;
- if (nodedevCompareToFile(actualCmdline, cmdlinefile) < 0)
+ if (nodedevCompareToFile(actualCmdline, outfile) < 0)
goto cleanup;
ret = 0;
@@ -170,6 +174,27 @@ testMdevctlStop(const void *data)
return ret;
}
+static int
+testMdevctlUuidCommandHelper(const void *data)
+{
+ const struct UuidCommandTestInfo *info = data;
+ GetStopUndefineCmdFunc func;
+ const char *cmd;
+ g_autofree char *cmdlinefile = NULL;
+
+ if (info->command == MDEVCTL_CMD_STOP) {
+ cmd = "stop";
+ func = nodeDeviceGetMdevctlStopCommand;
+ } else {
+ return -1;
+ }
+
+ cmdlinefile = g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv",
+ abs_srcdir, cmd);
+
+ return testMdevctlUuidCommand(info->uuid, func, cmdlinefile);
+}
+
static int
testMdevctlListDefined(const void *data G_GNUC_UNUSED)
{
@@ -387,8 +412,15 @@ mymain(void)
#define DO_TEST_DEFINE(filename) \
DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE,
filename, MDEVCTL_CMD_DEFINE)
+#define DO_TEST_UUID_COMMAND_FULL(desc, uuid, command) \
+ do { \
+ struct UuidCommandTestInfo info = { uuid, command }; \
+ DO_TEST_FULL(desc, testMdevctlUuidCommandHelper, &info); \
+ } \
+ while (0)
+
#define DO_TEST_STOP(uuid) \
- DO_TEST_FULL("mdevctl stop " uuid, testMdevctlStop, uuid)
+ DO_TEST_UUID_COMMAND_FULL("mdevctl stop " uuid, uuid, MDEVCTL_CMD_STOP)
#define DO_TEST_LIST_DEFINED() \
DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL)
--
2.26.2