[libvirt] [PATCH v2 6/7] tests: Introduce QEMU memory locking limit tests

Andrea Bolognani abologna at redhat.com
Mon Mar 27 15:38:58 UTC 2017


These tests cover a number of scenarios where we care about
the memory locking limit being set correctly for the guest
to work properly.
---
 tests/Makefile.am                                  |   9 ++
 .../qemumemlock-pc-hardlimit+hostdev.xml           |  20 +++
 .../qemumemlock-pc-hardlimit+locked+hostdev.xml    |  23 ++++
 .../qemumemlock-pc-hardlimit+locked.xml            |  17 +++
 tests/qemumemlockdata/qemumemlock-pc-hardlimit.xml |  14 ++
 tests/qemumemlockdata/qemumemlock-pc-hostdev.xml   |  17 +++
 tests/qemumemlockdata/qemumemlock-pc-kvm.xml       |  11 ++
 .../qemumemlock-pc-locked+hostdev.xml              |  20 +++
 tests/qemumemlockdata/qemumemlock-pc-locked.xml    |  14 ++
 tests/qemumemlockdata/qemumemlock-pc-tcg.xml       |  11 ++
 .../qemumemlock-pseries-hardlimit+hostdev.xml      |  20 +++
 ...emumemlock-pseries-hardlimit+locked+hostdev.xml |  23 ++++
 .../qemumemlock-pseries-hardlimit+locked.xml       |  17 +++
 .../qemumemlock-pseries-hardlimit.xml              |  14 ++
 .../qemumemlock-pseries-hostdev.xml                |  17 +++
 tests/qemumemlockdata/qemumemlock-pseries-kvm.xml  |  11 ++
 .../qemumemlock-pseries-locked+hostdev.xml         |  20 +++
 .../qemumemlockdata/qemumemlock-pseries-locked.xml |  14 ++
 tests/qemumemlockdata/qemumemlock-pseries-tcg.xml  |  11 ++
 tests/qemumemlocktest.c                            | 153 +++++++++++++++++++++
 20 files changed, 456 insertions(+)
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hardlimit+hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked+hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hardlimit.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-kvm.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-locked+hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-locked.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pc-tcg.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-hardlimit+hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked+hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-hardlimit.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-kvm.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-locked+hostdev.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-locked.xml
 create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-tcg.xml
 create mode 100644 tests/qemumemlocktest.c

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 076734f..db5e475 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -127,6 +127,7 @@ EXTRA_DIST =		\
 	qemumonitorjsondata \
 	qemuxml2argvdata \
 	qemuxml2xmloutdata \
+	qemumemlockdata \
 	secretxml2xmlin \
 	securityselinuxhelperdata \
 	securityselinuxlabeldata \
@@ -277,6 +278,7 @@ test_programs += qemuxml2argvtest qemuxml2xmltest \
 	qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \
 	qemumonitortest qemumonitorjsontest qemuhotplugtest \
 	qemuagenttest qemucapabilitiestest qemucaps2xmltest \
+	qemumemlocktest \
 	qemucommandutiltest
 test_helpers += qemucapsprobe
 test_libraries += libqemumonitortestutils.la \
@@ -659,6 +661,12 @@ domainsnapshotxml2xmltest_SOURCES = \
 	domainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \
 	testutils.c testutils.h
 domainsnapshotxml2xmltest_LDADD = $(qemu_LDADDS) $(LDADDS)
+
+qemumemlocktest_SOURCES = \
+	qemumemlocktest.c \
+	testutilsqemu.c testutilsqemu.h \
+	testutils.c testutils.h
+qemumemlocktest_LDADD = $(qemu_LDADDS) $(LDADDS)
 else ! WITH_QEMU
 EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
 	qemuhelptest.c domainsnapshotxml2xmltest.c \
@@ -666,6 +674,7 @@ EXTRA_DIST += qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \
 	qemumonitorjsontest.c qemuhotplugtest.c \
 	qemuagenttest.c qemucapabilitiestest.c \
 	qemucaps2xmltest.c qemucommandutiltest.c \
+	qemumemlocktest.c \
 	$(QEMUMONITORTESTUTILS_SOURCES)
 endif ! WITH_QEMU
 
