nodedev: Add tests for mdevctl autostart command

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Jonathon Jongsma 2021-05-27 16:06:19 -05:00
parent dc60f91530
commit 592031a580
2 changed files with 63 additions and 0 deletions

View File

@ -0,0 +1,8 @@
mdevctl \
modify \
--uuid d069d019-36ea-4111-8f0a-8c9a70e21366 \
--auto
mdevctl \
modify \
--uuid d069d019-36ea-4111-8f0a-8c9a70e21366 \
--manual

View File

@ -124,6 +124,56 @@ testMdevctlHelper(const void *data)
}
static int
testMdevctlAutostart(const void *data G_GNUC_UNUSED)
{
g_autoptr(virNodeDeviceDef) def = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
const char *actualCmdline = NULL;
int ret = -1;
g_autoptr(virCommand) enablecmd = NULL;
g_autoptr(virCommand) disablecmd = NULL;
g_autofree char *errmsg = NULL;
/* just concatenate both calls into the same output file */
g_autofree char *cmdlinefile =
g_strdup_printf("%s/nodedevmdevctldata/mdevctl-autostart.argv",
abs_srcdir);
g_autofree char *mdevxml =
g_strdup_printf("%s/nodedevschemadata/mdev_d069d019_36ea_4111_8f0a_8c9a70e21366.xml",
abs_srcdir);
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
if (!(def = virNodeDeviceDefParseFile(mdevxml, CREATE_DEVICE, VIRT_TYPE,
&parser_callbacks, NULL)))
return -1;
virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
if (!(enablecmd = nodeDeviceGetMdevctlSetAutostartCommand(def, true, &errmsg)))
goto cleanup;
if (virCommandRun(enablecmd, NULL) < 0)
goto cleanup;
if (!(disablecmd = nodeDeviceGetMdevctlSetAutostartCommand(def, false, &errmsg)))
goto cleanup;
if (virCommandRun(disablecmd, NULL) < 0)
goto cleanup;
if (!(actualCmdline = virBufferCurrentContent(&buf)))
goto cleanup;
if (virTestCompareToFileFull(actualCmdline, cmdlinefile, false) < 0)
goto cleanup;
ret = 0;
cleanup:
virBufferFreeAndReset(&buf);
return ret;
}
static int
testMdevctlListDefined(const void *data G_GNUC_UNUSED)
{
@ -378,6 +428,9 @@ mymain(void)
#define DO_TEST_LIST_DEFINED() \
DO_TEST_FULL("list defined mdevs", testMdevctlListDefined, NULL)
#define DO_TEST_AUTOSTART() \
DO_TEST_FULL("autostart mdevs", testMdevctlAutostart, NULL)
#define DO_TEST_PARSE_JSON(filename) \
DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filename)
@ -401,6 +454,8 @@ mymain(void)
DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
DO_TEST_AUTOSTART();
done:
nodedevTestDriverFree(driver);