From: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
Signed-off-by: Shivaprasad G Bhat <sbhat(a)linux.vnet.ibm.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413(a)gmail.com>
---
src/util/virprocess.h | 2 +-
tests/Makefile.am | 7 +++
tests/qemuhotplugtest.c | 42 +++++++++++++-
.../qemuhotplug-hostdev-pci.xml | 6 ++
.../qemuhotplug-base-live+hostdev-pci.xml | 58 +++++++++++++++++++
...uhotplug-pseries-base-live+hostdev-pci.xml | 51 ++++++++++++++++
.../qemuhotplug-pseries-base-live.xml | 43 ++++++++++++++
tests/virprocessmock.c | 28 +++++++++
8 files changed, 235 insertions(+), 2 deletions(-)
create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-hostdev-pci.xml
create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+hostdev-pci.xml
create mode 100644
tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+hostdev-pci.xml
create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live.xml
create mode 100644 tests/virprocessmock.c
diff --git a/src/util/virprocess.h b/src/util/virprocess.h
index 003ba1edf4..4806c592da 100644
--- a/src/util/virprocess.h
+++ b/src/util/virprocess.h
@@ -75,7 +75,7 @@ int virProcessGetNamespaces(pid_t pid,
int virProcessSetNamespaces(size_t nfdlist,
int *fdlist);
-int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes);
+int virProcessSetMaxMemLock(pid_t pid, unsigned long long bytes) ATTRIBUTE_NOINLINE;
int virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes);
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f480e68e7d..66d249a0cc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -210,6 +210,7 @@ test_libraries = libshunload.la \
virpcimock.la \
virnetdevmock.la \
virrandommock.la \
+ virprocessmock.la \
virhostcpumock.la \
domaincapsmock.la \
virfilecachemock.la \
@@ -1182,6 +1183,12 @@ virrandommock_la_SOURCES = \
virrandommock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
virrandommock_la_LIBADD = $(MOCKLIBS_LIBS)
+virprocessmock_la_SOURCES = \
+ virprocessmock.c
+virprocessmock_la_CFLAGS = $(AM_CFLAGS)
+virprocessmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
+virprocessmock_la_LIBADD = $(MOCKLIBS_LIBS)
+
virhostcpumock_la_SOURCES = \
virhostcpumock.c
virhostcpumock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 354068d748..bf95bfb4a7 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -28,6 +28,7 @@
#include "testutils.h"
#include "testutilsqemu.h"
#include "testutilsqemuschema.h"
+#include "virhostdev.h"
#include "virerror.h"
#include "virstring.h"
#include "virthread.h"
@@ -79,6 +80,8 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_PLAIN);
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL);
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SCSI_DISK_WWN);
+ virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI);
+ virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0)
goto cleanup;
@@ -130,6 +133,9 @@ testQemuHotplugAttach(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_WATCHDOG:
ret = qemuDomainAttachWatchdog(&driver, vm, dev->data.watchdog);
break;
+ case VIR_DOMAIN_DEVICE_HOSTDEV:
+ ret = qemuDomainAttachHostDevice(&driver, vm, dev->data.hostdev);
+ break;
default:
VIR_TEST_VERBOSE("device type '%s' cannot be attached\n",
virDomainDeviceTypeToString(dev->type));
@@ -151,6 +157,7 @@ testQemuHotplugDetach(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_CHR:
case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_WATCHDOG:
+ case VIR_DOMAIN_DEVICE_HOSTDEV:
ret = qemuDomainDetachDeviceLive(vm, dev, &driver, async);
break;
default:
@@ -578,6 +585,7 @@ testQemuHotplugCpuIndividual(const void *opaque)
return ret;
}
+#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
static int
@@ -587,6 +595,21 @@ mymain(void)
int ret = 0;
struct qemuHotplugTestData data = {0};
struct testQemuHotplugCpuParams cpudata;
+ char *fakerootdir;
+
+ if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) {
+ fprintf(stderr, "Out of memory\n");
+ abort();
+ }
+
+ if (!mkdtemp(fakerootdir)) {
+ fprintf(stderr, "Cannot create fakerootdir");
+ abort();
+ }
+
+ setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
+ unsetenv("LD_PRELOAD");
+
#if !WITH_YAJL
fputs("libvirt not compiled with JSON support, skipping this test\n",
stderr);
@@ -621,6 +644,8 @@ mymain(void)
if (!driver.lockManager)
return EXIT_FAILURE;
+ driver.hostdevMgr = virHostdevManagerGetDefault();
+
/* wait only 100ms for DEVICE_DELETED event */
qemuDomainRemoveDeviceWaitTime = 100;
@@ -789,6 +814,15 @@ mymain(void)
"human-monitor-command", HMP("OK\\r\\n"),
"device_add", QMP_OK);
+ DO_TEST_ATTACH("base-live", "hostdev-pci", false, true,
+ "device_add", QMP_OK);
+ DO_TEST_DETACH("base-live", "hostdev-pci", false, false,
+ "device_del", QMP_DEVICE_DELETED("hostdev0")
QMP_OK);
+ DO_TEST_ATTACH("pseries-base-live", "hostdev-pci", false, true,
+ "device_add", QMP_OK);
+ DO_TEST_DETACH("pseries-base-live", "hostdev-pci", false, false,
+ "device_del", QMP_DEVICE_DELETED("hostdev0")
QMP_OK);
+
DO_TEST_ATTACH("base-live", "watchdog", false, true,
"watchdog-set-action", QMP_OK,
"device_add", QMP_OK);
@@ -846,9 +880,15 @@ mymain(void)
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true,
true, true);
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", true,
true, true);
+ if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
+ virFileDeleteTree(fakerootdir);
+ VIR_FREE(fakerootdir);
+
qemuTestDriverFree(&driver);
virObjectUnref(data.vm);
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
-VIR_TEST_MAIN(mymain)
+VIR_TEST_MAIN_PRELOAD(mymain,
+ abs_builddir "/.libs/virpcimock.so",
+ abs_builddir "/.libs/virprocessmock.so");
diff --git a/tests/qemuhotplugtestdevices/qemuhotplug-hostdev-pci.xml
b/tests/qemuhotplugtestdevices/qemuhotplug-hostdev-pci.xml
new file mode 100644
index 0000000000..6f7c99c943
--- /dev/null
+++ b/tests/qemuhotplugtestdevices/qemuhotplug-hostdev-pci.xml
@@ -0,0 +1,6 @@
+<hostdev mode='subsystem' type='pci' managed='yes'>
+ <driver name='vfio'/>
+ <source>
+ <address domain='0x0000' bus='0x06' slot='0x12'
function='0x2'/>
+ </source>
+</hostdev>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-base-live+hostdev-pci.xml
b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+hostdev-pci.xml
new file mode 100644
index 0000000000..40dcc33595
--- /dev/null
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-base-live+hostdev-pci.xml
@@ -0,0 +1,58 @@
+<domain type='kvm' id='7'>
+ <name>hotplug</name>
+ <uuid>d091ea82-29e6-2e34-3005-f02617b36e87</uuid>
+ <memory unit='KiB'>4194304</memory>
+ <currentMemory unit='KiB'>4194304</currentMemory>
+ <vcpu placement='static'>4</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ <pae/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>restart</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'>
+ <alias name='usb'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='ide' index='0'>
+ <alias name='ide'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='scsi' index='0' model='virtio-scsi'>
+ <alias name='scsi0'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x03' function='0x0'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'>
+ <alias name='pci'/>
+ </controller>
+ <controller type='virtio-serial' index='0'>
+ <alias name='virtio-serial0'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x04' function='0x0'/>
+ </controller>
+ <input type='mouse' bus='ps2'>
+ <alias name='input0'/>
+ </input>
+ <input type='keyboard' bus='ps2'>
+ <alias name='input1'/>
+ </input>
+ <hostdev mode='subsystem' type='pci' managed='yes'>
+ <driver name='vfio'/>
+ <source>
+ <address domain='0x0000' bus='0x06' slot='0x12'
function='0x2'/>
+ </source>
+ <alias name='hostdev0'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x05' function='0x0'/>
+ </hostdev>
+ <memballoon model='none'/>
+ </devices>
+ <seclabel type='none' model='none'/>
+</domain>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+hostdev-pci.xml
b/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+hostdev-pci.xml
new file mode 100644
index 0000000000..483cb5d8f0
--- /dev/null
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live+hostdev-pci.xml
@@ -0,0 +1,51 @@
+<domain type='kvm' id='7'>
+ <name>hotplug</name>
+ <uuid>d091ea82-29e6-2e34-3005-f02617b36e87</uuid>
+ <memory unit='KiB'>4194304</memory>
+ <currentMemory unit='KiB'>4194304</currentMemory>
+ <vcpu placement='static'>4</vcpu>
+ <os>
+ <type arch='ppc64' machine='pseries'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-ppc64</emulator>
+ <controller type='pci' index='0' model='pci-root'>
+ <model name='spapr-pci-host-bridge'/>
+ <target index='0'/>
+ <alias name='pci.0'/>
+ </controller>
+ <controller type='pci' index='1' model='pci-root'>
+ <model name='spapr-pci-host-bridge'/>
+ <target index='1'/>
+ <alias name='pci.1'/>
+ </controller>
+ <controller type='usb' index='0'>
+ <alias name='usb'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x01' function='0x0'/>
+ </controller>
+ <input type='keyboard' bus='usb'>
+ <alias name='input0'/>
+ <address type='usb' bus='0' port='1'/>
+ </input>
+ <input type='mouse' bus='usb'>
+ <alias name='input1'/>
+ <address type='usb' bus='0' port='2'/>
+ </input>
+ <hostdev mode='subsystem' type='pci' managed='yes'>
+ <driver name='vfio'/>
+ <source>
+ <address domain='0x0000' bus='0x06' slot='0x12'
function='0x2'/>
+ </source>
+ <alias name='hostdev0'/>
+ <address type='pci' domain='0x0000' bus='0x01'
slot='0x01' function='0x0'/>
+ </hostdev>
+ <memballoon model='none'/>
+ <panic model='pseries'/>
+ </devices>
+ <seclabel type='none' model='none'/>
+</domain>
diff --git a/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live.xml
b/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live.xml
new file mode 100644
index 0000000000..1dcc35f626
--- /dev/null
+++ b/tests/qemuhotplugtestdomains/qemuhotplug-pseries-base-live.xml
@@ -0,0 +1,43 @@
+<domain type='kvm' id='7'>
+ <name>hotplug</name>
+ <uuid>d091ea82-29e6-2e34-3005-f02617b36e87</uuid>
+ <memory unit='KiB'>4194304</memory>
+ <currentMemory unit='KiB'>4194304</currentMemory>
+ <vcpu placement='static'>4</vcpu>
+ <os>
+ <type arch='ppc64' machine='pseries'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-ppc64</emulator>
+ <controller type='pci' index='0' model='pci-root'>
+ <model name='spapr-pci-host-bridge'/>
+ <target index='0'/>
+ <alias name='pci.0'/>
+ </controller>
+ <controller type='pci' index='1' model='pci-root'>
+ <model name='spapr-pci-host-bridge'/>
+ <target index='1'/>
+ <alias name='pci.1'/>
+ </controller>
+ <controller type='usb' index='0'>
+ <alias name='usb'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x01' function='0x0'/>
+ </controller>
+ <input type='keyboard' bus='usb'>
+ <alias name='input0'/>
+ <address type='usb' bus='0' port='1'/>
+ </input>
+ <input type='mouse' bus='usb'>
+ <alias name='input1'/>
+ <address type='usb' bus='0' port='2'/>
+ </input>
+ <memballoon model='none'/>
+ <panic model='pseries'/>
+ </devices>
+ <seclabel type='none' model='none'/>
+</domain>
diff --git a/tests/virprocessmock.c b/tests/virprocessmock.c
new file mode 100644
index 0000000000..985562fee1
--- /dev/null
+++ b/tests/virprocessmock.c
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2018 Red Hat, Inc.
+ * Copyright (C) 2018 IBM Corp.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <
http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <config.h>
+#include "virprocess.h"
+
+int
+virProcessSetMaxMemLock(pid_t pid ATTRIBUTE_UNUSED, unsigned long long bytes
ATTRIBUTE_UNUSED)
+{
+ return 0;
+}
--
2.21.0