From nobody Wed Jan 15 09:15:01 2025 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1704731686120727.6424152262128; Mon, 8 Jan 2024 08:34:46 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0578917B1; Mon, 8 Jan 2024 11:34:44 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6419F1A72; Mon, 8 Jan 2024 11:07:27 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 277151A84; Mon, 8 Jan 2024 11:06:44 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 80F8619DF for ; Mon, 8 Jan 2024 11:06:08 -0500 (EST) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-85-BB_0u6xeN7CfKQKkNoFgGA-1; Mon, 08 Jan 2024 11:06:06 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3DD188D12C for ; Mon, 8 Jan 2024 16:06:04 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F345C15E6A for ; Mon, 8 Jan 2024 16:06:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: BB_0u6xeN7CfKQKkNoFgGA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 09/23] qemuxmlactivetest: Prepare for proper active/inactive -> active/inactive testing Date: Mon, 8 Jan 2024 17:05:39 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: IIKZGMAOLTUBH72WSIY3JIG5CUM7GC7D X-Message-ID-Hash: IIKZGMAOLTUBH72WSIY3JIG5CUM7GC7D X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1704731687158100001 Currently the xml->xml testing we have in qemuxml2xmltest covers only 3 of the 4 possibilities: By invocation: active -> active; inactive -> inactive; by unintentionally: active -> inactive (for configs which don't set an 'id' as the formatter assumes it's inactive) To do it better introduce proper active -> inactive/active testing into qemuxmlactivetest. It's chosen such as we only really parse an XML as live when restoring a status XML. To give users possibility to avoid constructing a full status XML add a simpler variant. As of such it will be used only for configs where we specifically cared about parsing live data. To ensure that the formatter doesn't decide that a config is inactive because it doesn't have an ID we fill in a domain ID if it was not present in the source. In this patch the tests are not yet added. Signed-off-by: Peter Krempa --- tests/qemuxmlactivetest.c | 112 +++++++++++++++++++++++++++++++++++++- tests/testutilsqemu.c | 3 + tests/testutilsqemu.h | 3 + 3 files changed, 117 insertions(+), 1 deletion(-) diff --git a/tests/qemuxmlactivetest.c b/tests/qemuxmlactivetest.c index 65431863bd..f892a1fbbe 100644 --- a/tests/qemuxmlactivetest.c +++ b/tests/qemuxmlactivetest.c @@ -87,12 +87,118 @@ testRunStatus(const char *name, } +static int +testqemuActiveXML2XMLCommon(testQemuInfo *info, + bool live) +{ + g_autofree char *actual =3D NULL; + const char *outfile =3D info->out_xml_active; + unsigned int format_flags =3D VIR_DOMAIN_DEF_FORMAT_SECURE; + + /* Prepare the test data and parse the input just once */ + if (!info->def) { + if (testQemuInfoInitArgs((testQemuInfo *) info) < 0) + return -1; + + virFileCacheClear(driver.qemuCapsCache); + + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) = < 0) + return -1; + + if (!(info->def =3D virDomainDefParseFile(info->infile, + driver.xmlopt, NULL, + info->parseFlags))) + return -1; + + if (!virDomainDefCheckABIStability(info->def, info->def, driver.xm= lopt)) { + VIR_TEST_DEBUG("ABI stability check failed on %s", info->infil= e); + return -1; + } + + /* make sure that the XML definition looks active, by setting an ID + * as otherwise the XML formatter will simply assume that it's ina= ctive */ + if (info->def->id =3D=3D -1) + info->def->id =3D 1337; + } + + if (!live) { + format_flags |=3D VIR_DOMAIN_DEF_FORMAT_INACTIVE; + outfile =3D info->out_xml_inactive; + } + + if (!(actual =3D virDomainDefFormat(info->def, driver.xmlopt, format_f= lags))) { + VIR_TEST_VERBOSE("failed to format output XML\n"); + return -1; + } + + if (virTestCompareToFile(actual, outfile) < 0) + return -1; + + return 0; +} + + +static int +testqemuActiveXML2XMLActive(const void *opaque) +{ + testQemuInfo *info =3D (testQemuInfo *) opaque; + + return testqemuActiveXML2XMLCommon(info, true); +} + + +static int +testqemuActiveXML2XMLInactive(const void *opaque) +{ + testQemuInfo *info =3D (testQemuInfo *) opaque; + + return testqemuActiveXML2XMLCommon(info, false); +} + + +static void G_GNUC_UNUSED +testRunActive(const char *name, + const char *suffix, + struct testQemuConf *testConf, + int *ret, + ...) +{ + g_autofree char *name_active =3D g_strdup_printf("QEMU active-XML -> a= ctive-XML %s", name); + g_autofree char *name_inactive =3D g_strdup_printf("QEMU activeXML -> = inactive-XMLXML %s", name); + g_autoptr(testQemuInfo) info =3D g_new0(testQemuInfo, 1); + va_list ap; + + info->name =3D name; + info->conf =3D testConf; + + va_start(ap, ret); + testQemuInfoSetArgs(info, ap); + va_end(ap); + + info->infile =3D g_strdup_printf("%s/qemuxml2argvdata/%s.xml", abs_src= dir, + info->name); + + info->out_xml_active =3D g_strdup_printf("%s/qemuxmlactive2xmldata/%s-= active%s.xml", + abs_srcdir, info->name, suffix); + + info->out_xml_inactive =3D g_strdup_printf("%s/qemuxmlactive2xmldata/%= s-inactive%s.xml", + abs_srcdir, info->name, suffi= x); + + virTestRunLog(ret, name_inactive, testqemuActiveXML2XMLInactive, info); + virTestRunLog(ret, name_active, testqemuActiveXML2XMLActive, info); +} + + static int mymain(void) { int ret =3D 0; g_autoptr(virConnect) conn =3D NULL; - struct testQemuConf testConf =3D { NULL, NULL, NULL, NULL, NULL }; + g_autoptr(GHashTable) capslatest =3D testQemuGetLatestCaps(); + g_autoptr(GHashTable) capscache =3D virHashNew(virObjectUnref); + struct testQemuConf testConf =3D { .capslatest =3D capslatest, + .capscache =3D capscache, + .qapiSchemaCache =3D NULL }; if (qemuTestDriverInit(&driver) < 0) return EXIT_FAILURE; @@ -107,6 +213,10 @@ mymain(void) virSetConnectSecret(conn); virSetConnectStorage(conn); +#define DO_TEST_ACTIVE_CAPS_LATEST(_name) \ + testRunActive(_name, ".x86_64-latest", &testConf, &ret, \ + ARG_CAPS_ARCH, "x86_64", ARG_CAPS_VER, "latest", ARG_END= ); + #define DO_TEST_STATUS(_name) \ do { \ if (testRunStatus(_name, &testConf, ARG_END) < 0) \ diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 3799c2eb51..9c12a165b1 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -958,7 +958,10 @@ testQemuInfoFree(testQemuInfo *info) { VIR_FREE(info->infile); VIR_FREE(info->outfile); + VIR_FREE(info->out_xml_active); + VIR_FREE(info->out_xml_inactive); VIR_FREE(info->errfile); + virDomainDefFree(info->def); virObjectUnref(info->qemuCaps); g_clear_pointer(&info->args.fakeCapsAdd, virBitmapFree); g_clear_pointer(&info->args.fakeCapsDel, virBitmapFree); diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index 9343457f59..d31b7694cb 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -100,7 +100,10 @@ struct _testQemuInfo { const char *name; char *infile; char *outfile; + char *out_xml_active; + char *out_xml_inactive; char *errfile; + virDomainDef *def; /* parsed domain definition */ virQEMUCaps *qemuCaps; qemuNbdkitCaps *nbdkitCaps; const char *migrateFrom; --=20 2.43.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org