From nobody Sun May 5 02:07:56 2024 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1548277188829609.7925530538885; Wed, 23 Jan 2019 12:59:48 -0800 (PST) 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 E023DC7A17; Wed, 23 Jan 2019 20:59:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AD49E5D6A6; Wed, 23 Jan 2019 20:59:46 +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 5AA653F954; Wed, 23 Jan 2019 20:59:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0NKxYth026147 for ; Wed, 23 Jan 2019 15:59:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9E82A6C1F1; Wed, 23 Jan 2019 20:59:34 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-31.phx2.redhat.com [10.3.116.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57C2E6A685 for ; Wed, 23 Jan 2019 20:59:34 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 23 Jan 2019 15:59:27 -0500 Message-Id: <20190123205928.14800-2-jferlan@redhat.com> In-Reply-To: <20190123205928.14800-1-jferlan@redhat.com> References: <20190123205928.14800-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/2] tests: Add mocking for qemuMonitorJSONGetSEVCapabilities 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: , 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.39]); Wed, 23 Jan 2019 20:59:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Commit d4005609 added "altered" capabilities replies output in order to fake a 'query-sev-capabilities' reply from QEMU. This worked fine for the 2.12 processing for qemuxml2argvtest until the next capabilities was generated and the output wasn't doctored. Thus commit 6c50cef8 used DO_TEST_CAPS_VER against 2.12.0 noting that the 2.12.0 capabilities were hand edited to add AMD specific output into an Intel capabilities reply. Instead of "altering" the output or running against a specific reply that we know was altered, let's instead use the mocking capabilities to check the return from a real call and mock up return data if we determine the returned real call doesn't support compiled-in SEV. This way the qemuxml2argvtest can use the DO_TEST_CAPS_LATEST which runs only for x86_64 to determine that noting in "latest" changes with respect to SEV and effectively fake things out to generate expected output ensuring that other changes to libvirt/qemu don't somehow affect SEV support. Signed-off-by: John Ferlan Reviewed-by: Cole Robinson --- tests/qemucapsprobemock.c | 50 +++++++++++++++++++ ...=3D> launch-security-sev.x86_64-latest.args} | 0 tests/qemuxml2argvtest.c | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) rename tests/qemuxml2argvdata/{launch-security-sev.x86_64-2.12.0.args =3D>= launch-security-sev.x86_64-latest.args} (100%) diff --git a/tests/qemucapsprobemock.c b/tests/qemucapsprobemock.c index f3f17f2116..0351b946b2 100644 --- a/tests/qemucapsprobemock.c +++ b/tests/qemucapsprobemock.c @@ -22,9 +22,15 @@ #include "internal.h" #include "viralloc.h" #include "virjson.h" +#include "virlog.h" +#include "virstring.h" #include "qemu/qemu_monitor.h" #include "qemu/qemu_monitor_json.h" =20 +#define VIR_FROM_THIS VIR_FROM_NONE + +VIR_LOG_INIT("tests.qemucapsprobemock"); + #define REAL_SYM(realFunc) \ do { \ if (!realFunc && !(realFunc =3D dlsym(RTLD_NEXT, __FUNCTION__))) {= \ @@ -120,3 +126,47 @@ qemuMonitorJSONIOProcessLine(qemuMonitorPtr mon, virJSONValueFree(value); return ret; } + + +static int (*realQemuMonitorJSONGetSEVCapabilities)(qemuMonitorPtr mon, + virSEVCapability **cap= abilities); + +int +qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon, + virSEVCapability **capabilities) +{ + int ret =3D -1; + VIR_AUTOPTR(virSEVCapability) capability =3D NULL; + + VIR_DEBUG("mocked qemuMonitorJSONGetSEVCapabilities"); + + REAL_SYM(realQemuMonitorJSONGetSEVCapabilities); + + ret =3D realQemuMonitorJSONGetSEVCapabilities(mon, capabilities); + + if (ret =3D=3D 0) { + /* QEMU has only compiled-in support of SEV in which case we + * can mock up a response instead since generation of SEV output + * is only possible on AMD hardware. Since the qemuxml2argvtest + * doesn't currently distinguish between AMD and Intel for x86_64 + * if we "alter" the pseudo failure we can at least allow the + * test to succeed using the latest replies rather than a specific + * version with altered reply data */ + if (VIR_ALLOC(capability) < 0) + return -1; + + if (VIR_STRDUP(capability->pdh, "Unchecked, but mocked pdh") < 0) + return -1; + + if (VIR_STRDUP(capability->cert_chain, "Mocked cert_chain too") < = 0) + return -1; + + capability->cbitpos =3D 47; + capability->reduced_phys_bits =3D 1; + VIR_STEAL_PTR(*capabilities, capability); + + return 1; + } + + return ret; +} diff --git a/tests/qemuxml2argvdata/launch-security-sev.x86_64-2.12.0.args = b/tests/qemuxml2argvdata/launch-security-sev.x86_64-latest.args similarity index 100% rename from tests/qemuxml2argvdata/launch-security-sev.x86_64-2.12.0.args rename to tests/qemuxml2argvdata/launch-security-sev.x86_64-latest.args diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index ba6fd4db35..c65f6f91ee 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3068,7 +3068,7 @@ mymain(void) DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw", "s390x"); DO_TEST_CAPS_ARCH_LATEST("vhost-vsock-ccw-auto", "s390x"); =20 - DO_TEST_CAPS_VER("launch-security-sev", "2.12.0"); + DO_TEST_CAPS_LATEST("launch-security-sev"); =20 DO_TEST("riscv64-virt", QEMU_CAPS_DEVICE_VIRTIO_MMIO); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 02:07:56 2024 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154827718256546.193431080638675; Wed, 23 Jan 2019 12:59:42 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D18927FDE6; Wed, 23 Jan 2019 20:59:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 78C8F1019633; Wed, 23 Jan 2019 20:59:39 +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 28AEC180339F; Wed, 23 Jan 2019 20:59:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0NKxZOn026152 for ; Wed, 23 Jan 2019 15:59:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1F9B16A685; Wed, 23 Jan 2019 20:59:35 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-31.phx2.redhat.com [10.3.116.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id CABA36C207 for ; Wed, 23 Jan 2019 20:59:34 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Wed, 23 Jan 2019 15:59:28 -0500 Message-Id: <20190123205928.14800-3-jferlan@redhat.com> In-Reply-To: <20190123205928.14800-1-jferlan@redhat.com> References: <20190123205928.14800-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/2] tests: Document procedure to build QEMU for *.replies generation 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 23 Jan 2019 20:59:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add some comments to describe how to set up the QEMU environment prior to running the qemucapsprobe in order to allow for the creation of consistent results. Signed-off-by: John Ferlan Reviewed-by: Cole Robinson --- tests/qemucapabilitiestest.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index 00137bb415..2b6291e99e 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -200,11 +200,41 @@ mymain(void) DO_TEST("riscv64", "caps_3.0.0"); =20 /* + * Create a QEMU build environment using a checked out version + * of the release tag, such as: + * + * git checkout -b v3.0.0 v3.0.0 + * + * Be sure the build dependencies are up to date, such as via yum: + * + * yum builddep qemu + * + * Configure the environment, such as for x86_64: + * + * ./configure --target-list=3Dx86_64-softmmu \ + * --disable-xen --disable-strip --disable-fdt \ + * --disable-werror --enable-debug \ + * --enable-system --enable-user --enable-linux-user \ + * --with-pkgversion=3Dv3.0.0 + * + * Build the QEMU emulator binary. + * + * Then from a clean libvirt build: + * * Run "tests/qemucapsprobe /path/to/qemu/binary >foo.replies" - * to generate updated or new *.replies data files. + * to generate updated or new *.replies data files, such as: + * + * tests/qemucapsprobe /path/to/qemu/binary > \ + * tests/qemucapabilitiesdata/caps_3.0.0.x86_64.replies * - * If you manually edit replies files you can run + * If you needed to manually edit replies files you can run * "tests/qemucapsfixreplies foo.replies" to fix the replies ids. + * + * Run "VIR_TEST_REGENERATE_OUTPUT=3D1 tests/qemucapabilitiestest" to + * update the corresponding tests/qemucapabilitiesdata/caps_*.xml file. + * + * May also need to run "VIR_TEST_REGENERATE_OUTPUT=3D1 tests/domainca= pstest" + * depending on what changed. */ =20 qemuTestDriverFree(&data.driver); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list