diff --git a/tests/qemumemlockdata/qemumemlock-pc-hardlimit+hostdev.xml b/tests/qemumemlockdata/qemumemlock-pc-hardlimit+hostdev.xml
new file mode 100644
index 0000000..5443145
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-hardlimit+hostdev.xml
@@ -0,0 +1,20 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked+hostdev.xml b/tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked+hostdev.xml
new file mode 100644
index 0000000..8184eef
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked+hostdev.xml
@@ -0,0 +1,23 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked.xml b/tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked.xml
new file mode 100644
index 0000000..78bee62
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked.xml
@@ -0,0 +1,17 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-hardlimit.xml b/tests/qemumemlockdata/qemumemlock-pc-hardlimit.xml
new file mode 100644
index 0000000..b1e3867
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-hardlimit.xml
@@ -0,0 +1,14 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-hostdev.xml b/tests/qemumemlockdata/qemumemlock-pc-hostdev.xml
new file mode 100644
index 0000000..6c058a9
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-hostdev.xml
@@ -0,0 +1,17 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-kvm.xml b/tests/qemumemlockdata/qemumemlock-pc-kvm.xml
new file mode 100644
index 0000000..7fa4e24
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-kvm.xml
@@ -0,0 +1,11 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-locked+hostdev.xml b/tests/qemumemlockdata/qemumemlock-pc-locked+hostdev.xml
new file mode 100644
index 0000000..fbc1dc3
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-locked+hostdev.xml
@@ -0,0 +1,20 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-locked.xml b/tests/qemumemlockdata/qemumemlock-pc-locked.xml
new file mode 100644
index 0000000..febb036
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-locked.xml
@@ -0,0 +1,14 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pc-tcg.xml b/tests/qemumemlockdata/qemumemlock-pc-tcg.xml
new file mode 100644
index 0000000..1934269
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pc-tcg.xml
@@ -0,0 +1,11 @@
+<domain type='qemu'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64' machine='pc'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+hostdev.xml b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+hostdev.xml
new file mode 100644
index 0000000..ddd3b47
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+hostdev.xml
@@ -0,0 +1,20 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked+hostdev.xml b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked+hostdev.xml
new file mode 100644
index 0000000..73c28c1
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked+hostdev.xml
@@ -0,0 +1,23 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked.xml b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked.xml
new file mode 100644
index 0000000..fe984a2
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked.xml
@@ -0,0 +1,17 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hardlimit.xml b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit.xml
new file mode 100644
index 0000000..b23de1d
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit.xml
@@ -0,0 +1,14 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memtune>
+    <hard_limit unit='KiB'>2097152</hard_limit>
+  </memtune>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hostdev.xml b/tests/qemumemlockdata/qemumemlock-pseries-hostdev.xml
new file mode 100644
index 0000000..daf70a4
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-hostdev.xml
@@ -0,0 +1,17 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-kvm.xml b/tests/qemumemlockdata/qemumemlock-pseries-kvm.xml
new file mode 100644
index 0000000..5a065da
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-kvm.xml
@@ -0,0 +1,11 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-locked+hostdev.xml b/tests/qemumemlockdata/qemumemlock-pseries-locked+hostdev.xml
new file mode 100644
index 0000000..74212f1
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-locked+hostdev.xml
@@ -0,0 +1,20 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+    <hostdev mode='subsystem' type='pci' managed='yes'>
+      <driver name='vfio'/>
+      <source>
+        <address domain='0x0000' bus='0x04' slot='0x02' function='0x0'/>
+      </source>
+    </hostdev>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-locked.xml b/tests/qemumemlockdata/qemumemlock-pseries-locked.xml
new file mode 100644
index 0000000..befaefd
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-locked.xml
@@ -0,0 +1,14 @@
+<domain type='kvm'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <memoryBacking>
+    <locked/>
+  </memoryBacking>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlockdata/qemumemlock-pseries-tcg.xml b/tests/qemumemlockdata/qemumemlock-pseries-tcg.xml
new file mode 100644
index 0000000..a3b03dd
--- /dev/null
+++ b/tests/qemumemlockdata/qemumemlock-pseries-tcg.xml
@@ -0,0 +1,11 @@
+<domain type='qemu'>
+  <name>guest</name>
+  <memory unit='KiB'>1048576</memory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='ppc64' machine='pseries'>hvm</type>
+  </os>
+  <devices>
+    <emulator>/usr/bin/qemu-system-ppc64</emulator>
+  </devices>
+</domain>
diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c
new file mode 100644
index 0000000..9159388
--- /dev/null
+++ b/tests/qemumemlocktest.c
@@ -0,0 +1,153 @@
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+
+#include "testutils.h"
+
+#ifdef WITH_QEMU
+
+# include "datatypes.h"
+# include "internal.h"
+# include "virstring.h"
+# include "conf/domain_conf.h"
+# include "qemu/qemu_domain.h"
+
+# include "testutilsqemu.h"
+
+# define VIR_FROM_THIS VIR_FROM_QEMU
+
+static const char *abs_top_srcdir;
+static virQEMUDriver driver;
+
+struct testInfo {
+    const char *name;
+    unsigned long long memlock;
+};
+
+static int
+testCompareMemLock(const void *data)
+{
+    const struct testInfo *info = data;
+    virConnectPtr conn = NULL;
+    virDomainObjPtr vm = NULL;
+    char *xml = NULL;
+    int ret = -1;
+
+    if (!(conn = virGetConnect()))
+        goto cleanup;
+
+    if (virAsprintf(&xml, "%s/qemumemlockdata/qemumemlock-%s.xml",
+                    abs_srcdir, info->name) < 0)
+        goto cleanup;
+
+    if (!(vm = virDomainObjNew(driver.xmlopt)))
+        goto cleanup;
+
+    if (!(vm->def = virDomainDefParseFile(xml, driver.caps, driver.xmlopt, NULL,
+                                          VIR_DOMAIN_DEF_PARSE_INACTIVE))) {
+        goto cleanup;
+    }
+
+    if (virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBytes(vm->def)) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virObjectUnref(vm);
+    virObjectUnref(conn);
+    VIR_FREE(xml);
+
+    return ret;
+}
+
+
+static int
+mymain(void)
+{
+    int ret = 0;
+
+    abs_top_srcdir = getenv("abs_top_srcdir");
+    if (!abs_top_srcdir)
+        abs_top_srcdir = abs_srcdir "/..";
+
+    if (qemuTestDriverInit(&driver) < 0)
+        return EXIT_FAILURE;
+
+    driver.privileged = true;
+
+# define DO_TEST(name, memlock) \
+    do { \
+        static struct testInfo info = { \
+            name, memlock \
+        }; \
+        if (virTestRun("QEMU MEMLOCK " name, testCompareMemLock, &info) < 0) \
+            ret = -1; \
+    } while (0)
+
+    /* The tests below make sure that the memory locking limit is being
+     * calculated correctly in a number of situations. Each test is
+     * performed both on x86_64/pc and ppc64/pseries in order to account
+     * for some architecture-specific details.
+     *
+     * kvm: simple KMV guest
+     * tcg: simple TCG guest
+     *
+     * hardlimit: guest where <memtune><hard_limit> has been configured
+     * locked:    guest where <memoryBacking><locked> has been enabled
+     * hostdev:   guest that has some hostdev assigned
+     *
+     * The remaining tests cover different combinations of the above to
+     * ensure settings are prioritized as expected.
+     */
+
+    qemuTestSetHostArch(driver.caps, VIR_ARCH_X86_64);
+
+    DO_TEST("pc-kvm", 0);
+    DO_TEST("pc-tcg", 0);
+
+    DO_TEST("pc-hardlimit", 2147483648);
+    DO_TEST("pc-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
+    DO_TEST("pc-hostdev", 2147483648);
+
+    DO_TEST("pc-hardlimit+locked", 2147483648);
+    DO_TEST("pc-hardlimit+hostdev", 2147483648);
+    DO_TEST("pc-hardlimit+locked+hostdev", 2147483648);
+    DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
+
+    qemuTestSetHostArch(driver.caps, VIR_ARCH_PPC64);
+
+    DO_TEST("pseries-kvm", 20971520);
+    DO_TEST("pseries-tcg", 0);
+
+    DO_TEST("pseries-hardlimit", 2147483648);
+    DO_TEST("pseries-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
+    DO_TEST("pseries-hostdev", 2168455168);
+
+    DO_TEST("pseries-hardlimit+locked", 2147483648);
+    DO_TEST("pseries-hardlimit+hostdev", 2147483648);
+    DO_TEST("pseries-hardlimit+locked+hostdev", 2147483648);
+    DO_TEST("pseries-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
+
+    qemuTestDriverFree(&driver);
+
+    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+VIRT_TEST_MAIN(mymain)
+
+#else
+
+int
+main(void)
+{
+    return EXIT_AM_SKIP;
+}
+
+#endif /* WITH_QEMU */
-- 
2.7.4




More information about the libvir-list mailing list