Signed-off-by: Thanos Makatos <thanos.makatos(a)nutanix.com>
---
src/test/test_driver.c | 61 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 2 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e87d7cfd44..6eda0dcc01 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -26,8 +26,6 @@
#include <unistd.h>
#include <sys/stat.h>
#include <libxml/xmlsave.h>
-
-
#include "virerror.h"
#include "datatypes.h"
#include "test_driver.h"
@@ -10035,6 +10033,62 @@ testConnectGetDomainCapabilities(virConnectPtr conn
G_GNUC_UNUSED,
return virDomainCapsFormat(domCaps);
}
+static int
+testVirDomainAttachDeviceFlags(virDomainPtr domain,
+ const char *xml,
+ unsigned int flags G_GNUC_UNUSED) {
+
+ int ret = -1;
+ virDomainObj *vm;
+ testDriver *driver;
+ virDomainDeviceDef *devConf;
+
+ if (!(vm = testDomObjFromDomain(domain)))
+ return -1;
+
+ driver = domain->conn->privateData;
+
+ if (!(devConf = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt,
+ NULL, 0)))
+ goto out;
+
+ VIR_APPEND_ELEMENT(vm->def->hostdevs, vm->def->nhostdevs,
+ devConf->data.hostdev);
+ virDomainDeviceDefFree(devConf);
+ ret = 0;
+out:
+ virDomainObjEndAPI(&vm);
+ return ret;
+}
+
+static int
+testVirDomainAttachDevice(virDomainPtr domain, const char *xml)
+{
+ return testVirDomainAttachDeviceFlags(domain, xml, 0);
+}
+
+static int
+testVirDomainDetachDeviceAlias(virDomainPtr domain,
+ const char *alias,
+ unsigned int flags __attribute__((unused)))
+{
+ virDomainObj *vm;
+ int i;
+ bool found = false;
+
+ if (!(vm = testDomObjFromDomain(domain)))
+ return -1;
+
+ for (i = 0; i < vm->def->nhostdevs && !found; i++) {
+ if (!strcmp(vm->def->hostdevs[i]->info->alias, alias)) {
+ virDomainHostdevDefFree(vm->def->hostdevs[i]);
+ VIR_DELETE_ELEMENT(vm->def->hostdevs, i, vm->def->nhostdevs);
+ found = true;
+ }
+ }
+ virDomainObjEndAPI(&vm);
+ return found ? 0 : -1;
+}
/*
* Test driver
@@ -10058,6 +10112,9 @@ static virHypervisorDriver testHypervisorDriver = {
.connectListDomains = testConnectListDomains, /* 0.1.1 */
.connectNumOfDomains = testConnectNumOfDomains, /* 0.1.1 */
.connectListAllDomains = testConnectListAllDomains, /* 0.9.13 */
+ .domainAttachDevice = testVirDomainAttachDevice, /* 9.9.0 */
+ .domainAttachDeviceFlags = testVirDomainAttachDeviceFlags, /* 9.9.0 */
+ .domainDetachDeviceAlias = testVirDomainDetachDeviceAlias, /* 9.9.0 */
.domainCreateXML = testDomainCreateXML, /* 0.1.4 */
.domainCreateXMLWithFiles = testDomainCreateXMLWithFiles, /* 5.7.0 */
.domainLookupByID = testDomainLookupByID, /* 0.1.1 */
--
2.27.0
Show replies by date