2020-06-19 05:06:01 +08:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "internal.h"
|
|
|
|
#include "testutils.h"
|
|
|
|
#include "datatypes.h"
|
|
|
|
#include "node_device/node_device_driver.h"
|
|
|
|
#include "vircommand.h"
|
|
|
|
#define LIBVIRT_VIRCOMMANDPRIV_H_ALLOW
|
|
|
|
#include "vircommandpriv.h"
|
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_NODEDEV
|
|
|
|
|
|
|
|
struct startTestInfo {
|
|
|
|
const char *virt_type;
|
|
|
|
int create;
|
|
|
|
const char *filename;
|
2021-03-31 21:20:50 +08:00
|
|
|
virMdevctlCommand command;
|
2020-06-19 05:06:01 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* capture stdin passed to command */
|
|
|
|
static void
|
|
|
|
testCommandDryRunCallback(const char *const*args G_GNUC_UNUSED,
|
|
|
|
const char *const*env G_GNUC_UNUSED,
|
|
|
|
const char *input,
|
|
|
|
char **output G_GNUC_UNUSED,
|
|
|
|
char **error G_GNUC_UNUSED,
|
|
|
|
int *status G_GNUC_UNUSED,
|
|
|
|
void *opaque G_GNUC_UNUSED)
|
|
|
|
{
|
|
|
|
char **stdinbuf = opaque;
|
|
|
|
|
|
|
|
*stdinbuf = g_strdup(input);
|
|
|
|
}
|
|
|
|
|
2021-01-28 00:55:07 +08:00
|
|
|
typedef virCommand* (*MdevctlCmdFunc)(virNodeDeviceDef *, char **, char **);
|
|
|
|
|
|
|
|
|
2020-06-19 05:06:01 +08:00
|
|
|
static int
|
2021-03-31 21:32:44 +08:00
|
|
|
testMdevctlCreateOrDefine(const char *virt_type,
|
|
|
|
int create,
|
|
|
|
MdevctlCmdFunc mdevctl_cmd_func,
|
|
|
|
const char *mdevxml,
|
|
|
|
const char *cmdfile,
|
|
|
|
const char *jsonfile)
|
2020-06-19 05:06:01 +08:00
|
|
|
{
|
|
|
|
g_autoptr(virNodeDeviceDef) def = NULL;
|
2021-03-11 15:16:13 +08:00
|
|
|
virNodeDeviceObj *obj = NULL;
|
2020-07-03 07:35:41 +08:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2020-06-19 05:06:01 +08:00
|
|
|
const char *actualCmdline = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
g_autofree char *uuid = NULL;
|
2021-02-24 04:24:14 +08:00
|
|
|
g_autofree char *errmsg = NULL;
|
2020-06-19 05:06:01 +08:00
|
|
|
g_autofree char *stdinbuf = NULL;
|
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2021-04-01 23:54:09 +08:00
|
|
|
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
|
2020-06-19 05:06:01 +08:00
|
|
|
|
|
|
|
if (!(def = virNodeDeviceDefParseFile(mdevxml, create, virt_type)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
/* this function will set a stdin buffer containing the json configuration
|
|
|
|
* of the device. The json value is captured in the callback above */
|
2021-01-28 00:55:07 +08:00
|
|
|
cmd = mdevctl_cmd_func(def, &uuid, &errmsg);
|
2020-06-19 05:06:01 +08:00
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-04-09 15:21:28 +08:00
|
|
|
virCommandSetDryRun(dryRunToken, &buf, true, true, testCommandDryRunCallback, &stdinbuf);
|
2020-06-19 05:06:01 +08:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(actualCmdline = virBufferCurrentContent(&buf)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-04-09 15:21:28 +08:00
|
|
|
if (virTestCompareToFileFull(actualCmdline, cmdfile, false) < 0)
|
2020-06-19 05:06:01 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
2021-01-28 00:55:07 +08:00
|
|
|
if (virTestCompareToFile(stdinbuf, jsonfile) < 0)
|
2020-06-19 05:06:01 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-03-31 21:32:44 +08:00
|
|
|
testMdevctlCreateOrDefineHelper(const void *data)
|
2020-06-19 05:06:01 +08:00
|
|
|
{
|
|
|
|
const struct startTestInfo *info = data;
|
2021-01-28 00:55:07 +08:00
|
|
|
const char *cmd;
|
|
|
|
MdevctlCmdFunc func;
|
|
|
|
g_autofree char *mdevxml = NULL;
|
|
|
|
g_autofree char *cmdlinefile = NULL;
|
|
|
|
g_autofree char *jsonfile = NULL;
|
|
|
|
|
2021-03-31 21:32:44 +08:00
|
|
|
if (info->command == MDEVCTL_CMD_CREATE) {
|
|
|
|
cmd = "create";
|
|
|
|
func = nodeDeviceGetMdevctlCreateCommand;
|
2021-01-28 00:55:07 +08:00
|
|
|
} else if (info->command == MDEVCTL_CMD_DEFINE) {
|
|
|
|
cmd = "define";
|
|
|
|
func = nodeDeviceGetMdevctlDefineCommand;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
2020-06-19 05:06:01 +08:00
|
|
|
|
2021-01-28 00:55:07 +08:00
|
|
|
mdevxml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
|
|
|
|
info->filename);
|
|
|
|
cmdlinefile = g_strdup_printf("%s/nodedevmdevctldata/%s-%s.argv",
|
|
|
|
abs_srcdir, info->filename, cmd);
|
|
|
|
jsonfile = g_strdup_printf("%s/nodedevmdevctldata/%s-%s.json", abs_srcdir,
|
|
|
|
info->filename, cmd);
|
2020-06-19 05:06:01 +08:00
|
|
|
|
2021-03-31 21:32:44 +08:00
|
|
|
return testMdevctlCreateOrDefine(info->virt_type, info->create, func,
|
|
|
|
mdevxml, cmdlinefile, jsonfile);
|
2020-06-19 05:06:01 +08:00
|
|
|
}
|
|
|
|
|
2021-03-31 21:24:47 +08:00
|
|
|
typedef virCommand* (*GetStopUndefineCmdFunc)(virNodeDeviceDef *def, char **errbuf);
|
2020-11-14 00:45:33 +08:00
|
|
|
struct UuidCommandTestInfo {
|
2021-04-08 23:25:48 +08:00
|
|
|
const char *filename;
|
2021-03-31 21:20:50 +08:00
|
|
|
virMdevctlCommand command;
|
2020-11-14 00:45:33 +08:00
|
|
|
};
|
|
|
|
|
2020-06-19 05:06:03 +08:00
|
|
|
static int
|
2021-04-08 23:25:48 +08:00
|
|
|
testMdevctlUuidCommand(GetStopUndefineCmdFunc func,
|
|
|
|
const char *mdevxml, const char *outfile)
|
2020-06-19 05:06:03 +08:00
|
|
|
{
|
2021-04-08 23:25:48 +08:00
|
|
|
g_autoptr(virNodeDeviceDef) def = NULL;
|
2020-07-03 07:35:41 +08:00
|
|
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
2020-06-19 05:06:03 +08:00
|
|
|
const char *actualCmdline = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
2021-02-24 04:24:14 +08:00
|
|
|
g_autofree char *errmsg = NULL;
|
2021-04-01 23:54:09 +08:00
|
|
|
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
|
2020-06-19 05:06:03 +08:00
|
|
|
|
2021-04-08 23:25:48 +08:00
|
|
|
if (!(def = virNodeDeviceDefParseFile(mdevxml, EXISTING_DEVICE, "QEMU")))
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-03-31 21:24:47 +08:00
|
|
|
cmd = func(def, &errmsg);
|
2020-06-19 05:06:03 +08:00
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-04-09 15:21:28 +08:00
|
|
|
virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
|
2020-06-19 05:06:03 +08:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(actualCmdline = virBufferCurrentContent(&buf)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-04-09 15:21:28 +08:00
|
|
|
if (virTestCompareToFileFull(actualCmdline, outfile, false) < 0)
|
2020-06-19 05:06:03 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-11-14 00:45:33 +08:00
|
|
|
static int
|
|
|
|
testMdevctlUuidCommandHelper(const void *data)
|
|
|
|
{
|
|
|
|
const struct UuidCommandTestInfo *info = data;
|
|
|
|
GetStopUndefineCmdFunc func;
|
|
|
|
const char *cmd;
|
|
|
|
g_autofree char *cmdlinefile = NULL;
|
2021-04-08 23:25:48 +08:00
|
|
|
g_autofree char *mdevxml = NULL;
|
2020-11-14 00:45:33 +08:00
|
|
|
|
|
|
|
if (info->command == MDEVCTL_CMD_STOP) {
|
|
|
|
cmd = "stop";
|
|
|
|
func = nodeDeviceGetMdevctlStopCommand;
|
2020-07-03 04:14:30 +08:00
|
|
|
} else if (info->command == MDEVCTL_CMD_UNDEFINE) {
|
|
|
|
cmd = "undefine";
|
|
|
|
func = nodeDeviceGetMdevctlUndefineCommand;
|
2021-03-31 21:32:44 +08:00
|
|
|
}else if (info->command == MDEVCTL_CMD_START) {
|
|
|
|
cmd = "start";
|
|
|
|
func = nodeDeviceGetMdevctlStartCommand;
|
2020-11-14 00:45:33 +08:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-04-08 23:25:48 +08:00
|
|
|
mdevxml = g_strdup_printf("%s/nodedevschemadata/%s.xml", abs_srcdir,
|
|
|
|
info->filename);
|
2020-11-14 00:45:33 +08:00
|
|
|
cmdlinefile = g_strdup_printf("%s/nodedevmdevctldata/mdevctl-%s.argv",
|
|
|
|
abs_srcdir, cmd);
|
|
|
|
|
2021-04-08 23:25:48 +08:00
|
|
|
return testMdevctlUuidCommand(func, mdevxml, cmdlinefile);
|
2020-11-14 00:45:33 +08:00
|
|
|
}
|
|
|
|
|
2020-07-11 06:12:18 +08:00
|
|
|
static int
|
|
|
|
testMdevctlListDefined(const void *data G_GNUC_UNUSED)
|
|
|
|
{
|
|
|
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
|
const char *actualCmdline = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
g_autoptr(virCommand) cmd = NULL;
|
|
|
|
g_autofree char *output = NULL;
|
|
|
|
g_autofree char *errmsg = NULL;
|
|
|
|
g_autofree char *cmdlinefile =
|
|
|
|
g_strdup_printf("%s/nodedevmdevctldata/mdevctl-list-defined.argv",
|
|
|
|
abs_srcdir);
|
2021-04-01 23:54:09 +08:00
|
|
|
g_autoptr(virCommandDryRunToken) dryRunToken = virCommandDryRunTokenNew();
|
2020-07-11 06:12:18 +08:00
|
|
|
|
|
|
|
cmd = nodeDeviceGetMdevctlListCommand(true, &output, &errmsg);
|
|
|
|
|
|
|
|
if (!cmd)
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-04-09 15:21:28 +08:00
|
|
|
virCommandSetDryRun(dryRunToken, &buf, true, true, NULL, NULL);
|
2020-07-11 06:12:18 +08:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (!(actualCmdline = virBufferCurrentContent(&buf)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2021-04-09 15:21:28 +08:00
|
|
|
if (virTestCompareToFileFull(actualCmdline, cmdlinefile, false) < 0)
|
2020-07-11 06:12:18 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virBufferFreeAndReset(&buf);
|
|
|
|
return ret;
|
|
|
|
}
|
2020-07-11 06:12:18 +08:00
|
|
|
|
|
|
|
static int
|
|
|
|
testMdevctlParse(const void *data)
|
|
|
|
{
|
|
|
|
g_autofree char *buf = NULL;
|
|
|
|
const char *filename = data;
|
|
|
|
g_autofree char *jsonfile = g_strdup_printf("%s/nodedevmdevctldata/%s.json",
|
|
|
|
abs_srcdir, filename);
|
|
|
|
g_autofree char *xmloutfile = g_strdup_printf("%s/nodedevmdevctldata/%s.out.xml",
|
|
|
|
abs_srcdir, filename);
|
|
|
|
int ret = -1;
|
|
|
|
int nmdevs = 0;
|
|
|
|
virNodeDeviceDef **mdevs = NULL;
|
|
|
|
virBuffer xmloutbuf = VIR_BUFFER_INITIALIZER;
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (virFileReadAll(jsonfile, 1024*1024, &buf) < 0) {
|
|
|
|
VIR_TEST_DEBUG("Unable to read file %s", jsonfile);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nmdevs = nodeDeviceParseMdevctlJSON(buf, &mdevs)) < 0) {
|
|
|
|
VIR_TEST_DEBUG("Unable to parse json for %s", filename);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < nmdevs; i++) {
|
|
|
|
g_autofree char *devxml = virNodeDeviceDefFormat(mdevs[i]);
|
|
|
|
if (!devxml)
|
|
|
|
goto cleanup;
|
|
|
|
virBufferAddStr(&xmloutbuf, devxml);
|
|
|
|
}
|
|
|
|
|
2021-04-09 15:21:28 +08:00
|
|
|
if (virTestCompareToFileFull(virBufferCurrentContent(&xmloutbuf), xmloutfile, false) < 0)
|
2020-07-11 06:12:18 +08:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
virBufferFreeAndReset(&xmloutbuf);
|
|
|
|
for (i = 0; i < nmdevs; i++)
|
|
|
|
virNodeDeviceDefFree(mdevs[i]);
|
|
|
|
g_free(mdevs);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-06-19 05:06:01 +08:00
|
|
|
static void
|
2021-03-11 15:16:13 +08:00
|
|
|
nodedevTestDriverFree(virNodeDeviceDriverState *drv)
|
2020-06-19 05:06:01 +08:00
|
|
|
{
|
|
|
|
if (!drv)
|
|
|
|
return;
|
|
|
|
|
|
|
|
virNodeDeviceObjListFree(drv->devs);
|
|
|
|
virCondDestroy(&drv->initCond);
|
|
|
|
virMutexDestroy(&drv->lock);
|
2021-02-04 03:35:02 +08:00
|
|
|
g_free(drv->stateDir);
|
|
|
|
g_free(drv);
|
2020-06-19 05:06:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a fake root 'computer' device */
|
2021-03-11 15:16:13 +08:00
|
|
|
static virNodeDeviceDef *
|
2020-06-19 05:06:01 +08:00
|
|
|
fakeRootDevice(void)
|
|
|
|
{
|
2021-03-11 15:16:13 +08:00
|
|
|
virNodeDeviceDef *def = NULL;
|
2020-06-19 05:06:01 +08:00
|
|
|
|
2020-09-23 06:42:45 +08:00
|
|
|
def = g_new0(virNodeDeviceDef, 1);
|
|
|
|
def->caps = g_new0(virNodeDevCapsDef, 1);
|
2020-06-19 05:06:01 +08:00
|
|
|
def->name = g_strdup("computer");
|
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Add a fake pci device that can be used as a parent device for mediated
|
|
|
|
* devices. For our purposes, it only needs to have a name that matches the
|
|
|
|
* parent of the mdev, and it needs a PCI address
|
|
|
|
*/
|
2021-03-11 15:16:13 +08:00
|
|
|
static virNodeDeviceDef *
|
2020-06-19 05:06:01 +08:00
|
|
|
fakeParentDevice(void)
|
|
|
|
{
|
2021-03-11 15:16:13 +08:00
|
|
|
virNodeDeviceDef *def = NULL;
|
|
|
|
virNodeDevCapPCIDev *pci_dev;
|
2020-06-19 05:06:01 +08:00
|
|
|
|
2020-09-23 06:42:45 +08:00
|
|
|
def = g_new0(virNodeDeviceDef, 1);
|
|
|
|
def->caps = g_new0(virNodeDevCapsDef, 1);
|
2020-06-19 05:06:01 +08:00
|
|
|
|
|
|
|
def->name = g_strdup("pci_0000_00_02_0");
|
|
|
|
def->parent = g_strdup("computer");
|
|
|
|
|
|
|
|
def->caps->data.type = VIR_NODE_DEV_CAP_PCI_DEV;
|
|
|
|
pci_dev = &def->caps->data.pci_dev;
|
|
|
|
pci_dev->domain = 0;
|
|
|
|
pci_dev->bus = 0;
|
|
|
|
pci_dev->slot = 2;
|
|
|
|
pci_dev->function = 0;
|
|
|
|
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2021-03-11 15:16:13 +08:00
|
|
|
addDevice(virNodeDeviceDef *def)
|
2020-06-19 05:06:01 +08:00
|
|
|
{
|
2021-03-11 15:16:13 +08:00
|
|
|
virNodeDeviceObj *obj;
|
2020-06-19 05:06:01 +08:00
|
|
|
if (!def)
|
|
|
|
return -1;
|
|
|
|
|
2020-07-29 01:50:28 +08:00
|
|
|
obj = virNodeDeviceObjListAssignDef(driver->devs, def);
|
2020-06-19 05:06:01 +08:00
|
|
|
|
|
|
|
if (!obj) {
|
|
|
|
virNodeDeviceDefFree(def);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
virNodeDeviceObjEndAPI(&obj);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
nodedevTestDriverAddTestDevices(void)
|
|
|
|
{
|
|
|
|
if (addDevice(fakeRootDevice()) < 0 ||
|
|
|
|
addDevice(fakeParentDevice()) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bare minimum driver init to be able to test nodedev functionality */
|
|
|
|
static int
|
|
|
|
nodedevTestDriverInit(void)
|
|
|
|
{
|
|
|
|
int ret = -1;
|
2020-09-23 06:42:45 +08:00
|
|
|
driver = g_new0(virNodeDeviceDriverState, 1);
|
2020-06-19 05:06:01 +08:00
|
|
|
|
|
|
|
driver->lockFD = -1;
|
|
|
|
if (virMutexInit(&driver->lock) < 0 ||
|
|
|
|
virCondInit(&driver->initCond) < 0) {
|
|
|
|
VIR_TEST_DEBUG("Unable to initialize test nodedev driver");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(driver->devs = virNodeDeviceObjListNew()))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
nodedevTestDriverFree(driver);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (nodedevTestDriverInit() < 0)
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
/* add a mock device to the device list so it can be used as a parent
|
|
|
|
* reference */
|
|
|
|
if (nodedevTestDriverAddTestDevices() < 0) {
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DO_TEST_FULL(desc, func, info) \
|
2021-03-31 00:05:59 +08:00
|
|
|
if (virTestRun(desc, func, info) < 0) \
|
2020-06-19 05:06:01 +08:00
|
|
|
ret = -1;
|
|
|
|
|
2021-01-28 00:55:07 +08:00
|
|
|
#define DO_TEST_CMD(desc, virt_type, create, filename, command) \
|
2020-06-19 05:06:01 +08:00
|
|
|
do { \
|
2021-01-28 00:55:07 +08:00
|
|
|
struct startTestInfo info = { virt_type, create, filename, command }; \
|
2021-03-31 21:32:44 +08:00
|
|
|
DO_TEST_FULL(desc, testMdevctlCreateOrDefineHelper, &info); \
|
2020-06-19 05:06:01 +08:00
|
|
|
} \
|
2020-07-02 00:08:34 +08:00
|
|
|
while (0)
|
2020-06-19 05:06:01 +08:00
|
|
|
|
2021-03-31 21:32:44 +08:00
|
|
|
#define DO_TEST_CREATE(filename) \
|
|
|
|
DO_TEST_CMD("mdevctl create " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_CREATE)
|
2021-01-28 00:55:07 +08:00
|
|
|
|
|
|
|
#define DO_TEST_DEFINE(filename) \
|
|
|
|
DO_TEST_CMD("mdevctl define " filename, "QEMU", CREATE_DEVICE, filename, MDEVCTL_CMD_DEFINE)
|
2020-06-19 05:06:01 +08:00
|
|
|
|
2021-04-08 23:25:48 +08:00
|
|
|
#define DO_TEST_UUID_COMMAND_FULL(desc, filename, command) \
|
2020-11-14 00:45:33 +08:00
|
|
|
do { \
|
2021-04-08 23:25:48 +08:00
|
|
|
struct UuidCommandTestInfo info = { filename, command }; \
|
2020-11-14 00:45:33 +08:00
|
|
|
DO_TEST_FULL(desc, testMdevctlUuidCommandHelper, &info); \
|
|
|
|
} \
|
|
|
|
while (0)
|
|
|
|
|
2021-04-08 23:25:48 +08:00
|
|
|
#define DO_TEST_STOP(filename) \
|
|
|
|
DO_TEST_UUID_COMMAND_FULL("mdevctl stop " filename, filename, MDEVCTL_CMD_STOP)
|
2020-06-19 05:06:03 +08:00
|
|
|
|
2021-04-08 23:25:48 +08:00
|
|
|
#define DO_TEST_UNDEFINE(filename) \
|
|
|
|
DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " filename, filename, MDEVCTL_CMD_UNDEFINE)
|
2020-07-03 04:14:30 +08:00
|
|
|
|
2021-03-31 21:32:44 +08:00
|
|
|
#define DO_TEST_START(filename) \
|
|
|
|
DO_TEST_UUID_COMMAND_FULL("mdevctl start " filename, filename, MDEVCTL_CMD_START)
|
2020-06-18 23:21:13 +08:00
|
|
|
|
2020-07-11 06:12:18 +08:00
|
|
|
#define DO_TEST_LIST_DEFINED() \
|
|
|
|
DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL)
|
|
|
|
|
2020-07-11 06:12:18 +08:00
|
|
|
#define DO_TEST_PARSE_JSON(filename) \
|
|
|
|
DO_TEST_FULL("parse mdevctl json " filename, testMdevctlParse, filename)
|
|
|
|
|
2021-03-31 21:32:44 +08:00
|
|
|
DO_TEST_CREATE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
|
|
|
|
DO_TEST_CREATE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
|
|
|
|
DO_TEST_CREATE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
|
2020-06-19 05:06:01 +08:00
|
|
|
|
2020-06-19 05:06:03 +08:00
|
|
|
/* Test mdevctl stop command, pass an arbitrary uuid */
|
2021-04-08 23:25:48 +08:00
|
|
|
DO_TEST_STOP("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
|
2020-06-19 05:06:03 +08:00
|
|
|
|
2020-07-11 06:12:18 +08:00
|
|
|
DO_TEST_LIST_DEFINED();
|
|
|
|
|
2020-07-11 06:12:18 +08:00
|
|
|
DO_TEST_PARSE_JSON("mdevctl-list-multiple");
|
|
|
|
|
2021-01-28 00:55:07 +08:00
|
|
|
DO_TEST_DEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
|
|
|
|
DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
|
|
|
|
DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
|
|
|
|
|
2021-04-08 23:25:48 +08:00
|
|
|
DO_TEST_UNDEFINE("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
|
2020-07-03 04:14:30 +08:00
|
|
|
|
2021-03-31 21:32:44 +08:00
|
|
|
DO_TEST_START("mdev_d069d019_36ea_4111_8f0a_8c9a70e21366");
|
2020-06-18 23:21:13 +08:00
|
|
|
|
2020-06-19 05:06:01 +08:00
|
|
|
done:
|
|
|
|
nodedevTestDriverFree(driver);
|
|
|
|
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
VIR_TEST_MAIN(mymain)
|