tests: nodedev: switch all test macros to accept a filename

Rather than specifying a UUID string to some test macros, just pass a
filename to an xml definition. This helps work toward unifying the test
macros and making it more maintainable.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
This commit is contained in:
Jonathon Jongsma 2021-04-08 10:25:48 -05:00
parent 14085ef98d
commit 94589d1dc8
4 changed files with 26 additions and 18 deletions

View File

@ -1,3 +1,3 @@
mdevctl \ mdevctl \
start \ start \
-u 8a05ad83-3472-497d-8631-8142f31460e8 -u d069d019-36ea-4111-8f0a-8c9a70e21366

View File

@ -1,3 +1,3 @@
mdevctl \ mdevctl \
stop \ stop \
-u e2451f73-c95b-4124-b900-e008af37c576 -u d069d019-36ea-4111-8f0a-8c9a70e21366

View File

@ -1,3 +1,3 @@
mdevctl \ mdevctl \
undefine \ undefine \
-u d76a6b78-45ed-4149-a325-005f9abc5281 -u d069d019-36ea-4111-8f0a-8c9a70e21366

View File

@ -125,13 +125,15 @@ testMdevctlStartOrDefineHelper(const void *data)
typedef virCommand* (*GetStopUndefineCmdFunc)(const char *uuid, char **errbuf); typedef virCommand* (*GetStopUndefineCmdFunc)(const char *uuid, char **errbuf);
struct UuidCommandTestInfo { struct UuidCommandTestInfo {
const char *uuid; const char *filename;
MdevctlCmd command; MdevctlCmd command;
}; };
static int static int
testMdevctlUuidCommand(const char *uuid, GetStopUndefineCmdFunc func, const char *outfile) testMdevctlUuidCommand(GetStopUndefineCmdFunc func,
const char *mdevxml, const char *outfile)
{ {
g_autoptr(virNodeDeviceDef) def = NULL;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
const char *actualCmdline = NULL; const char *actualCmdline = NULL;
int ret = -1; int ret = -1;
@ -139,7 +141,10 @@ testMdevctlUuidCommand(const char *uuid, GetStopUndefineCmdFunc func, const char
g_autofree char *errmsg = NULL; g_autofree char *errmsg = NULL;
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew(); g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
cmd = func(uuid, &errmsg); if (!(def = virNodeDeviceDefParseFile(mdevxml, EXISTING_DEVICE, "QEMU")))
goto cleanup;
cmd = func(def->caps->data.mdev.uuid, &errmsg);
if (!cmd) if (!cmd)
goto cleanup; goto cleanup;
@ -167,6 +172,7 @@ testMdevctlUuidCommandHelper(const void *data)
GetStopUndefineCmdFunc func; GetStopUndefineCmdFunc func;
const char *cmd; const char *cmd;
g_autofree char *cmdlinefile = NULL; g_autofree char *cmdlinefile = NULL;
g_autofree char *mdevxml = NULL;
if (info->command == MDEVCTL_CMD_STOP) { if (info->command == MDEVCTL_CMD_STOP) {
cmd = "stop"; cmd = "stop";
@ -181,10 +187,12 @@ testMdevctlUuidCommandHelper(const void *data)
return -1; return -1;
} }
mdevxml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
info->filename);
cmdlinefile = g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv", cmdlinefile = g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv",
abs_srcdir, cmd); abs_srcdir, cmd);
return testMdevctlUuidCommand(info->uuid, func, cmdlinefile); return testMdevctlUuidCommand(func, mdevxml, cmdlinefile);
} }
static int static int
@ -405,21 +413,21 @@ mymain(void)
#define DO_TEST_DEFINE(filename) \ #define DO_TEST_DEFINE(filename) \
DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_DEFINE) DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_DEFINE)
#define DO_TEST_UUID_COMMAND_FULL(desc, uuid, command) \ #define DO_TEST_UUID_COMMAND_FULL(desc, filename, command) \
do { \ do { \
struct UuidCommandTestInfo info = { uuid, command }; \ struct UuidCommandTestInfo info = { filename, command }; \
DO_TEST_FULL(desc, testMdevctlUuidCommandHelper, &info); \ DO_TEST_FULL(desc, testMdevctlUuidCommandHelper, &info); \
} \ } \
while (0) while (0)
#define DO_TEST_STOP(uuid) \ #define DO_TEST_STOP(filename) \
DO_TEST_UUID_COMMAND_FULL("mdevctl stop " uuid, uuid, MDEVCTL_CMD_STOP) DO_TEST_UUID_COMMAND_FULL("mdevctl stop " filename, filename, MDEVCTL_CMD_STOP)
#define DO_TEST_UNDEFINE(uuid) \ #define DO_TEST_UNDEFINE(filename) \
DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " uuid, uuid, MDEVCTL_CMD_UNDEFINE) DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " filename, filename, MDEVCTL_CMD_UNDEFINE)
#define DO_TEST_CREATE(uuid) \ #define DO_TEST_CREATE(filename) \
DO_TEST_UUID_COMMAND_FULL("mdevctl create " uuid, uuid, MDEVCTL_CMD_CREATE) DO_TEST_UUID_COMMAND_FULL("mdevctl create " filename, filename, MDEVCTL_CMD_CREATE)
#define DO_TEST_LIST_DEFINED() \ #define DO_TEST_LIST_DEFINED() \
DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL) DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL)
@ -433,7 +441,7 @@ mymain(void)
DO_TEST_START("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); DO_TEST_START("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
/* Test mdevctl stop command, pass an arbitrary uuid */ /* Test mdevctl stop command, pass an arbitrary uuid */
DO_TEST_STOP("e2451f73-c95b-4124-b900-e008af37c576"); DO_TEST_STOP("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
DO_TEST_LIST_DEFINED(); DO_TEST_LIST_DEFINED();
@ -443,9 +451,9 @@ mymain(void)
DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076"); DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9"); DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
DO_TEST_UNDEFINE("d76a6b78-45ed-4149-a325-005f9abc5281"); DO_TEST_UNDEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
DO_TEST_CREATE("8a05ad83-3472-497d-8631-8142f31460e8"); DO_TEST_CREATE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
done: done:
nodedevTestDriverFree(driver); nodedevTestDriverFree(driver);