From nobody Mon Feb 9 08:56:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629463597982786.728393635952; Fri, 20 Aug 2021 05:46:37 -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-535-xtUDWFIeOqC1hQ4b0M26gg-1; Fri, 20 Aug 2021 08:46:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9FE888799E0; Fri, 20 Aug 2021 12:46:29 +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 82A691B400; Fri, 20 Aug 2021 12:46:29 +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 268D74A7CB; Fri, 20 Aug 2021 12:46:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17KCjN6t013731 for ; Fri, 20 Aug 2021 08:45:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7A30D105019C; Fri, 20 Aug 2021 12:45:23 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast02.extmail.prod.ext.rdu2.redhat.com [10.11.55.18]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76188105019B for ; Fri, 20 Aug 2021 12:45:20 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A73A780018D for ; Fri, 20 Aug 2021 12:45:20 +0000 (UTC) Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-555-1pbDfuFLMSOae-YLCQC-iw-1; Fri, 20 Aug 2021 08:45:18 -0400 Received: by mail-pl1-f182.google.com with SMTP id l11so5905584plk.6 for ; Fri, 20 Aug 2021 05:45:17 -0700 (PDT) Received: from localhost ([38.94.109.214]) by smtp.gmail.com with ESMTPSA id s16sm6664286pfk.185.2021.08.20.05.45.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Aug 2021 05:45:16 -0700 (PDT) X-MC-Unique: xtUDWFIeOqC1hQ4b0M26gg-1 X-MC-Unique: 1pbDfuFLMSOae-YLCQC-iw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zK4D71cMNP1Y9D0NjQO4dWP+CpQBh+ZjTaL40aPhfEM=; b=m30MbCrWhFYAl5pg3VYZv/y46CtgvPlUbgqCFaCrCwH2UU0QafmWT3ndse3ZPy1sIF lpv3rv16gojcAePwLG0ZYPociBG9oVkd8zq6uUdnYp74a1NoD7p/Z8uyuNh3rfyeaJiS aq03r7PATRkN5fvJbKZxXXn17tNGkdkDVF+/3I2T2GAs67bEp6KZqlAaPp4gr/BxV6Sy vnoT+qiE2kjWtk63ZAfTwm2mWCadxESmIzt0eo2LQHlU259yefBZe7xQf6WNi9inJ3Ez Uq38KGi5rc2kgUFbihVkMXN7vL0ZrI/QRVgaLIUkCjPwQScUviyXVix66NLRyn6QbfDd B0MA== X-Gm-Message-State: AOAM532xsQLni+Dc8WNVgxwJNV0LiGHkE2mtMcs6gemrVCeiQCFheFXs ct19VPys1TFZBZb2X9PWgZXiGGsQDWFKiXSiQdc= X-Google-Smtp-Source: ABdhPJx/SslQKdPzuG7daEQeNaRL+hTIp12JbqnuJ3htMbHa2/RV8XLRIm3cadfVDvMKX1408bULGA== X-Received: by 2002:a17:90a:ff94:: with SMTP id hf20mr4444109pjb.64.1629463516821; Fri, 20 Aug 2021 05:45:16 -0700 (PDT) From: Luke Yue To: libvir-list@redhat.com Subject: [PATCH v2 11/12] virshtest: add expectError parameter to testCompareOutputLit Date: Fri, 20 Aug 2021 20:44:38 +0800 Message-Id: <20210820124439.535276-12-lukedyue@gmail.com> In-Reply-To: <20210820124439.535276-1-lukedyue@gmail.com> References: <20210820124439.535276-1-lukedyue@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 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.13 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-ZM-MESSAGEID: 1629463599025100001 Content-Type: text/plain; charset="utf-8" Add expectError so that we can failed some test on purpose and compare the error message. There are some problems though, if the command raise an internal error, the test would fail. And when testing command is failed on purpose, the error message will be printed even the test passed. Signed-off-by: Luke Yue --- tests/virshtest.c | 53 ++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/tests/virshtest.c b/tests/virshtest.c index 87da1f5889..0d2ffd960a 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -109,7 +109,7 @@ static int testFilterLine(char *buffer, } =20 static int -testCompareOutputLit(const char *expectData, +testCompareOutputLit(const char *expectData, const char *expectError, const char *filter, const char *const argv[]) { g_autofree char *actualData =3D NULL; @@ -125,14 +125,19 @@ testCompareOutputLit(const char *expectData, virCommandSetOutputBuffer(cmd, &actualData); virCommandSetErrorBuffer(cmd, &errbuf); =20 - if (virCommandRun(cmd, NULL) < 0) + if (virCommandRun(cmd, NULL) < 0 && STREQ(expectError, "")) return -1; =20 - if (STRNEQ(errbuf, "")) { + if (STREQ(expectError, "") && STRNEQ(errbuf, "")) { fprintf(stderr, "Command reported error: %s", errbuf); return -1; } =20 + if (STRNEQ(errbuf, expectError)) { + virTestDifference(stderr, errbuf, expectError); + return -1; + } + if (filter && testFilterLine(actualData, filter) < 0) return -1; =20 @@ -162,7 +167,7 @@ static int testCompareListDefault(const void *data G_GN= UC_UNUSED) ----------------------\n\ 1 test running\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareListCustom(const void *data G_GNUC_UNUSED) @@ -175,7 +180,7 @@ static int testCompareListCustom(const void *data G_GNU= C_UNUSED) 2 fc4 running\n\ 3 fc5 running\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareNodeinfoDefault(const void *data G_GNUC_UNUSED) @@ -191,7 +196,7 @@ Thread(s) per core: 2\n\ NUMA cell(s): 2\n\ Memory size: 3145728 KiB\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareNodeinfoCustom(const void *data G_GNUC_UNUSED) @@ -211,112 +216,112 @@ Thread(s) per core: 2\n\ NUMA cell(s): 4\n\ Memory size: 8192000 KiB\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDominfoByID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "2", NULL }; const char *exp =3D dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit(exp, "", "\nCPU time:", argv); } =20 static int testCompareDominfoByUUID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", DOM_FC4_UUID, = NULL }; const char *exp =3D dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit(exp, "", "\nCPU time:", argv); } =20 static int testCompareDominfoByName(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "fc4", NULL }; const char *exp =3D dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit(exp, "", "\nCPU time:", argv); } =20 static int testCompareTaintedDominfoByName(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "fc5", NULL }; const char *exp =3D dominfo_fc5; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit(exp, "", "\nCPU time:", argv); } =20 static int testCompareDomuuidByID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domuuid", "2", NULL }; const char *exp =3D domuuid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomuuidByName(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domuuid", "fc4", NULL }; const char *exp =3D domuuid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomidByName(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domid", "fc4", NULL }; const char *exp =3D domid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomidByUUID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domid", DOM_FC4_UUID, NU= LL }; const char *exp =3D domid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomnameByID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domname", "2", NULL }; const char *exp =3D domname_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomnameByUUID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domname", DOM_FC4_UUID, = NULL }; const char *exp =3D domname_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomstateByID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domstate", "2", NULL }; const char *exp =3D domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomstateByUUID(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domstate", DOM_FC4_UUID,= NULL }; const char *exp =3D domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomstateByName(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domstate", "fc4", NULL }; const char *exp =3D domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "domcontrol", "fc4", NULL= }; const char *exp =3D "ok\n\n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareGetBlkioParameters(const void *data G_GNUC_UNUSED) { const char *const argv[] =3D { VIRSH_CUSTOM, "blkiotune", "fv0", NULL = }; const char *exp =3D get_blkio_parameters; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 static int testCompareSetBlkioParameters(const void *data G_GNUC_UNUSED) @@ -335,7 +340,7 @@ static int testCompareSetBlkioParameters(const void *da= ta G_GNUC_UNUSED) " SET_BLKIO_PARAMETER ";\ blkiotune fv0", NULL }; const char *exp =3D set_blkio_parameters; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit(exp, "", NULL, argv); } =20 struct testInfo { @@ -346,7 +351,7 @@ struct testInfo { static int testCompareEcho(const void *data) { const struct testInfo *info =3D data; - return testCompareOutputLit(info->result, NULL, info->argv); + return testCompareOutputLit(info->result, "", NULL, info->argv); } =20 =20 --=20 2.33.0