[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH v2 6/7] tests: qemu: Add test case for pci-hostdev hotplug



On 7/25/19 8:09 PM, Daniel Henrique Barboza wrote:
From: Shivaprasad G Bhat <sbhat linux vnet ibm com>

Signed-off-by: Shivaprasad G Bhat <sbhat linux vnet ibm com>
Signed-off-by: Daniel Henrique Barboza <danielhb413 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");

This unsetenv is not necessary, isn't it?

Reviewed-by: Michal Privoznik <mprivozn redhat com>

Michal


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]