From nobody Mon Feb 9 00:55:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; 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.120 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=1587655368; cv=none; d=zohomail.com; s=zohoarc; b=dJzGvgHJfdPB1cdGfXdfzo+nhHyZkhcilzcvW1fapjmc3vLJITvwY1ijPMietPmhLBNcicE67hmV/59+eeQEL7ISgqroJWzSBMdQvyx2ubY3pmiFJaLWLYOWjLqxRDuPn8ktMO9hzrv/y9BJqKBJT035nJM/tlHJXUNJjngvXok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587655368; 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=wKOWJpY6iJOl/+g3eCRS5pDCP7QeTdNrW55oQl5D+TA=; b=BkbChEAQn0eQL842OOSvIsQW+cK9KYCHnltjnBFGvnq2+QiydevJc0KUD+kzLABmXI/UUxjfniurB0VE4setAi/+OTjXSEtIKa/iFUF1mwq/4BOgVUV9MTeesPHJJ80QXCEaRNqAOyQNXMAkUcKbvyAICEEeC4aNd5PwyYZwqNg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1587655368460238.76879111986648; Thu, 23 Apr 2020 08:22:48 -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-288-EE8VeByIO9uIz5E-5U_bgQ-1; Thu, 23 Apr 2020 11:22:43 -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 F39C8108BD0E; Thu, 23 Apr 2020 15:22:36 +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 C88465D9D7; Thu, 23 Apr 2020 15:22:36 +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 7BCF94E585; Thu, 23 Apr 2020 15:22:36 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 03NFMH5I010468 for ; Thu, 23 Apr 2020 11:22:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8740C60E1C; Thu, 23 Apr 2020 15:22:17 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.40.208.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id E9EC260C81 for ; Thu, 23 Apr 2020 15:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587655367; 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=wKOWJpY6iJOl/+g3eCRS5pDCP7QeTdNrW55oQl5D+TA=; b=DpkRfTMJYDYlxVxmuNHHViAm4uHUfuH/gwIZJ2ng84PfZ5VjLYROJlbw6iU9bsWLwMUSTJ QXkmA0asBtIQ6D5AYotuT4+2PeGf+KKLtfVyG7ZVCKtLyBJAPFNYNws6A8PdJHRoO0RFRn QmMzfhvRAQFpjL/zDb8jOHl3op9+Ot8= X-MC-Unique: EE8VeByIO9uIz5E-5U_bgQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 8/8] qemumonitortestutils: Enforce consumption of all items in test monitor Date: Thu, 23 Apr 2020 17:22:05 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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 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" To prevent unexpected situations where a change in code would stop looking at some of the tested commands go unnoticed add a mechanism to force consumption of all test items. Since there are a few tests which would be hard to fix add also a mechanism to opt-out of the check. Signed-off-by: Peter Krempa --- tests/cputest.c | 2 ++ tests/qemuhotplugtest.c | 2 ++ tests/qemumonitorjsontest.c | 2 ++ tests/qemumonitortestutils.c | 31 ++++++++++++++++++++++++++++++- tests/qemumonitortestutils.h | 2 ++ 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/cputest.c b/tests/cputest.c index 869d016ffc..21f47a6853 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -482,6 +482,8 @@ cpuTestMakeQEMUCaps(const struct data *data) if (!(testMon =3D qemuMonitorTestNewFromFile(json, driver.xmlopt, true= ))) goto error; + qemuMonitorTestAllowUnusedCommands(testMon); + cpu =3D virCPUDefNew(); cpu->model =3D g_strdup("host"); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 65867a0122..9a215ab303 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -453,6 +453,8 @@ testQemuHotplugCpuPrepare(const char *test, &driver, data->vm, qm= pschema))) goto error; + qemuMonitorTestAllowUnusedCommands(data->mon); + priv->mon =3D qemuMonitorTestGetMonitor(data->mon); virObjectUnlock(priv->mon); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 615bc8c102..60c816d1d1 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -796,6 +796,8 @@ qemuMonitorJSONTestAttachOneChardev(virDomainXMLOptionP= tr xmlopt, if (!(data.test =3D qemuMonitorTestNewSchema(xmlopt, schema))) goto cleanup; + qemuMonitorTestAllowUnusedCommands(data.test); + if (qemuMonitorTestAddItemExpect(data.test, "chardev-add", expectargs, true, jsonreply) < 0) goto cleanup; diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index 1af56c6d87..0b6188b4ca 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -57,6 +57,8 @@ struct _qemuMonitorTest { bool running; bool started; + bool allowUnusedCommands; + char *incoming; size_t incomingLength; size_t incomingCapacity; @@ -423,8 +425,15 @@ qemuMonitorTestFree(qemuMonitorTestPtr test) VIR_FREE(test->incoming); VIR_FREE(test->outgoing); - for (i =3D 0; i < test->nitems; i++) + for (i =3D 0; i < test->nitems; i++) { + if (!test->allowUnusedCommands) { + g_fprintf(stderr, + "\nunused test monitor item '%s'\n", + NULLSTR(test->items[i]->identifier)); + } + qemuMonitorTestItemFree(test->items[i]); + } VIR_FREE(test->items); if (test->tmpdir && rmdir(test->tmpdir) < 0) @@ -432,6 +441,11 @@ qemuMonitorTestFree(qemuMonitorTestPtr test) VIR_FREE(test->tmpdir); + if (!test->allowUnusedCommands && + test->nitems !=3D 0) { + qemuMonitorTestError("unused test monitor items are not allowed fo= r this test\n"); + } + virMutexDestroy(&test->lock); VIR_FREE(test); } @@ -1290,6 +1304,21 @@ qemuMonitorTestNewFromFile(const char *fileName, } +/** + * qemuMonitorTestAllowUnusedCommands: + * @test: test monitor object + * + * By default all test items/commands must be used by the test. This funct= ion + * allows to override the requirement for individual tests e.g. if it's ne= cessary + * to test some negative scenarios which would not use all commands. + */ +void +qemuMonitorTestAllowUnusedCommands(qemuMonitorTestPtr test) +{ + test->allowUnusedCommands =3D true; +} + + static int qemuMonitorTestFullAddItem(qemuMonitorTestPtr test, const char *filename, diff --git a/tests/qemumonitortestutils.h b/tests/qemumonitortestutils.h index 384002d086..f45e850000 100644 --- a/tests/qemumonitortestutils.h +++ b/tests/qemumonitortestutils.h @@ -50,6 +50,8 @@ void *qemuMonitorTestItemGetPrivateData(qemuMonitorTestIt= emPtr item); int qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test, const char *e= rrmsg, ...); +void qemuMonitorTestAllowUnusedCommands(qemuMonitorTestPtr test); + int qemuMonitorTestAddItem(qemuMonitorTestPtr test, const char *command_name, const char *response); --=20 2.26.0