mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-02 04:15:46 +00:00
tests: Add test case for QEMU pci-hostdev hotplug
This patch adds hostdev test cases in qemuhotplugtest.c. Note: the small tweak inside virpcimock.c was needed because the new tests added a code path in which virHostHasIOMMU() (virutil.c) started being called, and the mocked '/sys/kernel/' prefix that is mocked in virpcimock.c wasn't being considered in the opendir() mock. An alternative to avoid these situations in virpcimock.c is implemented in the next patch. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
5a9dc4a50c
commit
944a35d7f0
@ -75,7 +75,7 @@ int virProcessGetNamespaces(pid_t pid,
|
|||||||
int virProcessSetNamespaces(size_t nfdlist,
|
int virProcessSetNamespaces(size_t nfdlist,
|
||||||
int *fdlist);
|
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 virProcessSetMaxProcesses(pid_t pid, unsigned int procs);
|
||||||
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
|
int virProcessSetMaxFiles(pid_t pid, unsigned int files);
|
||||||
int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes);
|
int virProcessSetMaxCoreSize(pid_t pid, unsigned long long bytes);
|
||||||
|
@ -216,6 +216,7 @@ test_libraries = libshunload.la \
|
|||||||
libvirpcimock.la \
|
libvirpcimock.la \
|
||||||
libvirnetdevmock.la \
|
libvirnetdevmock.la \
|
||||||
libvirrandommock.la \
|
libvirrandommock.la \
|
||||||
|
libvirprocessmock.la \
|
||||||
libvirhostcpumock.la \
|
libvirhostcpumock.la \
|
||||||
libdomaincapsmock.la \
|
libdomaincapsmock.la \
|
||||||
libvirfilecachemock.la \
|
libvirfilecachemock.la \
|
||||||
@ -1196,6 +1197,12 @@ libvirrandommock_la_SOURCES = \
|
|||||||
libvirrandommock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
libvirrandommock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
||||||
libvirrandommock_la_LIBADD = $(MOCKLIBS_LIBS)
|
libvirrandommock_la_LIBADD = $(MOCKLIBS_LIBS)
|
||||||
|
|
||||||
|
libvirprocessmock_la_SOURCES = \
|
||||||
|
virprocessmock.c
|
||||||
|
libvirprocessmock_la_CFLAGS = $(AM_CFLAGS)
|
||||||
|
libvirprocessmock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
||||||
|
libvirprocessmock_la_LIBADD = $(MOCKLIBS_LIBS)
|
||||||
|
|
||||||
libvirhostcpumock_la_SOURCES = \
|
libvirhostcpumock_la_SOURCES = \
|
||||||
virhostcpumock.c
|
virhostcpumock.c
|
||||||
libvirhostcpumock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
libvirhostcpumock_la_LDFLAGS = $(MOCKLIBS_LDFLAGS)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "testutils.h"
|
#include "testutils.h"
|
||||||
#include "testutilsqemu.h"
|
#include "testutilsqemu.h"
|
||||||
#include "testutilsqemuschema.h"
|
#include "testutilsqemuschema.h"
|
||||||
|
#include "virhostdev.h"
|
||||||
#include "virerror.h"
|
#include "virerror.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "virthread.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_PLAIN);
|
||||||
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL);
|
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_IVSHMEM_DOORBELL);
|
||||||
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_SCSI_DISK_WWN);
|
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)
|
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, priv->qemuCaps) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -130,6 +133,9 @@ testQemuHotplugAttach(virDomainObjPtr vm,
|
|||||||
case VIR_DOMAIN_DEVICE_WATCHDOG:
|
case VIR_DOMAIN_DEVICE_WATCHDOG:
|
||||||
ret = qemuDomainAttachWatchdog(&driver, vm, dev->data.watchdog);
|
ret = qemuDomainAttachWatchdog(&driver, vm, dev->data.watchdog);
|
||||||
break;
|
break;
|
||||||
|
case VIR_DOMAIN_DEVICE_HOSTDEV:
|
||||||
|
ret = qemuDomainAttachHostDevice(&driver, vm, dev->data.hostdev);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
VIR_TEST_VERBOSE("device type '%s' cannot be attached",
|
VIR_TEST_VERBOSE("device type '%s' cannot be attached",
|
||||||
virDomainDeviceTypeToString(dev->type));
|
virDomainDeviceTypeToString(dev->type));
|
||||||
@ -151,6 +157,7 @@ testQemuHotplugDetach(virDomainObjPtr vm,
|
|||||||
case VIR_DOMAIN_DEVICE_CHR:
|
case VIR_DOMAIN_DEVICE_CHR:
|
||||||
case VIR_DOMAIN_DEVICE_SHMEM:
|
case VIR_DOMAIN_DEVICE_SHMEM:
|
||||||
case VIR_DOMAIN_DEVICE_WATCHDOG:
|
case VIR_DOMAIN_DEVICE_WATCHDOG:
|
||||||
|
case VIR_DOMAIN_DEVICE_HOSTDEV:
|
||||||
ret = qemuDomainDetachDeviceLive(vm, dev, &driver, async);
|
ret = qemuDomainDetachDeviceLive(vm, dev, &driver, async);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -578,6 +585,7 @@ testQemuHotplugCpuIndividual(const void *opaque)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -587,6 +595,19 @@ mymain(void)
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct qemuHotplugTestData data = {0};
|
struct qemuHotplugTestData data = {0};
|
||||||
struct testQemuHotplugCpuParams cpudata;
|
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);
|
||||||
|
|
||||||
#if !WITH_YAJL
|
#if !WITH_YAJL
|
||||||
fputs("libvirt not compiled with JSON support, skipping this test\n", stderr);
|
fputs("libvirt not compiled with JSON support, skipping this test\n", stderr);
|
||||||
@ -621,6 +642,8 @@ mymain(void)
|
|||||||
if (!driver.lockManager)
|
if (!driver.lockManager)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
|
driver.hostdevMgr = virHostdevManagerGetDefault();
|
||||||
|
|
||||||
/* wait only 100ms for DEVICE_DELETED event */
|
/* wait only 100ms for DEVICE_DELETED event */
|
||||||
qemuDomainRemoveDeviceWaitTime = 100;
|
qemuDomainRemoveDeviceWaitTime = 100;
|
||||||
|
|
||||||
@ -789,6 +812,15 @@ mymain(void)
|
|||||||
"human-monitor-command", HMP("OK\\r\\n"),
|
"human-monitor-command", HMP("OK\\r\\n"),
|
||||||
"device_add", QMP_OK);
|
"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,
|
DO_TEST_ATTACH("base-live", "watchdog", false, true,
|
||||||
"watchdog-set-action", QMP_OK,
|
"watchdog-set-action", QMP_OK,
|
||||||
"device_add", QMP_OK);
|
"device_add", QMP_OK);
|
||||||
@ -846,9 +878,15 @@ mymain(void)
|
|||||||
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true, true, true);
|
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "16-22", true, true, true);
|
||||||
DO_TEST_CPU_INDIVIDUAL("ppc64-modern-individual", "17", 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);
|
qemuTestDriverFree(&driver);
|
||||||
virObjectUnref(data.vm);
|
virObjectUnref(data.vm);
|
||||||
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
return (ret == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
VIR_TEST_MAIN(mymain)
|
VIR_TEST_MAIN_PRELOAD(mymain,
|
||||||
|
VIR_TEST_MOCK("virpci"),
|
||||||
|
VIR_TEST_MOCK("virprocess"));
|
||||||
|
6
tests/qemuhotplugtestdevices/qemuhotplug-hostdev-pci.xml
Normal file
6
tests/qemuhotplugtestdevices/qemuhotplug-hostdev-pci.xml
Normal file
@ -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>
|
@ -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>
|
@ -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>
|
@ -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>
|
@ -1148,7 +1148,8 @@ opendir(const char *path)
|
|||||||
|
|
||||||
init_syms();
|
init_syms();
|
||||||
|
|
||||||
if (STRPREFIX(path, SYSFS_PCI_PREFIX) &&
|
if ((STRPREFIX(path, SYSFS_PCI_PREFIX) ||
|
||||||
|
STRPREFIX(path, "/sys/kernel/")) &&
|
||||||
getrealpath(&newpath, path) < 0)
|
getrealpath(&newpath, path) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
28
tests/virprocessmock.c
Normal file
28
tests/virprocessmock.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 Red Hat, Inc.
|
||||||
|
* Copyright (C) 2019 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user