From nobody Thu May 2 01:33:52 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1596736302; cv=none; d=zohomail.com; s=zohoarc; b=B72qrzkjCIGHgXzvjFLx2NJ8AzzVjOJHdUoqgE3VfU53ZKl7eui+W6u+v96EW9MsRxSp8Pk4dUG63voHkYJ1G+Sn14hlrHlupaMfXf7vRzfZfzlNK9kxmQYRs9eo5qBD1mCHdLsYrY7YKuF9Fw47vY1br/w2Edhtb3puKcs4tEo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596736302; 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=KiYD39nwjltM5q2thARVHWU6Iecwh6mIr7lJP27B8H4=; b=M3TXExq3j8ijMeVKz/o4DrFXrHi0d+iXMu7ljqFFuIIvbrZZDviRnK9NRDhBXY2ivy+uXfWlbwb1Q715/dEBdB68XmN28tVIdFPLbU9lYHJzs7KnO7sgz0QSi+05vS0gGFcrUslHPbeAVFZ+lNi9FLmki75zs/oD+ekkviT3F3M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1596736302102732.5975829641791; Thu, 6 Aug 2020 10:51:42 -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-369-yzWMKgpXMOGICAP4KQ6iDQ-1; Thu, 06 Aug 2020 13:51:38 -0400 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 D27271800D42; Thu, 6 Aug 2020 17:51:32 +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 B33165DA7A; Thu, 6 Aug 2020 17:51:32 +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 7DD439A109; Thu, 6 Aug 2020 17:51:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 076Hovqj000926 for ; Thu, 6 Aug 2020 13:50:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id D1EE31002397; Thu, 6 Aug 2020 17:50:57 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38F291002393 for ; Thu, 6 Aug 2020 17:50:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596736300; 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=KiYD39nwjltM5q2thARVHWU6Iecwh6mIr7lJP27B8H4=; b=eicFI/04aVtX5HXLV3Flk9wtzJ6GxXs4oRKv1iw5+TYZbxf4CnQA45Id3DVjASNu/VTjbV HtjZ7QMyJJSwAJGefoEoHL3gBbtRIcNoAt0kLDpnZ7FlD1b1G5Lwak1UiAmVaXxr93odb0 PaMX7lzCExwttRGHrQnk+9HNihxzIOg= X-MC-Unique: yzWMKgpXMOGICAP4KQ6iDQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/2] testutilsqemuschema: Add template checker for schema entries Date: Thu, 6 Aug 2020 19:50:50 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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) Content-Type: text/plain; charset="utf-8" We'll need to match that a certain part of the qemu schema hasn't grown new properties unexpectedly. Add a helper which matches an 'object' QMP schema entry against a template and reports errors if expected types don't match or new entries are added. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tests/testutilsqemuschema.c | 115 ++++++++++++++++++++++++++++++++++++ tests/testutilsqemuschema.h | 5 ++ 2 files changed, 120 insertions(+) diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index d9bc00903d..21a58cb4c6 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -607,6 +607,121 @@ testQEMUSchemaValidateCommand(const char *command, } +/** + * testQEMUSchemaEntryMatchTemplate: + * + * @schemaentry: a JSON object representing a 'object' node in the QAPI sc= hema + * ...: a NULL terminated list of strings representing the template of pro= perties + * which the QMP object needs to have. + * + * The strings have following format: + * + * "type:name" + * "?type:name" + * + * "type" corresponds to the 'type' property of the member to check (= str, bool, any ...) + * "name" corresponds to the name of the member to check + * + * If the query string starts with an '?' and member 'name' may be mi= ssing. + * + * This function matches that @schemaentry has all expected members and the + * members have expected types. @schemaentry also must not have any unknown + * members. + */ +int +testQEMUSchemaEntryMatchTemplate(virJSONValuePtr schemaentry, + ...) +{ + g_autoptr(virJSONValue) members =3D NULL; + va_list ap; + const char *next; + int ret =3D -1; + + if (STRNEQ_NULLABLE(virJSONValueObjectGetString(schemaentry, "meta-typ= e"), "object")) { + VIR_TEST_VERBOSE("schemaentry is not an object"); + return -1; + } + + if (!(members =3D virJSONValueCopy(virJSONValueObjectGetArray(schemaen= try, "members")))) { + VIR_TEST_VERBOSE("failed to copy 'members'"); + return -1; + } + + va_start(ap, schemaentry); + + /* pass 1 */ + + while ((next =3D va_arg(ap, const char *))) { + char modifier =3D *next; + g_autofree char *type =3D NULL; + char *name; + size_t i; + bool found =3D false; + bool optional =3D false; + + if (!g_ascii_isalpha(modifier)) + next++; + + if (modifier =3D=3D '?') + optional =3D true; + + type =3D g_strdup(next); + + if ((name =3D strchr(type, ':'))) { + *(name++) =3D '\0'; + } else { + VIR_TEST_VERBOSE("malformed template string '%s'", next); + goto cleanup; + } + + for (i =3D 0; i < virJSONValueArraySize(members); i++) { + virJSONValuePtr member =3D virJSONValueArrayGet(members, i); + const char *membername =3D virJSONValueObjectGetString(member,= "name"); + const char *membertype =3D virJSONValueObjectGetString(member,= "type"); + + if (STRNEQ_NULLABLE(name, membername)) + continue; + + if (STRNEQ_NULLABLE(membertype, type)) { + VIR_TEST_VERBOSE("member '%s' is of unexpected type '%s' (= expected '%s')", + NULLSTR(membername), NULLSTR(membertype),= type); + goto cleanup; + } + + found =3D true; + break; + } + + if (found) { + virJSONValueFree(virJSONValueArraySteal(members, i)); + } else { + if (!optional) { + VIR_TEST_VERBOSE("mandatory member '%s' not found", name); + goto cleanup; + } + } + } + + /* pass 2 - check any unexpected members */ + if (virJSONValueArraySize(members) > 0) { + size_t i; + + for (i =3D 0; i < virJSONValueArraySize(members); i++) { + VIR_TEST_VERBOSE("unexpected member '%s'", + NULLSTR(virJSONValueObjectGetString(virJSONVa= lueArrayGet(members, i), "name"))); + } + + goto cleanup; + } + + ret =3D 0; + + cleanup: + va_end(ap); + return ret; +} + + static virJSONValuePtr testQEMUSchemaLoadReplies(const char *filename) { diff --git a/tests/testutilsqemuschema.h b/tests/testutilsqemuschema.h index c90a6b626d..1649ad78b5 100644 --- a/tests/testutilsqemuschema.h +++ b/tests/testutilsqemuschema.h @@ -37,6 +37,11 @@ testQEMUSchemaValidateCommand(const char *command, bool allowRemoved, virBufferPtr debug); +int +testQEMUSchemaEntryMatchTemplate(virJSONValuePtr schemaentry, + ...); + + virJSONValuePtr testQEMUSchemaGetLatest(const char* arch); --=20 2.26.2 From nobody Thu May 2 01:33:52 2024 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-delivery-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=1596736294; cv=none; d=zohomail.com; s=zohoarc; b=dh/e1mNn5CvwpsszROTEshDExkA3Vi+bd0t2tEpiY1ECHw6KNxFviQPsAIqK/hKg4PApCuEjGjiOJkUDIysnbDn2mZbcaI5qSZcnipaR1DN9cOVAUw9AECS5qz5OPEKWf9dnCzkiQ1NyiORvyuQRbVFmyaI2RMjLYI+S1sCJYUs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596736294; 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=X7Wo/y0d8e8cM6gl12hDc6N27CipK2oKo2uLC3NecQg=; b=UQ/wKzk+2N/+7lqWd8XRB6XfJuiiNLFEwVIyRS1Qy/OhReye3zbb8FGOSPqe/7xl/HFqUi7PJATbAtp/E+hEAsStwdNxpft3P3WLbfr9sGBJtGPGptI+edafMPwlRxrGL6G86hnPFSyHaEQ2pgUTc+0+t0a5FiI+aqb7LN//STM= 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-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1596736294689441.5884787344921; Thu, 6 Aug 2020 10:51:34 -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-130-lrP2SD3XNyaSfnXdYuoICg-1; Thu, 06 Aug 2020 13:51:30 -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 0F72791272; Thu, 6 Aug 2020 17:51:25 +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 B3E9F1002393; Thu, 6 Aug 2020 17:51:24 +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 4F5BA1809561; Thu, 6 Aug 2020 17:51:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 076Hoxvr000937 for ; Thu, 6 Aug 2020 13:50:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 09C3F1002397; Thu, 6 Aug 2020 17:50:59 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id 412151002393 for ; Thu, 6 Aug 2020 17:50:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1596736293; 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=X7Wo/y0d8e8cM6gl12hDc6N27CipK2oKo2uLC3NecQg=; b=EDJPsEfQmyF2QMSAbaPXMkdaL8xPixxMskDXdLwO8ZSkFxufNVJY1AQtGi7BOqmTF9ziYd n/z90JI8ASO4KlYjr6mugU2bItMtUMNJ7PdYmxamv97HSrlao1mTyoQHDv6ymK4/+5meFy SaMzCU3gYUGbKTkGdb+hT/El33jgwUI= X-MC-Unique: lrP2SD3XNyaSfnXdYuoICg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/2] qemumonitorjsontest: Add a last-resort warning if object-add/device_add are QAPIfied Date: Thu, 6 Aug 2020 19:50:51 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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) Content-Type: text/plain; charset="utf-8" When netdev-add was qapified it took us by surprise and we had to scramble to fix the internals to format conformant monitor arguments. Add a last-resort early warning system if this happens to object-add or device_add. Hopefully qemu developers notify us sooner than this. Signed-off-by: Peter Krempa Reviewed-by: Daniel Henrique Barboza --- tests/qemumonitorjsontest.c | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 77e70c1dc4..bc25958e70 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2888,6 +2888,55 @@ testQAPISchemaValidate(const void *opaque) } +/** + * testQAPISchemaObjectDeviceAdd: + * + * Purpose of this test is to add a last-resort notification that 'object-= add' + * and 'device_add' are not covered by the QMP schema by surprise. Ideally= QEMU + * developers will notify us before they switch so we have time to adapt o= ur + * generators first. This didn't work out when netdev-add was converted. + * + * We validate that the QMP schema describes only the expected types and n= othing + * else assuming that no new field will be added until final conversion. + */ +static int +testQAPISchemaObjectDeviceAdd(const void *opaque) +{ + virHashTablePtr schema =3D (virHashTablePtr) opaque; + virJSONValuePtr entry; + + if (virQEMUQAPISchemaPathGet("device_add/arg-type", schema, &entry) < = 0) { + fprintf(stderr, "schema for 'device_add' not found\n"); + return -1; + } + + if (testQEMUSchemaEntryMatchTemplate(entry, + "str:driver", + "str:bus", + "str:id", + NULL) < 0) { + VIR_TEST_VERBOSE("device_add has unexpected members in schema"); + return -1; + } + + if (virQEMUQAPISchemaPathGet("object-add/arg-type", schema, &entry) < = 0) { + fprintf(stderr, "schema for 'objectadd' not found\n"); + return -1; + } + + if (testQEMUSchemaEntryMatchTemplate(entry, + "str:qom-type", + "str:id", + "any:props", + NULL) < 0) { + VIR_TEST_VERBOSE("object-add has unexpected members in schema"); + return -1; + } + + return 0; +} + + static void testQueryJobsPrintJob(virBufferPtr buf, qemuMonitorJobInfoPtr job) @@ -3380,6 +3429,10 @@ mymain(void) #undef DO_TEST_QAPI_VALIDATE + if (virTestRun("validate that object-add and device_add don't have sch= ema", + testQAPISchemaObjectDeviceAdd, qapiData.schema) < 0) + ret =3D -1; + #define DO_TEST_QUERY_JOBS(name) \ do { \ struct testQueryJobsData data =3D { name, driver.xmlopt}; \ --=20 2.26.2