From nobody Mon Feb 9 23:42:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1490293037785644.9962032892895; Thu, 23 Mar 2017 11:17:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1485718E3C7; Thu, 23 Mar 2017 18:17:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (unknown [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D1B1B17587; Thu, 23 Mar 2017 18:17:16 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7BA2D5EC67; Thu, 23 Mar 2017 18:17:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v2NIH1sp011516 for ; Thu, 23 Mar 2017 14:17:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0DB9F53C3A; Thu, 23 Mar 2017 18:17:01 +0000 (UTC) Received: from inaba.usersys.redhat.com (unknown [10.34.129.229]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A27B831A3 for ; Thu, 23 Mar 2017 18:17:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1485718E3C7 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1485718E3C7 From: Andrea Bolognani To: libvir-list@redhat.com Date: Thu, 23 Mar 2017 19:16:46 +0100 Message-Id: <1490293007-27030-8-git-send-email-abologna@redhat.com> In-Reply-To: <1490293007-27030-1-git-send-email-abologna@redhat.com> References: <1490293007-27030-1-git-send-email-abologna@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 7/8] tests: Introduce QEMU memory locking limit tests X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Mar 2017 18:17:17 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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 | 172 +++++++++++++++++= ++++ 20 files changed, 475 insertions(+) create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hardlimit+hostdev.= xml create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked+h= ostdev.xml create mode 100644 tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked.x= ml 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+hos= tdev.xml create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-hardlimit+loc= ked+hostdev.xml create mode 100644 tests/qemumemlockdata/qemumemlock-pseries-hardlimit+loc= ked.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+hostde= v.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 af69a3a..ccf5ee1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -127,6 +127,7 @@ EXTRA_DIST =3D \ qemumonitorjsondata \ qemuxml2argvdata \ qemuxml2xmloutdata \ + qemumemlockdata \ secretxml2xmlin \ securityselinuxhelperdata \ securityselinuxlabeldata \ @@ -276,6 +277,7 @@ test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ qemuargv2xmltest qemuhelptest domainsnapshotxml2xmltest \ qemumonitortest qemumonitorjsontest qemuhotplugtest \ qemuagenttest qemucapabilitiestest qemucaps2xmltest \ + qemumemlocktest \ qemucommandutiltest test_helpers +=3D qemucapsprobe test_libraries +=3D libqemumonitortestutils.la \ @@ -658,6 +660,12 @@ domainsnapshotxml2xmltest_SOURCES =3D \ domainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h domainsnapshotxml2xmltest_LDADD =3D $(qemu_LDADDS) $(LDADDS) + +qemumemlocktest_SOURCES =3D \ + qemumemlocktest.c \ + testutilsqemu.c testutilsqemu.h \ + testutils.c testutils.h +qemumemlocktest_LDADD =3D $(qemu_LDADDS) $(LDADDS) else ! WITH_QEMU EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \ qemuhelptest.c domainsnapshotxml2xmltest.c \ @@ -665,6 +673,7 @@ EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c qe= muargv2xmltest.c \ qemumonitorjsontest.c qemuhotplugtest.c \ qemuagenttest.c qemucapabilitiestest.c \ qemucaps2xmltest.c qemucommandutiltest.c \ + qemumemlocktest.c \ $(QEMUMONITORTESTUTILS_SOURCES) endif ! WITH_QEMU =20 diff --git a/tests/qemumemlockdata/qemumemlock-pc-hardlimit+hostdev.xml b/t= ests/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 @@ + + guest + 1048576 + + 2097152 + + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + +
+ + + + 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 @@ + + guest + 1048576 + + 2097152 + + + + + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + +
+ + + + diff --git a/tests/qemumemlockdata/qemumemlock-pc-hardlimit+locked.xml b/te= sts/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 @@ + + guest + 1048576 + + 2097152 + + + + + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + diff --git a/tests/qemumemlockdata/qemumemlock-pc-hardlimit.xml b/tests/qem= umemlockdata/qemumemlock-pc-hardlimit.xml new file mode 100644 index 0000000..b1e3867 --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pc-hardlimit.xml @@ -0,0 +1,14 @@ + + guest + 1048576 + + 2097152 + + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + diff --git a/tests/qemumemlockdata/qemumemlock-pc-hostdev.xml b/tests/qemum= emlockdata/qemumemlock-pc-hostdev.xml new file mode 100644 index 0000000..6c058a9 --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pc-hostdev.xml @@ -0,0 +1,17 @@ + + guest + 1048576 + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + +
+ + + + diff --git a/tests/qemumemlockdata/qemumemlock-pc-kvm.xml b/tests/qemumemlo= ckdata/qemumemlock-pc-kvm.xml new file mode 100644 index 0000000..7fa4e24 --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pc-kvm.xml @@ -0,0 +1,11 @@ + + guest + 1048576 + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + diff --git a/tests/qemumemlockdata/qemumemlock-pc-locked+hostdev.xml b/test= s/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 @@ + + guest + 1048576 + + + + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + + +
+ + + + diff --git a/tests/qemumemlockdata/qemumemlock-pc-locked.xml b/tests/qemume= mlockdata/qemumemlock-pc-locked.xml new file mode 100644 index 0000000..febb036 --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pc-locked.xml @@ -0,0 +1,14 @@ + + guest + 1048576 + + + + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + diff --git a/tests/qemumemlockdata/qemumemlock-pc-tcg.xml b/tests/qemumemlo= ckdata/qemumemlock-pc-tcg.xml new file mode 100644 index 0000000..1934269 --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pc-tcg.xml @@ -0,0 +1,11 @@ + + guest + 1048576 + 1 + + hvm + + + /usr/bin/qemu-system-x86_64 + + diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+hostdev.xm= l 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 @@ + + guest + 1048576 + + 2097152 + + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + + +
+ + + + diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked+hos= tdev.xml b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked+hostd= ev.xml new file mode 100644 index 0000000..73c28c1 --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pseries-hardlimit+locked+hostdev.xml @@ -0,0 +1,23 @@ + + guest + 1048576 + + 2097152 + + + + + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + + +
+ + + + 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 @@ + + guest + 1048576 + + 2097152 + + + + + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + diff --git a/tests/qemumemlockdata/qemumemlock-pseries-hardlimit.xml b/test= s/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 @@ + + guest + 1048576 + + 2097152 + + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + 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 @@ + + guest + 1048576 + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + + +
+ + + + diff --git a/tests/qemumemlockdata/qemumemlock-pseries-kvm.xml b/tests/qemu= memlockdata/qemumemlock-pseries-kvm.xml new file mode 100644 index 0000000..5a065da --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pseries-kvm.xml @@ -0,0 +1,11 @@ + + guest + 1048576 + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + 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 @@ + + guest + 1048576 + + + + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + + +
+ + + + diff --git a/tests/qemumemlockdata/qemumemlock-pseries-locked.xml b/tests/q= emumemlockdata/qemumemlock-pseries-locked.xml new file mode 100644 index 0000000..befaefd --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pseries-locked.xml @@ -0,0 +1,14 @@ + + guest + 1048576 + + + + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + diff --git a/tests/qemumemlockdata/qemumemlock-pseries-tcg.xml b/tests/qemu= memlockdata/qemumemlock-pseries-tcg.xml new file mode 100644 index 0000000..a3b03dd --- /dev/null +++ b/tests/qemumemlockdata/qemumemlock-pseries-tcg.xml @@ -0,0 +1,11 @@ + + guest + 1048576 + 1 + + hvm + + + /usr/bin/qemu-system-ppc64 + + diff --git a/tests/qemumemlocktest.c b/tests/qemumemlocktest.c new file mode 100644 index 0000000..9e65622 --- /dev/null +++ b/tests/qemumemlocktest.c @@ -0,0 +1,172 @@ +#include + +#include +#include +#include +#include + +#include +#include + +#include "testutils.h" + +#ifdef WITH_QEMU + +# include "datatypes.h" +# include "internal.h" +# include "virstring.h" +# include "conf/domain_conf.h" +# include "qemu/qemu_capabilities.h" +# include "qemu/qemu_process.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 =3D data; + virConnectPtr conn =3D NULL; + virDomainObjPtr vm =3D NULL; + virCommandPtr cmd =3D NULL; + char *xml =3D NULL; + int ret =3D -1; + + if (!(conn =3D virGetConnect())) + goto cleanup; + + if (virAsprintf(&xml, "%s/qemumemlockdata/qemumemlock-%s.xml", + abs_srcdir, info->name) < 0) + goto cleanup; + + if (!(vm =3D virDomainObjNew(driver.xmlopt))) + goto cleanup; + + if (!(vm->def =3D virDomainDefParseFile(xml, driver.caps, driver.xmlop= t, NULL, + VIR_DOMAIN_DEF_PARSE_INACTIVE)))= { + goto cleanup; + } + + if (!(cmd =3D qemuProcessCreatePretendCmd(conn, &driver, vm, NULL, 0, = false, + VIR_QEMU_PROCESS_START_COLD)))= { + goto cleanup; + } + + if (virTestCompareToULL(info->memlock, virCommandGetMaxMemLock(cmd)) <= 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virCommandFree(cmd); + virObjectUnref(vm); + virObjectUnref(conn); + VIR_FREE(xml); + + return ret; +} + + +int +main(void) +{ + virQEMUCapsPtr qemuCaps =3D NULL; + int ret =3D 0; + + abs_top_srcdir =3D getenv("abs_top_srcdir"); + if (!abs_top_srcdir) + abs_top_srcdir =3D abs_srcdir "/.."; + + if (qemuTestDriverInit(&driver) < 0) + return EXIT_FAILURE; + + driver.privileged =3D true; + + /* QEMU capabilites are the same for all tests */ + if (!(qemuCaps =3D virQEMUCapsNew())) + return EXIT_FAILURE; + + virQEMUCapsSetList(qemuCaps, + QEMU_CAPS_KVM, QEMU_CAPS_REALTIME_MLOCK, + QEMU_CAPS_DEVICE_VFIO_PCI); + + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, "qemumemlock", qemuC= aps) < 0) + return EXIT_FAILURE; + + virObjectUnref(qemuCaps); + +# define DO_TEST(name, memlock) \ + do { \ + static struct testInfo info =3D { \ + name, memlock \ + }; \ + if (virTestRun("QEMU MEMLOCK " name, testCompareMemLock, &info) < = 0) \ + ret =3D -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 has been configured + * locked: guest where 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 =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +#else + +int main(void) +{ + return EXIT_AM_SKIP; +} + +#endif /* WITH_QEMU */ --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list