From nobody Sun Feb 8 16:06:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 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=1584987187; cv=none; d=zohomail.com; s=zohoarc; b=TWgm92aDN2ztezckkG3vjH5s9w3bpxcc2ltnW82OE5Rp8RZiutulJC789UdRtGA6Uxt+LK3GMEF9byOVK5mpUXO8tGmcVGU82NrIZNjWETVK3c515OPBzIN7kBN+RBHvE2Roi4VJkNE1EREMELfhplw5ADeQVe8Vb0iOGQHKoFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584987187; 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=3T6+FcmWW1NMSr37Nlu2uIQ3ex6CDhJsLF8jbjM44z4=; b=cd1l4Ul28PbRUcRiQX+0CD2mwhZyJVUSDk5WhVwkqX0Rqx21WUi9T/aFrEQTjVzb3e1K/qhLHIA0Cx+lYGG9glNcBj0xNFrbQk12kReSIpsILK4dlkVBecnSGM1zfQcO34lHUK/b9FLEpxvrnon0HCYi1CwT1CQFxGJIH0LXmpg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584987187682658.3748045926634; Mon, 23 Mar 2020 11:13:07 -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-354-Pzk0GRKRM-6Xc8a7MI8Y2A-1; Mon, 23 Mar 2020 14:12:33 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 28199800D50; Mon, 23 Mar 2020 18:12:28 +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 F39565C545; Mon, 23 Mar 2020 18:12:27 +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 A532E8639F; Mon, 23 Mar 2020 18:12:27 +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 02NICEG3009484 for ; Mon, 23 Mar 2020 14:12:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id BF92A91290; Mon, 23 Mar 2020 18:12:14 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 46C708D574 for ; Mon, 23 Mar 2020 18:12:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584987186; 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=3T6+FcmWW1NMSr37Nlu2uIQ3ex6CDhJsLF8jbjM44z4=; b=VYbx9vL3zSvkPkvmHnQmBRLnSe/aKrjSxA17Dn1pNeReeg3UtbrvWREb5XOv6HGx9xXgCK RglPlKzqVD8kj9PrVCEoueD8b8CSjSn2D9PgT4xLmOzTy3wqRPPrpEYZAMfRA8WKkvYEDu n0YlF7PlG7o+rS44zGJmlVjCK024Mgk= X-MC-Unique: Pzk0GRKRM-6Xc8a7MI8Y2A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/14] testQemuDiskXMLToProps: Store all per-image data in one structure Date: Mon, 23 Mar 2020 19:11:57 +0100 Message-Id: <808a28077e4ece54a5e24ec26e7bf7b0737c7d64.1584986997.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.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" We had two non-syncrhonized arrays holding the individual data. This was a lazy way to do it when I was adding new tests recently. Since it's hard to extend with new data to test refactor the storage of test data to use a new struct where all per-image data are kept and can be extended easily. Signed-off-by: Peter Krempa --- tests/qemublocktest.c | 90 ++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 36 deletions(-) diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 312af0d962..47d08333f7 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -180,6 +180,13 @@ testJSONtoJSON(const void *args) } +struct testQemuDiskXMLToJSONImageData { + virJSONValuePtr formatprops; + virJSONValuePtr storageprops; + virJSONValuePtr storagepropssrc; +}; + + struct testQemuDiskXMLToJSONData { virQEMUDriverPtr driver; virHashTablePtr schema; @@ -187,11 +194,8 @@ struct testQemuDiskXMLToJSONData { const char *name; bool fail; - virJSONValuePtr *props; - size_t nprops; - - virJSONValuePtr *propssrc; - size_t npropssrc; + struct testQemuDiskXMLToJSONImageData *images; + size_t nimages; virQEMUCapsPtr qemuCaps; }; @@ -202,16 +206,13 @@ testQemuDiskXMLToPropsClear(struct testQemuDiskXMLToJ= SONData *data) { size_t i; - for (i =3D 0; i < data->nprops; i++) - virJSONValueFree(data->props[i]); - - for (i =3D 0; i < data->npropssrc; i++) - virJSONValueFree(data->propssrc[i]); - - data->nprops =3D 0; - VIR_FREE(data->props); - data->npropssrc =3D 0; - VIR_FREE(data->propssrc); + for (i =3D 0; i < data->nimages; i++) { + virJSONValueFree(data->images[i].formatprops); + virJSONValueFree(data->images[i].storageprops); + virJSONValueFree(data->images[i].storagepropssrc); + } + data->nimages =3D 0; + VIR_FREE(data->images); } @@ -286,6 +287,7 @@ testQemuDiskXMLToProps(const void *opaque) } for (n =3D disk->src; virStorageSourceIsBacking(n); n =3D n->backingSt= ore) { + if (testQemuDiskXMLToJSONFakeSecrets(n) < 0) return -1; @@ -306,10 +308,14 @@ testQemuDiskXMLToProps(const void *opaque) return -1; } - if (VIR_APPEND_ELEMENT(data->props, data->nprops, formatProps) < 0= || - VIR_APPEND_ELEMENT(data->props, data->nprops, storageProps) < = 0 || - VIR_APPEND_ELEMENT(data->propssrc, data->npropssrc, storageSrc= OnlyProps) < 0) + if (VIR_REALLOC_N(data->images, data->nimages + 1) < 0) return -1; + + data->images[data->nimages].formatprops =3D g_steal_pointer(&forma= tProps); + data->images[data->nimages].storageprops =3D g_steal_pointer(&stor= ageProps); + data->images[data->nimages].storagepropssrc =3D g_steal_pointer(&s= torageSrcOnlyProps); + + data->nimages++; } return 0; @@ -326,27 +332,37 @@ testQemuDiskXMLToPropsValidateSchema(const void *opaq= ue) if (data->fail) return EXIT_AM_SKIP; - for (i =3D 0; i < data->nprops; i++) { + for (i =3D 0; i < data->nimages; i++) { g_auto(virBuffer) debug =3D VIR_BUFFER_INITIALIZER; - if (testQEMUSchemaValidate(data->props[i], data->schemaroot, + if (testQEMUSchemaValidate(data->images[i].formatprops, data->sche= maroot, data->schema, &debug) < 0) { g_autofree char *debugmsg =3D virBufferContentAndReset(&debug); - g_autofree char *propsstr =3D virJSONValueToString(data->props= [i], true); + g_autofree char *propsstr =3D virJSONValueToString(data->image= s[i].formatprops, true); VIR_TEST_VERBOSE("json does not conform to QAPI schema"); VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output= :\n %s", propsstr, NULLSTR(debugmsg)); ret =3D -1; } - } - for (i =3D 0; i < data->npropssrc; i++) { - g_auto(virBuffer) debug =3D VIR_BUFFER_INITIALIZER; + virBufferFreeAndReset(&debug); - if (testQEMUSchemaValidate(data->propssrc[i], data->schemaroot, + if (testQEMUSchemaValidate(data->images[i].storageprops, data->sch= emaroot, data->schema, &debug) < 0) { g_autofree char *debugmsg =3D virBufferContentAndReset(&debug); - g_autofree char *propsstr =3D virJSONValueToString(data->props= src[i], true); + g_autofree char *propsstr =3D virJSONValueToString(data->image= s[i].storageprops, true); + VIR_TEST_VERBOSE("json does not conform to QAPI schema"); + VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output= :\n %s", + propsstr, NULLSTR(debugmsg)); + ret =3D -1; + } + + virBufferFreeAndReset(&debug); + + if (testQEMUSchemaValidate(data->images[i].storagepropssrc, data->= schemaroot, + data->schema, &debug) < 0) { + g_autofree char *debugmsg =3D virBufferContentAndReset(&debug); + g_autofree char *propsstr =3D virJSONValueToString(data->image= s[i].storagepropssrc, true); VIR_TEST_VERBOSE("json does not conform to QAPI schema"); VIR_TEST_DEBUG("json:\n%s\ndoes not match schema. Debug output= :\n %s", propsstr, NULLSTR(debugmsg)); @@ -372,13 +388,17 @@ testQemuDiskXMLToPropsValidateFile(const void *opaque) jsonpath =3D g_strdup_printf("%s%s.json", testQemuDiskXMLToJSONPath, d= ata->name); - for (i =3D 0; i < data->nprops; i++) { - g_autofree char *jsonstr =3D NULL; + for (i =3D 0; i < data->nimages; i++) { + g_autofree char *formatprops =3D NULL; + g_autofree char *storageprops =3D NULL; - if (!(jsonstr =3D virJSONValueToString(data->props[i], true))) + if (!(formatprops =3D virJSONValueToString(data->images[i].formatp= rops, true))) return -1; - virBufferAdd(&buf, jsonstr, -1); + if (!(storageprops =3D virJSONValueToString(data->images[i].storag= eprops, true))) + return -1; + + virBufferStrcat(&buf, formatprops, storageprops, NULL); } actual =3D virBufferContentAndReset(&buf); @@ -402,10 +422,10 @@ testQemuDiskXMLToPropsValidateFileSrcOnly(const void = *opaque) jsonpath =3D g_strdup_printf("%s%s-srconly.json", testQemuDiskXMLToJSO= NPath, data->name); - for (i =3D 0; i < data->npropssrc; i++) { + for (i =3D 0; i < data->nimages; i++) { g_autofree char *jsonstr =3D NULL; - if (!(jsonstr =3D virJSONValueToString(data->propssrc[i], true))) + if (!(jsonstr =3D virJSONValueToString(data->images[i].storageprop= ssrc, true))) return -1; virBufferAdd(&buf, jsonstr, -1); @@ -1117,10 +1137,8 @@ mymain(void) #define TEST_DISK_TO_JSON_FULL(nme, fl) \ do { \ diskxmljsondata.name =3D nme; \ - diskxmljsondata.props =3D NULL; \ - diskxmljsondata.nprops =3D 0; \ - diskxmljsondata.propssrc =3D NULL; \ - diskxmljsondata.npropssrc =3D 0; \ + diskxmljsondata.images =3D NULL; \ + diskxmljsondata.nimages =3D 0; \ diskxmljsondata.fail =3D fl; \ if (virTestRun("disk xml to props " nme, testQemuDiskXMLToProps, \ &diskxmljsondata) < 0) \ --=20 2.24.1