From nobody Sun Feb 8 18:44:55 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1588186193; cv=none; d=zohomail.com; s=zohoarc; b=Wi7/T2lWp2M/LRqVMYa2edDx2lwBikxA0seB7ChQsRvobDup+xEjEiOTWHBNvqsbg+A4P7iKMPfc6LBhqKYha1MnOq+hFNSfG+VCt34k5kX3fxyFoWle5tBu+ZlyVKIjJwvkOKqNldbWNW/3rPJ6169gy/BSIUarLchC4sJsffc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1588186193; 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=Dxk/8KXgBFnOhk+PgC+VGguit7f50w6T4EQcZdTHCqk=; b=jh34hVCRz/LAbSItHDK+aD5FTl+3XwX3lFInDVG+phZrNVP0uB7EKKDP/wONTn/XIb5wlpy4r7M5Or1yj4sDypM51/foMqpYukGDrXzEmY6iWkk8ovB8dvyLSYxfkPo9p80SvN1h7qZQXSGhtBXOCwT/eMbv2AFxstU/TKY2A2Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1588186193510737.0712642932856; Wed, 29 Apr 2020 11:49:53 -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-10-y6nHK_BzMDiIz5hnMmszkA-1; Wed, 29 Apr 2020 14:49:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 95E308018AC; Wed, 29 Apr 2020 18:49:44 +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 6F54C600E5; Wed, 29 Apr 2020 18:49:44 +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 211831809561; Wed, 29 Apr 2020 18:49:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03TInOp7001506 for ; Wed, 29 Apr 2020 14:49:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id 636F25C1BE; Wed, 29 Apr 2020 18:49:24 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC8855C241 for ; Wed, 29 Apr 2020 18:49:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1588186192; 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=Dxk/8KXgBFnOhk+PgC+VGguit7f50w6T4EQcZdTHCqk=; b=hJLNjvVlcqnivE0Z7gJUSj1iZe/ZBQrVxQODfaUAI8TsfcLUcpmZe377Lo6Fw435wQtGY5 GniEoMM5cMndt+TH5KUpzzAovZsibAxcPiiXE4ymPJJimQUXp8xEWd4hcR4I8svdfC+czc ekTAIYn4tU4eQgQnyHPnqJhjG3IO1U8= X-MC-Unique: y6nHK_BzMDiIz5hnMmszkA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/15] testutilsqemuschema: Introduce testQEMUSchemaValidateCommand Date: Wed, 29 Apr 2020 20:49:02 +0200 Message-Id: <824326dfd4bef77ef16a4eee50f9a699017a7fe2.1588185999.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 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.11 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" The new helper splits out all steps necessary to validate a QMP command against the schema. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/testutilsqemuschema.c | 44 +++++++++++++++++++++++++++++++++++++ tests/testutilsqemuschema.h | 6 +++++ 2 files changed, 50 insertions(+) diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 7b82ff27b2..60409a0f91 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -517,6 +517,50 @@ testQEMUSchemaValidate(virJSONValuePtr obj, } +/** + * testQEMUSchemaValidateCommand: + * @command: command to validate + * @arguments: arguments of @command to validate + * @schema: hash table containing schema entries + * @debug: a virBuffer which will be filled with debug information if prov= ided + * + * Validates whether @command and it's @arguments conforms to the QAPI sch= ema + * passed in via @schema. Returns 0, if the command and args matches @sche= ma, + * -1 if it does not and -2 if there is a problem with the schema or with + * internals. + * + * @debug is filled with information regarding the validation process + */ +int +testQEMUSchemaValidateCommand(const char *command, + virJSONValuePtr arguments, + virHashTablePtr schema, + virBufferPtr debug) +{ + g_autofree char *schemapatharguments =3D g_strdup_printf("%s/arg-type"= , command); + g_autoptr(virJSONValue) emptyargs =3D NULL; + virJSONValuePtr schemarootcommand; + virJSONValuePtr schemarootarguments; + + if (virQEMUQAPISchemaPathGet(command, schema, &schemarootcommand) < 0 = || + !schemarootcommand) { + virBufferAsprintf(debug, "ERROR: command '%s' not found in the sch= ema", command); + return -1; + } + + if (!arguments) + arguments =3D emptyargs =3D virJSONValueNewObject(); + + if (virQEMUQAPISchemaPathGet(schemapatharguments, schema, &schemaroota= rguments) < 0 || + !schemarootarguments) { + virBufferAsprintf(debug, "ERROR: failed to look up 'arg-type' of = '%s'", command); + return -1; + } + + return testQEMUSchemaValidateRecurse(arguments, schemarootarguments, s= chema, debug); +} + + /** * testQEMUSchemaGetLatest: * diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h index 84ee9a9670..e3a375b038 100644 --- a/tests/testutilsqemuschema.h +++ b/tests/testutilsqemuschema.h @@ -28,6 +28,12 @@ testQEMUSchemaValidate(virJSONValuePtr obj, virHashTablePtr schema, virBufferPtr debug); +int +testQEMUSchemaValidateCommand(const char *command, + virJSONValuePtr arguments, + virHashTablePtr schema, + virBufferPtr debug); + virJSONValuePtr testQEMUSchemaGetLatest(const char* arch); --=20 2.26.2