From nobody Mon Apr 29 04:22:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1640183095; cv=none; d=zohomail.com; s=zohoarc; b=I15j7kUTSr85jcWXwVRRLxqB19YCRKfBdp6EspDkd+ny+1uFtBnnPjDNK4eUI+xRpUN3FIrU2eyD6zVJEHfq1JNOfmP/S15A0FlAWqqhteVgM5yZqwhFmGS0ib8MV+8bFUYwhp+e9GnbNM3a/5923+2kssq7/h2y4G2wjrcYixE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640183095; 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=ZeDHUgbS/+o10rV2xDgS2Q0NIB9Ak78DtnnBEATHHTg=; b=MdMzFTSwBgKZlbXZ3stK55q56U69jT1nCyJx/9SWyNJAnlTthTZ1yHDAoDe0E3vwQE3+rAVP/pLv5K/MdboOVaHuk91x6L0rpKc4+2jMDKLIfVxKgDyQXDtlG5ET0z3Z8f6QfI2L+otdKyedr6mJgTeTZ8j5DRymuUBX8irlM28= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 164018309549339.79514996134037; Wed, 22 Dec 2021 06:24:55 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-111-Mn2FwivKOlWxZ_S6FzW8aw-1; Wed, 22 Dec 2021 09:24:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F1EEB801AAB; Wed, 22 Dec 2021 14:24:43 +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 D3F27ADD6; Wed, 22 Dec 2021 14:24:43 +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 25F8F4BB7C; Wed, 22 Dec 2021 14:24:43 +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 1BMEOVU3029912 for ; Wed, 22 Dec 2021 09:24:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 12E0170D28; Wed, 22 Dec 2021 14:24:31 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6288370D24 for ; Wed, 22 Dec 2021 14:24:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640183094; 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=ZeDHUgbS/+o10rV2xDgS2Q0NIB9Ak78DtnnBEATHHTg=; b=Qwi20FB0MeBWgiTI9YMJ1srATWTJqcTyPFwzqeGBrxQ4593HN9pYS8F8p4JD5MAekDCdvs oV5ScLR0JXvhI4gBtF2MDRoTua6LbqrSN+51G2gtVttEVR6d0JOD6kxfU/gzdGNR7kFErX yH6OCp/QAO19GQjodZHbWxy8IkH8pBY= X-MC-Unique: Mn2FwivKOlWxZ_S6FzW8aw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/5] util: json: Introduce virJSONValueObjectReplaceValue Date: Wed, 22 Dec 2021 15:24:06 +0100 Message-Id: <9745a29eb1450643543c5461543357b52c584398.1640182750.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.14 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: 1640183096520100001 Content-Type: text/plain; charset="utf-8" The new helper replaces the 'value' part of the key-value tuple in an object. The advantage of this new helper is that it preserves the ordering of the key in the object when compared to a combination of stealing the old key and adding a new value. This will be needed for a new test/helper for validating and modifying qemu capabilities data. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/libvirt_private.syms | 1 + src/util/virjson.c | 20 ++++++++++++++++++++ src/util/virjson.h | 6 ++++++ 3 files changed, 27 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 435ee8054c..431075899d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2567,6 +2567,7 @@ virJSONValueObjectHasKey; virJSONValueObjectKeysNumber; virJSONValueObjectPrependString; virJSONValueObjectRemoveKey; +virJSONValueObjectReplaceValue; virJSONValueObjectStealArray; virJSONValueObjectStealObject; virJSONValueToBuffer; diff --git a/src/util/virjson.c b/src/util/virjson.c index 1c6fef22da..6e13e97e15 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -1149,6 +1149,26 @@ virJSONValueObjectGetString(virJSONValue *object, } +void +virJSONValueObjectReplaceValue(virJSONValue *object, + const char *key, + virJSONValue **newval) +{ + size_t i; + + if (object->type !=3D VIR_JSON_TYPE_OBJECT || + !*newval) + return; + + for (i =3D 0; i < object->data.object.npairs; i++) { + if (STREQ(object->data.object.pairs[i].key, key)) { + virJSONValueFree(object->data.object.pairs[i].value); + object->data.object.pairs[i].value =3D g_steal_pointer(newval); + } + } +} + + /** * virJSONValueObjectGetStringOrNumber: * @object: JSON value object diff --git a/src/util/virjson.h b/src/util/virjson.h index f0b8c419de..aced48a538 100644 --- a/src/util/virjson.h +++ b/src/util/virjson.h @@ -248,6 +248,12 @@ virJSONValueObjectRemoveKey(virJSONValue *object, virJSONValue **value) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +void +virJSONValueObjectReplaceValue(virJSONValue *object, + const char *key, + virJSONValue **newval) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); + int virJSONValueArrayAppendString(virJSONValue *object, const char *value); --=20 2.31.1 From nobody Mon Apr 29 04:22:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1640183121; cv=none; d=zohomail.com; s=zohoarc; b=gJ4VV42SgcM+zwhtyACyyZpYpeBfSrgfexrl+Vs9etC3FD86POVX5xq4SLFrR3Te+FMnfqy0u8aN02cbCTj/2Q0NVG8QxtxWUJk9M4m8QNJGOYKLlJHreIj007JjangFNBdrVNcNzKoSIAolDj6CKNBVbhDoIp3dPnX4v6OnIgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640183121; 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=IbWLwThHV/qqXOzeicbZuvy6FvsGwsyge9UKNrqBRG4=; b=hai77L134xrx3GiaY87k3ZMTNOjl/9Q87Qje2hXM9xq54st3MffQjVSLid5JIoLNxoW6vUzMfpgKyd8q0z2KBc179yj91vbBfoEcDaQAeXeyFXAaYuHCfTItYR9/ianH7INRA0j2k3r95RyKSJov8afkjm11euNor439ypKFLlc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1640183121704518.8890415454292; Wed, 22 Dec 2021 06:25:21 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-441-T4DHxG5YM9WfhrM4R9peNw-1; Wed, 22 Dec 2021 09:25:12 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2A88381EE62; Wed, 22 Dec 2021 14:25:07 +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 093A6ADD6; Wed, 22 Dec 2021 14:25:07 +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 69A5E4A7C9; Wed, 22 Dec 2021 14:25:06 +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 1BMEOWCC029917 for ; Wed, 22 Dec 2021 09:24:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 49E6D70D28; Wed, 22 Dec 2021 14:24:32 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8307770D24 for ; Wed, 22 Dec 2021 14:24:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640183116; 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=IbWLwThHV/qqXOzeicbZuvy6FvsGwsyge9UKNrqBRG4=; b=PZbEuEHD7IjlK1iOWeza8MaWcp6WEDO9IkXHTAHjO9+L2xcRcW9J5jNt8EHYVn3yKEXMur AxIjLjthVM+MdOP2NcoW+fsGe+bskcY6xU8OoBwErpgO2vpIfVWoV9jvrPT+Qk/SZ4j/37 YcADv3Tn2Xzm6hssz6xpxuEoIWWB1/Q= X-MC-Unique: T4DHxG5YM9WfhrM4R9peNw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/5] tests: qemumonitortestutils.h: Reformat header file Date: Wed, 22 Dec 2021 15:24:07 +0100 Message-Id: <14406e0bbd2736a6d4256320c4f19f786a60700d.1640182750.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.14 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: 1640183123697100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/qemumonitortestutils.h | 140 ++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 59 deletions(-) diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h index e572627e20..89c33c434b 100644 --- a/tests/qemumonitortestutils.h +++ b/tests/qemumonitortestutils.h @@ -31,76 +31,98 @@ typedef int (*qemuMonitorTestResponseCallback)(qemuMoni= torTest *test, qemuMonitorTestItem *item, const char *message); -int qemuMonitorTestAddHandler(qemuMonitorTest *test, - const char *identifier, - qemuMonitorTestResponseCallback cb, - void *opaque, - virFreeCallback freecb); - -int qemuMonitorTestAddResponse(qemuMonitorTest *test, - const char *response); - -int qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTest *test, - const char *expectedcommand, - const char *actualcommand); - -void *qemuMonitorTestItemGetPrivateData(qemuMonitorTestItem *item); - -int qemuMonitorTestAddErrorResponse(qemuMonitorTest *test, const char *err= msg, ...); - -void qemuMonitorTestAllowUnusedCommands(qemuMonitorTest *test); -void qemuMonitorTestSkipDeprecatedValidation(qemuMonitorTest *test, - bool allowRemoved); - -int qemuMonitorTestAddItem(qemuMonitorTest *test, - const char *command_name, +int +qemuMonitorTestAddHandler(qemuMonitorTest *test, + const char *identifier, + qemuMonitorTestResponseCallback cb, + void *opaque, + virFreeCallback freecb); + +int +qemuMonitorTestAddResponse(qemuMonitorTest *test, const char *response); -int qemuMonitorTestAddItemVerbatim(qemuMonitorTest *test, - const char *command, - const char *cmderr, - const char *response); +int +qemuMonitorTestAddInvalidCommandResponse(qemuMonitorTest *test, + const char *expectedcommand, + const char *actualcommand); + +void * +qemuMonitorTestItemGetPrivateData(qemuMonitorTestItem *item); + +int +qemuMonitorTestAddErrorResponse(qemuMonitorTest *test, + const char *errmsg, + ...); + +void +qemuMonitorTestAllowUnusedCommands(qemuMonitorTest *test); +void +qemuMonitorTestSkipDeprecatedValidation(qemuMonitorTest *test, + bool allowRemoved); + +int +qemuMonitorTestAddItem(qemuMonitorTest *test, + const char *command_name, + const char *response); + +int +qemuMonitorTestAddItemVerbatim(qemuMonitorTest *test, + const char *command, + const char *cmderr, + const char *response); -int qemuMonitorTestAddAgentSyncResponse(qemuMonitorTest *test); +int +qemuMonitorTestAddAgentSyncResponse(qemuMonitorTest *test); -int qemuMonitorTestAddItemParams(qemuMonitorTest *test, - const char *cmdname, - const char *response, - ...) +int +qemuMonitorTestAddItemParams(qemuMonitorTest *test, + const char *cmdname, + const char *response, + ...) G_GNUC_NULL_TERMINATED; -int qemuMonitorTestAddItemExpect(qemuMonitorTest *test, - const char *cmdname, - const char *cmdargs, - bool apostrophe, - const char *response); +int +qemuMonitorTestAddItemExpect(qemuMonitorTest *test, + const char *cmdname, + const char *cmdargs, + bool apostrophe, + const char *response); #define qemuMonitorTestNewSimple(xmlopt) \ qemuMonitorTestNew(xmlopt, NULL, NULL, NULL, NULL) #define qemuMonitorTestNewSchema(xmlopt, schema) \ qemuMonitorTestNew(xmlopt, NULL, NULL, NULL, schema) -qemuMonitorTest *qemuMonitorTestNew(virDomainXMLOption *xmlopt, - virDomainObj *vm, - virQEMUDriver *driver, - const char *greeting, - GHashTable *schema); - -qemuMonitorTest *qemuMonitorTestNewFromFile(const char *fileName, - virDomainXMLOption *xmlopt, - bool simple); -qemuMonitorTest *qemuMonitorTestNewFromFileFull(const char *fileName, - virQEMUDriver *driver, - virDomainObj *vm, - GHashTable *qmpschema); - -qemuMonitorTest *qemuMonitorTestNewAgent(virDomainXMLOption *xmlopt); - - -void qemuMonitorTestFree(qemuMonitorTest *test); - -qemuMonitor *qemuMonitorTestGetMonitor(qemuMonitorTest *test); -qemuAgent *qemuMonitorTestGetAgent(qemuMonitorTest *test); -virDomainObj *qemuMonitorTestGetDomainObj(qemuMonitorTest *test); +qemuMonitorTest * +qemuMonitorTestNew(virDomainXMLOption *xmlopt, + virDomainObj *vm, + virQEMUDriver *driver, + const char *greeting, + GHashTable *schema); + +qemuMonitorTest * +qemuMonitorTestNewFromFile(const char *fileName, + virDomainXMLOption *xmlopt, + bool simple); +qemuMonitorTest * +qemuMonitorTestNewFromFileFull(const char *fileName, + virQEMUDriver *driver, + virDomainObj *vm, + GHashTable *qmpschema); + +qemuMonitorTest * +qemuMonitorTestNewAgent(virDomainXMLOption *xmlopt); + + +void +qemuMonitorTestFree(qemuMonitorTest *test); + +qemuMonitor * +qemuMonitorTestGetMonitor(qemuMonitorTest *test); +qemuAgent * +qemuMonitorTestGetAgent(qemuMonitorTest *test); +virDomainObj * +qemuMonitorTestGetDomainObj(qemuMonitorTest *test); G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuMonitorTest, qemuMonitorTestFree); --=20 2.31.1 From nobody Mon Apr 29 04:22:40 2024 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=1640183096; cv=none; d=zohomail.com; s=zohoarc; b=DXBmILa28PvWqbJg/CO78URAdt56zoNMC9G5dzxHuMJYPms7+5WSJXqDc+N2J8wtdxfS32iN3YcgmhZeZJrtGSPLk/4+UpvW6NKIDMbKw5qkQ4RGKLKatqO4E0zdX/mEQtmoyuejkuGZMMFQqpJ0+KWs5uB3x2m7fU+Dxxf0POs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640183096; 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=eW90cVr1ThuDvVT6uWz/9AFIpYR/TDSJHCxGO17lFf8=; b=cOpB22xBrRSiXw5w6x5FhbbXg0J146AY6G98YLZkLa5iw2lN/45xGgDAlKW9jLUPKbbQCUCZRny5esG9rWGLyeFBBsblyxgIl62H33lMHOEgZBxTUSYDb5tqPfjAVnA+A1jf1tvtY5WoMpXnsWuWZcUfw7cDT5TOiUIbBr6Mx2c= 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 1640183095998174.2082347606347; Wed, 22 Dec 2021 06:24:55 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-bC5Q_UDmPlWWFO4a_E5j1Q-1; Wed, 22 Dec 2021 09:24:53 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 85F9A1018725; Wed, 22 Dec 2021 14:24:48 +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 659781F318; Wed, 22 Dec 2021 14:24:48 +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 383B71806D1D; Wed, 22 Dec 2021 14:24:48 +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 1BMEOXbJ029922 for ; Wed, 22 Dec 2021 09:24:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 69D7470D28; Wed, 22 Dec 2021 14:24:33 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id BDE6E70D24 for ; Wed, 22 Dec 2021 14:24:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640183094; 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=eW90cVr1ThuDvVT6uWz/9AFIpYR/TDSJHCxGO17lFf8=; b=bmSG//raC87w74ZzpV9jj4efacO06K+oTJEHAa/fUpT0H3JITTVG6k05jD0DxLyzgc6VQZ k/IF53jwGBVUKuOoy8eLj7AyFZnkvg4IluxRgfMmXSlq+J5ccbt3BqyUDq7YMiXZxn+B21 6SD09T5YimNX6z+WLXPJrDqpoWUnGAI= X-MC-Unique: bC5Q_UDmPlWWFO4a_E5j1Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/5] qemumonitortestutils: Extract parser for the monitor conversation dump file Date: Wed, 22 Dec 2021 15:24:08 +0100 Message-Id: <490be1dc38bcd67af6435a1ea29ca62b3055d043.1640182750.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.23 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: 1640183096604100002 Content-Type: text/plain; charset="utf-8" Make the parser reusable by extracting it and making it parse into command,reply tuples. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/qemumonitortestutils.c | 123 ++++++++++++++++++++++++----------- tests/qemumonitortestutils.h | 13 ++++ 2 files changed, 99 insertions(+), 37 deletions(-) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 0d99b45909..f7a0a37685 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -1278,45 +1278,33 @@ qemuMonitorTestFullAddItem(qemuMonitorTest *test, /** - * qemuMonitorTestNewFromFileFull: - * @fileName: File name to load monitor replies from - * @driver: qemu driver object - * @vm: domain object (may be null if it's not needed by the test) - * @qmpschema: QMP schema data hash table if QMP checking is required + * qemuMonitorTestProcessFileEntries: + * @inputstr: input file contents (modified) + * @fileName: File name of @inputstr (for error reporting) + * @items: filled with command, reply tuples + * @nitems: Count of elements in @items. * - * Create a JSON test monitor simulator object and fill it with expected c= ommand - * sequence and replies specified in @fileName. + * Process a monitor interaction file. * * The file contains a sequence of JSON commands and reply objects separat= ed by - * empty lines. A command is followed by a reply. The QMP greeting is added - * automatically. - * - * Returns the monitor object on success; NULL on error. + * empty lines. A command is followed by a reply. */ -qemuMonitorTest * -qemuMonitorTestNewFromFileFull(const char *fileName, - virQEMUDriver *driver, - virDomainObj *vm, - GHashTable *qmpschema) +int +qemuMonitorTestProcessFileEntries(char *inputstr, + const char *fileName, + struct qemuMonitorTestCommandReplyTuple = **items, + size_t *nitems) { - g_autoptr(qemuMonitorTest) ret =3D NULL; - g_autofree char *jsonstr =3D NULL; - char *tmp; + size_t nalloc =3D 0; + char *tmp =3D inputstr; size_t line =3D 0; - - char *command =3D NULL; + char *command =3D inputstr; char *response =3D NULL; size_t commandln =3D 0; - if (virTestLoadFile(fileName, &jsonstr) < 0) - return NULL; - - if (!(ret =3D qemuMonitorTestNew(driver->xmlopt, vm, driver, NULL, - qmpschema))) - return NULL; + *items =3D NULL; + *nitems =3D 0; - tmp =3D jsonstr; - command =3D tmp; while ((tmp =3D strchr(tmp, '\n'))) { line++; @@ -1335,11 +1323,16 @@ qemuMonitorTestNewFromFileFull(const char *fileName, *(tmp + 1) =3D '\0'; if (response) { - if (qemuMonitorTestFullAddItem(ret, fileName, command, - response, commandln) < 0) - return NULL; - command =3D NULL; - response =3D NULL; + struct qemuMonitorTestCommandReplyTuple *item; + + VIR_RESIZE_N(*items, nalloc, *nitems, 1); + + item =3D *items + *nitems; + + item->command =3D g_steal_pointer(&command); + item->reply =3D g_steal_pointer(&response); + item->line =3D commandln; + (*nitems)++; } /* Move the @tmp and @singleReply. */ @@ -1354,14 +1347,70 @@ qemuMonitorTestNewFromFileFull(const char *fileName, } if (command) { + struct qemuMonitorTestCommandReplyTuple *item; + if (!response) { virReportError(VIR_ERR_INTERNAL_ERROR, "missing response for c= ommand " "on line '%zu' in '%s'", commandln, fileName); - return NULL; + return -1; } - if (qemuMonitorTestFullAddItem(ret, fileName, command, - response, commandln) < 0) + VIR_RESIZE_N(*items, nalloc, *nitems, 1); + + item =3D *items + *nitems; + + item->command =3D g_steal_pointer(&command); + item->reply =3D g_steal_pointer(&response); + item->line =3D commandln; + (*nitems)++; + } + + return 0; +} + +/** + * qemuMonitorTestNewFromFileFull: + * @fileName: File name to load monitor replies from + * @driver: qemu driver object + * @vm: domain object (may be null if it's not needed by the test) + * @qmpschema: QMP schema data hash table if QMP checking is required + * + * Create a JSON test monitor simulator object and fill it with expected c= ommand + * sequence and replies specified in @fileName. + * + * The file contains a sequence of JSON commands and reply objects separat= ed by + * empty lines. A command is followed by a reply. The QMP greeting is added + * automatically. + * + * Returns the monitor object on success; NULL on error. + */ +qemuMonitorTest * +qemuMonitorTestNewFromFileFull(const char *fileName, + virQEMUDriver *driver, + virDomainObj *vm, + GHashTable *qmpschema) +{ + g_autoptr(qemuMonitorTest) ret =3D NULL; + g_autofree char *jsonstr =3D NULL; + g_autofree struct qemuMonitorTestCommandReplyTuple *items =3D NULL; + size_t nitems =3D 0; + size_t i; + + if (virTestLoadFile(fileName, &jsonstr) < 0) + return NULL; + + if (!(ret =3D qemuMonitorTestNew(driver->xmlopt, vm, driver, NULL, + qmpschema))) + return NULL; + + if (qemuMonitorTestProcessFileEntries(jsonstr, fileName, &items, &nite= ms) < 0) + return NULL; + + for (i =3D 0; i < nitems; i++) { + struct qemuMonitorTestCommandReplyTuple *item =3D items + i; + + if (qemuMonitorTestFullAddItem(ret, fileName, item->command, item-= >reply, + item->line) < 0) return NULL; } diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h index 89c33c434b..56e3d56056 100644 --- a/tests/qemumonitortestutils.h +++ b/tests/qemumonitortestutils.h @@ -126,3 +126,16 @@ virDomainObj * qemuMonitorTestGetDomainObj(qemuMonitorTest *test); G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuMonitorTest, qemuMonitorTestFree); + +struct qemuMonitorTestCommandReplyTuple { + const char *command; + const char *reply; + size_t line; /* line number of @command */ +}; + + +int +qemuMonitorTestProcessFileEntries(char *inputstr, + const char *fileName, + struct qemuMonitorTestCommandReplyTuple = **items, + size_t *nitems); --=20 2.31.1 From nobody Mon Apr 29 04:22:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1640183118; cv=none; d=zohomail.com; s=zohoarc; b=FP8NwT5cI5RSVivQVKY1AnKbJiKQDU7YBwYSTD6dEXdOM+UTPD7AAO+0T3A4oy1Tnv35tfsMiKbXmJkVqf9Y5R1EzvgfqBAJRBZltpg6quOls5I8d2mvRXo8vM01nXjIyI8Sfzog/m6uTSe4/kdMHRCfYFc4sSbDbEBt+oKRXGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640183118; 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=o5QlIh8/WkszloBd20c+mxV5ZUtV2qv+k0s/2pKF7Lw=; b=nKN/JIptmMoW5Jp4frFy3IxNK1nIjbWx+wSv2fpdPLx7V6FktPyL+a/ASTQQfJBEA5aT1Bi0S0tMwHC7gBhFouqIH9ifapUJ0QNncDOKfboYHvUkXQ3HH+KxjomOVHTZogJpUZXxTXdKdjSFRKsiqjmAWzcisad3c0o6SqrY4jQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 164018311898353.01837542424562; Wed, 22 Dec 2021 06:25:18 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-451-jMcN4koMOhW6iND1b1VlFQ-1; Wed, 22 Dec 2021 09:25:16 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1C0CA802CBC; Wed, 22 Dec 2021 14:25:10 +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 EF40D60C2D; Wed, 22 Dec 2021 14:25:09 +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 B4DEF1806D2C; Wed, 22 Dec 2021 14:25:09 +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 1BMEOY7k029927 for ; Wed, 22 Dec 2021 09:24:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id 88D2570D28; Wed, 22 Dec 2021 14:24:34 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3A3270D24 for ; Wed, 22 Dec 2021 14:24:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640183118; 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=o5QlIh8/WkszloBd20c+mxV5ZUtV2qv+k0s/2pKF7Lw=; b=eTNzHG3KA7q8M0+Iy+4cm50LO7KF1heZSC1egyxmMQt7HfcHVOI32ohJaXCsUKj5AhK7/P reajViWCWkPs1eJmfyi4fDOXTkE7FqdBPhJ5SFU5MrAOJRMitnul4V9v5QfEajazJCJcRV GnW/+q3gFwMbnq/1QBmWlRfl6xHw1rA= X-MC-Unique: jMcN4koMOhW6iND1b1VlFQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/5] tests: Tool for programatic modification of qemucapabilitiesdata/*.replies Date: Wed, 22 Dec 2021 15:24:09 +0100 Message-Id: <9952fea7a7e8e5b07bdd1927b45cc28620d3ce7c.1640182750.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.14 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: 1640183121216100001 Content-Type: text/plain; charset="utf-8" The tool is assembled from individual bits used for tests and actual capturing of the replies files. The tool ensures correct numbering and formatting of entries. In normal usage mode it masks as a test which validates formatting and numbering of the tests/qemucapabilitiesdata/*.replies files. This tool was actually used to produce commits 096ac87a1a46 and aa21615ccbc. In case a manual modification of the replies file is needed the 'modify()' function provides a convenient way to do programatic modification of the caps file. As an example the modify() function has commented-out code which provides a basic scaffold to do modifications along with a how-to. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/meson.build | 1 + tests/qemucapabilitiesnumbering.c | 242 ++++++++++++++++++++++++++++++ 2 files changed, 243 insertions(+) create mode 100644 tests/qemucapabilitiesnumbering.c diff --git a/tests/meson.build b/tests/meson.build index f75c248720..4792220b48 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -452,6 +452,7 @@ if conf.has('WITH_QEMU') { 'name': 'qemuagenttest', 'link_with': [ test_qemu_driver_lib, test_u= tils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] }, { 'name': 'qemublocktest', 'include': [ storage_file_inc_dir ], 'link_= with': [ test_qemu_driver_lib, test_utils_qemu_monitor_lib ], 'link_whole':= [ test_utils_qemu_lib ] }, { 'name': 'qemucapabilitiestest', 'link_with': [ test_qemu_driver_lib,= test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] }, + { 'name': 'qemucapabilitiesnumbering', 'link_with': [ test_qemu_driver= _lib, test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] = }, { 'name': 'qemucaps2xmltest', 'link_with': [ test_qemu_driver_lib ], '= link_whole': [ test_utils_qemu_lib ] }, { 'name': 'qemucommandutiltest', 'link_with': [ test_qemu_driver_lib, = test_utils_qemu_monitor_lib ], 'link_whole': [ test_utils_qemu_lib ] }, { 'name': 'qemudomaincheckpointxml2xmltest', 'link_with': [ test_qemu_= driver_lib ], 'link_whole': [ test_utils_qemu_lib ] }, diff --git a/tests/qemucapabilitiesnumbering.c b/tests/qemucapabilitiesnumb= ering.c new file mode 100644 index 0000000000..eff7dbe2a1 --- /dev/null +++ b/tests/qemucapabilitiesnumbering.c @@ -0,0 +1,242 @@ +/* + * qemucapabilitiesnumbering.c: swiss-army knife for qemu capability data = manipulation + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ +#include + +#include "testutils.h" +#include "testutilsqemu.h" +#include "qemumonitortestutils.h" + +struct qmpTuple { + virJSONValue *command; + virJSONValue *reply; +}; + +struct qmpCommandList { + struct qmpTuple *items; + size_t nitems; +}; + +typedef struct qmpCommandList qmpCommandList; + + +static int +modify(struct qmpCommandList *list G_GNUC_UNUSED) +{ + /* in case you want to programmatically modify the replies file enable= the + * following block and modify it to your needs. After compiling run th= is + * with: + * + * VIR_TEST_REGENERATE_OUTPUT=3D1 tests/qemucapabilitiesnumbering + * + * This applies the modification along with updating the files. Use gi= t to + * your advantage to roll back mistakes. + */ +#if 0 + struct qmpTuple tmptuple =3D { NULL, NULL }; + size_t found =3D 0; + size_t i; + + for (i =3D 0; i < list->nitems; i++) { + struct qmpTuple *item =3D list->items + i; + const char *cmdname =3D virJSONValueObjectGetString(item->command,= "execute"); + + if (STREQ_NULLABLE(cmdname, "qom-list-properties")) { + found =3D i; + // break; /* uncomment if you want to find the first occurence= */ + } + } + + if (found =3D=3D 0) { + fprintf(stderr, "entry not found!!!\n"); + return -1; + } + + tmptuple.command =3D virJSONValueFromString("{\"execute\":\"dummy\"}"); + tmptuple.reply =3D virJSONValueFromString("{\"return\":{}}"); + // tmptuple.reply =3D virTestLoadFileJSON("path/", "to/", "file.json"); + + ignore_value(VIR_INSERT_ELEMENT(list->items, found + 1, list->nitems, = tmptuple)); +#endif + + return 0; +} + + +static void +qmpCommandListFree(qmpCommandList* list) +{ + size_t i; + + if (!list) + return; + + for (i =3D 0; i < list->nitems; i++) { + struct qmpTuple *item =3D list->items + i; + + virJSONValueFree(item->command); + virJSONValueFree(item->reply); + } + + g_free(list->items); + g_free(list); +} + + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(qmpCommandList, qmpCommandListFree); + + +static qmpCommandList * +loadReplies(const char *filename) +{ + g_autofree char *replies =3D NULL; + g_autofree struct qemuMonitorTestCommandReplyTuple *items =3D NULL; + size_t nitems =3D 0; + g_autoptr(qmpCommandList) list =3D NULL; + size_t i; + + if (virTestLoadFile(filename, &replies) < 0) { + fprintf(stderr, "Failed to load '%s'\n", filename); + return NULL; + } + + if (qemuMonitorTestProcessFileEntries(replies, filename, &items, &nite= ms) < 0) + return NULL; + + list =3D g_new0(qmpCommandList, 1); + list->items =3D g_new0(struct qmpTuple, nitems); + + for (i =3D 0; i < nitems; i++) { + struct qemuMonitorTestCommandReplyTuple *item =3D items + i; + + if (!(list->items[list->nitems].command =3D virJSONValueFromString= (item->command)) || + !(list->items[list->nitems++].reply =3D virJSONValueFromString= (item->reply))) + return NULL; + } + + return g_steal_pointer(&list); +} + +/* see printLineSkipEmpty in tests/qemucapsprobemock.c */ +static void +printLineSkipEmpty(const char *p, + virBuffer *buf) +{ + for (; *p; p++) { + if (p[0] =3D=3D '\n' && p[1] =3D=3D '\n') + continue; + + virBufferAddChar(buf, *p); + } +} + + +static void +renumberItem(virJSONValue *val, + size_t num) +{ + g_autoptr(virJSONValue) label =3D virJSONValueNewString(g_strdup_print= f("libvirt-%zu", num)); + + virJSONValueObjectReplaceValue(val, "id", &label); +} + + +static int +output(virBuffer *buf, + qmpCommandList *list) +{ + size_t commandindex =3D 1; + size_t i; + + for (i =3D 0; i < list->nitems; i++) { + struct qmpTuple *item =3D list->items + i; + g_autofree char *jsoncommand =3D NULL; + g_autofree char *jsonreply =3D NULL; + + if (STREQ_NULLABLE(virJSONValueObjectGetString(item->command, "exe= cute"), "qmp_capabilities")) + commandindex =3D 1; + + /* fix numbering */ + renumberItem(item->command, commandindex); + renumberItem(item->reply, commandindex); + commandindex++; + + /* output formatting */ + if (!(jsoncommand =3D virJSONValueToString(item->command, true)) || + !(jsonreply =3D virJSONValueToString(item->reply, true))) + return -1; + + printLineSkipEmpty(jsoncommand, buf); + virBufferAddLit(buf, "\n"); + printLineSkipEmpty(jsonreply, buf); + virBufferAddLit(buf, "\n"); + } + + virBufferTrim(buf, "\n"); + + return 0; +} + + +static int +testCapsFile(const void *opaque) +{ + const char *repliesFile =3D opaque; + g_autoptr(qmpCommandList) list =3D NULL; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + if (!(list =3D loadReplies(repliesFile))) + return -1; + + if (virTestGetRegenerate() > 0) { + if (modify(list) < 0) + return -1; + } + + output(&buf, list); + + if (virTestCompareToFile(virBufferCurrentContent(&buf), repliesFile) <= 0) + return -1; + + return 0; +} + + +static int +iterateCapsFile(const char *inputDir, + const char *prefix, + const char *version, + const char *archName, + const char *suffix, + void *opaque G_GNUC_UNUSED) +{ + g_autofree char *repliesFile =3D g_strdup_printf("%s/%s_%s.%s.%s", inp= utDir, prefix, version, archName, suffix); + + return virTestRun(repliesFile, testCapsFile, repliesFile); +} + + +static int +testmain(void) +{ + if (testQemuCapsIterate(".replies", iterateCapsFile, NULL) < 0) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +VIR_TEST_MAIN(testmain) --=20 2.31.1 From nobody Mon Apr 29 04:22:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1640183099; cv=none; d=zohomail.com; s=zohoarc; b=lJLfBaeAOUp+yojNJieKT0/tGVZoyR06Lz8vPHBn9+NQyoQ57ApHbrr5BC0SZFLV5RuXZQiEsXGJfX9hZMl7U+3AI8isj3nVRw05PSZRPIAYFbV5pCeZSMPK/Dnt/a+/qZ/83UoEU+Ie+RQW3uYmboMwFoV7CafbBoRBl5Oh9QQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1640183099; 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=bYjPg88k4FHHiqPyMxJwDwJ5IKOnrF2d/lAfb4yX/VA=; b=do3Q/r4j18+e2Y0gSTrT3319BtRDDXbYWydXgZ9yY2OB0Z+A950Q14Bup/yTPMtjfhWBs2XGR8CBNQbUlLWKklmF8w+HsWPnE6SHsboS6ehnNOVtCcDFBjXv3WC0tSEFtHEPrjQgq6cwfzhO4DtdWp7U8uccP/YOjKzNdbbpe+c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1640183099532371.37949737577253; Wed, 22 Dec 2021 06:24:59 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-383-1aG7SZyuP12kdzi8kOwYSg-1; Wed, 22 Dec 2021 09:24:57 -0500 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 29961802C92; Wed, 22 Dec 2021 14:24:51 +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 082467A2E1; Wed, 22 Dec 2021 14:24:51 +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 CFF244CA93; Wed, 22 Dec 2021 14:24:50 +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 1BMEOZHY029933 for ; Wed, 22 Dec 2021 09:24:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id AD18870D24; Wed, 22 Dec 2021 14:24:35 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0973F70D28 for ; Wed, 22 Dec 2021 14:24:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1640183098; 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=bYjPg88k4FHHiqPyMxJwDwJ5IKOnrF2d/lAfb4yX/VA=; b=Uxve6IniOUmWpqVWtK/hI6dnhhcTTZTStZeC9SbBnY/qwb9vYNM6b7CLD8fEX8UgMOYL/j rutx5faSwZ790HUYaLGPgar6mNuqecRw5bbgSlRR1EhwVyBF3BcsZJXpYYYywpVyUT5Avz XEjWOwEyp3edHOcXe8FxCr0cfwIO22A= X-MC-Unique: 1aG7SZyuP12kdzi8kOwYSg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 5/5] tests: Remove 'qemucapsfixreplies' Date: Wed, 22 Dec 2021 15:24:10 +0100 Message-Id: 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 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: 1640183101118100001 Content-Type: text/plain; charset="utf-8" The 'qemucapabilitiesnumbering' tool now replaces the role of this script and provides way to programmatically modify the replies file on top. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/domaincapstest.c | 3 ++- tests/qemucapabilitiestest.c | 4 +++- tests/qemucapsfixreplies | 26 -------------------------- 3 files changed, 5 insertions(+), 28 deletions(-) delete mode 100755 tests/qemucapsfixreplies diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c index 479bcb1c35..da5c629fd4 100644 --- a/tests/domaincapstest.c +++ b/tests/domaincapstest.c @@ -422,7 +422,8 @@ mymain(void) * to generate updated or new *.replies data files. * * If you manually edit replies files you can run - * "tests/qemucapsfixreplies foo.replies" to fix the replies ids. + * VIR_TEST_REGENERATE_OUTPUT=3D1 tests/qemucapabilitiesnumbering + * to fix the replies ids. * * Once a replies file has been generated and tweaked if necessary, * you can drop it into tests/qemucapabilitiesdata/ (with a sensible diff --git a/tests/qemucapabilitiestest.c b/tests/qemucapabilitiestest.c index 99534ab9a1..ae208f442c 100644 --- a/tests/qemucapabilitiestest.c +++ b/tests/qemucapabilitiestest.c @@ -212,7 +212,9 @@ mymain(void) * to generate updated or new *.replies data files. * * If you manually edit replies files you can run - * "tests/qemucapsfixreplies foo.replies" to fix the replies ids. + * VIR_TEST_REGENERATE_OUTPUT=3D1 tests/qemucapabilitiesnumbering + * to fix the replies ids. The tool also allows for programatic modifi= cation + * of the replies file. * * Once a replies file has been generated and tweaked if necessary, * you can drop it into tests/qemucapabilitiesdata/ (with a sensible diff --git a/tests/qemucapsfixreplies b/tests/qemucapsfixreplies deleted file mode 100755 index 597f9ecd6e..0000000000 --- a/tests/qemucapsfixreplies +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh - -if [ "$#" -ne 1 ] || [ "$1" =3D "--help" ] || [ ! -f "$1" ]; then - echo "This script fixes replies ids in QEMU replies files." - echo "" - echo " Usage: $0 path/to/qemu.replies" - exit 0 -fi - -awk -i inplace \ - 'BEGIN {last=3D0; pattern=3D"libvirt-[0-9]+"} - { - if (match($0, "libvirt-1[^0-9]")) { - count=3D1; - } - if (match($0, pattern)) { - str=3D"libvirt-" count; - sub(pattern, str, $0); - if (last !=3D count) { - last=3Dcount; - } else { - count++; - } - } - print - }' "$1" --=20 2.31.1