From nobody Mon Feb 9 03:59:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629217686; cv=none; d=zohomail.com; s=zohoarc; b=irrw8au3x9Nlrr7RNApRKTPSCtWSuq4e9AJWAwnHwLmkBXqreEU7iuKNY0cDuL7pki7aliLhh3bwfgYCq+H3duLANSiSrHX6cHCOpWlRnkBKBRagnXefXDWQBfzJa7ycQHDrTA9JyYvcFN7rHRsb83gIC3dXiAHTp8XniInLJrc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629217686; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=H3wyYQW0inqvW3SWzMHXN1y77vz2C9IR3NeZpB1sXrE=; b=JYCMe7JLXQwbfBJDnWzWnUzAu2Kn39uPQYjzeXbb+Hc8HWYZys+z9aEnkHKATlEiSecaI2WVjjZHdfat99FP9F5MeMdWhvOPlucQGZPG4UCd9QW+56/OhqKVi1zrIrLGNcbqQe9qnvmPwWRX2SvGHRYTYNEYWcegTRpQXXWIkc0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1629217686719652.4951066967171; Tue, 17 Aug 2021 09:28:06 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-218-VB5Mp4xKObyzyMdxfCOhEg-1; Tue, 17 Aug 2021 12:26:52 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4F93A9115C; Tue, 17 Aug 2021 16:26:31 +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 2346A10016FF; Tue, 17 Aug 2021 16:26:31 +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 DA69A181A6E3; Tue, 17 Aug 2021 16:26:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17HGQQQX020938 for ; Tue, 17 Aug 2021 12:26:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD3EB421F; Tue, 17 Aug 2021 16:26:26 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F2AA19C87 for ; Tue, 17 Aug 2021 16:26:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629217685; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=H3wyYQW0inqvW3SWzMHXN1y77vz2C9IR3NeZpB1sXrE=; b=apteJwjRL4oMHA/VHfzJF9mC2aDe4C0JWFkPPiD55rk8x3/IQrMX/y196QHfLb4pkljxcx VCGEJeCO4Sw5jRiTc0wDtTSn5Fik+yf5e9j8CkdicK/dVNMhQQljoA/hF9kYYfmuSQvhD5 94MWZNAA96xRZzKzxR/vziPVRpj3WHQ= X-MC-Unique: VB5Mp4xKObyzyMdxfCOhEg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH v2 21/23] testutilsqemu: Improve error propagation from 'testQemuInfoSetArgs' Date: Tue, 17 Aug 2021 18:25:22 +0200 Message-Id: <7f2435d62f07de94eb9d173a9e7d21e395d97312.1629217367.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629217688409100001 Content-Type: text/plain; charset="utf-8" Previously we've ran into problems when 'testQemuInfoSetArgs' failed as calling the actual test executor could lead to a crash if the data wasn't prepared but reporting an error doesn't play nicely with our test output which is handled by 'virTestRun'. To avoid the issue (and as a side effect improve compilation times of the test files) split up testQemuInfoSetArgs into two functions. The first is still called 'testQemuInfoSetArgs' and just blindly populates arguments into a sub-struct of testQemuInfo. This function no longer reports errors A new function 'testQemuInfoInitArgs' which is meant to be called from the test executor then checks errors and prepares the test data. This one can fail and the test will be marked as failed appropriately. A nice side effect is that this vastly improves compile times of qemuxml2xmltest and qemuxml2argvtest. Signed-off-by: Peter Krempa --- tests/qemustatusxml2xmltest.c | 12 +++-- tests/qemuxml2argvtest.c | 6 ++- tests/qemuxml2xmltest.c | 17 +++---- tests/testutilsqemu.c | 93 ++++++++++++++++++++--------------- tests/testutilsqemu.h | 18 +++++-- 5 files changed, 87 insertions(+), 59 deletions(-) diff --git a/tests/qemustatusxml2xmltest.c b/tests/qemustatusxml2xmltest.c index 995ef68a4c..d58f4b69da 100644 --- a/tests/qemustatusxml2xmltest.c +++ b/tests/qemustatusxml2xmltest.c @@ -23,6 +23,12 @@ testCompareStatusXMLToXMLFiles(const void *opaque) g_autofree char *actual =3D NULL; int ret =3D -1; + if (testQemuInfoInitArgs((struct testQemuInfo *) data) < 0) + return -1; + + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, data->qemuCaps) < 0) + return -1; + if (!(obj =3D virDomainObjParseFile(data->infile, driver.xmlopt, VIR_DOMAIN_DEF_PARSE_STATUS | VIR_DOMAIN_DEF_PARSE_ACTUAL_NET | @@ -112,11 +118,7 @@ mymain(void) static struct testQemuInfo info =3D { \ .name =3D _name, \ }; \ - if (testQemuInfoSetArgs(&info, &testConf, ARG_END) < 0 || \ - qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) <= 0) { \ - VIR_TEST_DEBUG("Failed to generate status test data for '%s'",= _name); \ - return -1; \ - } \ + testQemuInfoSetArgs(&info, &testConf, ARG_END); \ testInfoSetStatusPaths(&info); \ \ if (virTestRun("QEMU status XML-2-XML " _name, \ diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 0dbb6ad94b..34b92c4a35 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -653,6 +653,9 @@ testCompareXMLToArgv(const void *data) virArch arch =3D VIR_ARCH_NONE; g_autoptr(virIdentity) sysident =3D virIdentityGetSystem(); + if (testQemuInfoInitArgs((struct testQemuInfo *) info) < 0) + goto cleanup; + if (info->arch !=3D VIR_ARCH_NONE && info->arch !=3D VIR_ARCH_X86_64) qemuTestSetHostArch(&driver, info->arch); @@ -943,8 +946,7 @@ mymain(void) static struct testQemuInfo info =3D { \ .name =3D _name, \ }; \ - if (testQemuInfoSetArgs(&info, &testConf, __VA_ARGS__) < 0) \ - ret =3D -1; \ + testQemuInfoSetArgs(&info, &testConf, __VA_ARGS__); \ testInfoSetPaths(&info, _suffix); \ if (virTestRun("QEMU XML-2-ARGV " _name _suffix, \ testCompareXMLToArgv, &info) < 0) \ diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index e71b77b967..92fab7d169 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -32,11 +32,14 @@ enum { static int testXML2XMLCommon(const struct testQemuInfo *info) { - if (!(info->flags & FLAG_REAL_CAPS)) { + if (testQemuInfoInitArgs((struct testQemuInfo *) info) < 0) + return -1; + + if (!(info->flags & FLAG_REAL_CAPS)) virQEMUCapsInitQMPBasicArch(info->qemuCaps); - if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) = < 0) - return -1; - } + + if (qemuTestCapsCacheInsert(driver.qemuCapsCache, info->qemuCaps) < 0) + return -1; return 0; } @@ -154,11 +157,7 @@ mymain(void) static struct testQemuInfo info =3D { \ .name =3D _name, \ }; \ - if (testQemuInfoSetArgs(&info, &testConf, __VA_ARGS__) < 0 || \ - qemuTestCapsCacheInsert(driver.qemuCapsCache, info.qemuCaps) <= 0) { \ - VIR_TEST_DEBUG("Failed to generate test data for '%s'", _name)= ; \ - ret =3D -1; \ - } \ + testQemuInfoSetArgs(&info, &testConf, __VA_ARGS__); \ \ if (when & WHEN_INACTIVE) { \ testInfoSetPaths(&info, suffix, WHEN_INACTIVE); \ diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c index 821f6e2707..81d4a44f9a 100644 --- a/tests/testutilsqemu.c +++ b/tests/testutilsqemu.c @@ -677,38 +677,32 @@ testQemuCapsIterate(const char *suffix, } -int +void testQemuInfoSetArgs(struct testQemuInfo *info, struct testQemuConf *conf, ...) { va_list argptr; testQemuInfoArgName argname; - g_autoptr(virQEMUCaps) fakeCaps =3D virQEMUCapsNew(); - bool fakeCapsUsed =3D false; - int gic =3D GIC_NONE; - char *capsarch =3D NULL; - char *capsver =3D NULL; - g_autofree char *capsfile =3D NULL; int flag; - int ret =3D -1; - if (!fakeCaps) + if (!(info->args.fakeCaps =3D virQEMUCapsNew())) abort(); info->conf =3D conf; + info->args.newargs =3D true; va_start(argptr, conf); while ((argname =3D va_arg(argptr, testQemuInfoArgName)) !=3D ARG_END)= { switch (argname) { case ARG_QEMU_CAPS: - fakeCapsUsed =3D true; + info->args.fakeCapsUsed =3D true; while ((flag =3D va_arg(argptr, int)) < QEMU_CAPS_LAST) - virQEMUCapsSet(fakeCaps, flag); + virQEMUCapsSet(info->args.fakeCaps, flag); break; case ARG_GIC: - gic =3D va_arg(argptr, int); + info->args.gic =3D va_arg(argptr, int); break; case ARG_MIGRATE_FROM: @@ -728,55 +722,77 @@ testQemuInfoSetArgs(struct testQemuInfo *info, break; case ARG_CAPS_ARCH: - capsarch =3D va_arg(argptr, char *); + info->args.capsarch =3D va_arg(argptr, char *); break; case ARG_CAPS_VER: - capsver =3D va_arg(argptr, char *); + info->args.capsver =3D va_arg(argptr, char *); break; case ARG_END: default: - fprintf(stderr, "Unexpected test info argument"); - goto cleanup; + info->args.invalidarg =3D true; + break; } + + if (info->args.invalidarg) + break; } - if (!!capsarch ^ !!capsver) { - fprintf(stderr, "ARG_CAPS_ARCH and ARG_CAPS_VER " - "must be specified together.\n"); - goto cleanup; + va_end(argptr); +} + + +int +testQemuInfoInitArgs(struct testQemuInfo *info) +{ + g_autofree char *capsfile =3D NULL; + + if (!info->args.newargs) + return 0; + + info->args.newargs =3D false; + + if (info->args.invalidarg) { + fprintf(stderr, "Invalid agument encountered by 'testQemuInfoSetAr= gs'\n"); + return -1; } - if (capsarch && capsver) { + if (!!info->args.capsarch ^ !!info->args.capsver) { + fprintf(stderr, "ARG_CAPS_ARCH and ARG_CAPS_VER must be specified = together.\n"); + return -1; + } + + if (info->args.capsarch && info->args.capsver) { bool stripmachinealiases =3D false; virQEMUCaps *cachedcaps =3D NULL; - if (fakeCapsUsed) { - fprintf(stderr, "ARG_QEMU_CAPS can not be combined with ARG_CA= PS_ARCH " - "or ARG_CAPS_VER\n"); - goto cleanup; + if (info->args.fakeCapsUsed) { + fprintf(stderr, "ARG_QEMU_CAPS can not be combined with ARG_CA= PS_ARCH or ARG_CAPS_VER\n"); + return -1; } - info->arch =3D virArchFromString(capsarch); + info->arch =3D virArchFromString(info->args.capsarch); - if (STREQ(capsver, "latest")) { - capsfile =3D g_strdup(virHashLookup(info->conf->capslatest, ca= psarch)); + if (STREQ(info->args.capsver, "latest")) { + capsfile =3D g_strdup(virHashLookup(info->conf->capslatest, in= fo->args.capsarch)); stripmachinealiases =3D true; } else { capsfile =3D g_strdup_printf("%s/caps_%s.%s.xml", - TEST_QEMU_CAPS_PATH, capsver, capsa= rch); + TEST_QEMU_CAPS_PATH, + info->args.capsver, + info->args.capsarch); } if (!g_hash_table_lookup_extended(info->conf->capscache, capsfile,= NULL, (void **) &cachedcaps)) { if (!(cachedcaps =3D qemuTestParseCapabilitiesArch(info->arch,= capsfile))) - goto cleanup; + return -1; g_hash_table_insert(info->conf->capscache, g_strdup(capsfile),= cachedcaps); } if (!(info->qemuCaps =3D virQEMUCapsNewCopy(cachedcaps))) - goto cleanup; + return -1; if (stripmachinealiases) virQEMUCapsStripMachineAliases(info->qemuCaps); @@ -787,18 +803,14 @@ testQemuInfoSetArgs(struct testQemuInfo *info, capsfile[strlen(capsfile) - 3] =3D '\0'; info->schemafile =3D g_strdup_printf("%sreplies", capsfile); } else { - info->qemuCaps =3D g_steal_pointer(&fakeCaps); + info->qemuCaps =3D g_steal_pointer(&info->args.fakeCaps); } - if (gic !=3D GIC_NONE && testQemuCapsSetGIC(info->qemuCaps, gic) < 0) - goto cleanup; - - ret =3D 0; - - cleanup: - va_end(argptr); + if (info->args.gic !=3D GIC_NONE && + testQemuCapsSetGIC(info->qemuCaps, info->args.gic) < 0) + return -1; - return ret; + return 0; } @@ -810,4 +822,5 @@ testQemuInfoClear(struct testQemuInfo *info) VIR_FREE(info->schemafile); VIR_FREE(info->errfile); virObjectUnref(info->qemuCaps); + g_clear_pointer(&info->args.fakeCaps, virObjectUnref); } diff --git a/tests/testutilsqemu.h b/tests/testutilsqemu.h index af7e756c05..d59fa53239 100644 --- a/tests/testutilsqemu.h +++ b/tests/testutilsqemu.h @@ -60,6 +60,16 @@ struct testQemuConf { GHashTable *qapiSchemaCache; }; +struct testQemuArgs { + bool newargs; + virQEMUCaps *fakeCaps; + bool fakeCapsUsed; + char *capsver; + char *capsarch; + int gic; + bool invalidarg; +}; + struct testQemuInfo { const char *name; char *infile; @@ -73,6 +83,7 @@ struct testQemuInfo { virArch arch; char *schemafile; + struct testQemuArgs args; struct testQemuConf *conf; }; @@ -116,9 +127,10 @@ int testQemuCapsIterate(const char *suffix, testQemuCapsIterateCallback callback, void *opaque); -int testQemuInfoSetArgs(struct testQemuInfo *info, - struct testQemuConf *conf, - ...); +void testQemuInfoSetArgs(struct testQemuInfo *info, + struct testQemuConf *conf, + ...); +int testQemuInfoInitArgs(struct testQemuInfo *info); void testQemuInfoClear(struct testQemuInfo *info); #endif --=20 2.31.1