From nobody Tue Feb 10 00:23:58 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1711130287851640.7342175159522; Fri, 22 Mar 2024 10:58:07 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6499D1C65; Fri, 22 Mar 2024 13:58:06 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 340421A96; Fri, 22 Mar 2024 13:56:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B562D1A62; Fri, 22 Mar 2024 13:56:23 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id A088A1A62 for ; Fri, 22 Mar 2024 13:56:22 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-439-ybMIE7ZIPD2yFqI80oL9Tg-1; Fri, 22 Mar 2024 13:56:20 -0400 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8195918653A2 for ; Fri, 22 Mar 2024 17:56:20 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id F0195492BFA for ; Fri, 22 Mar 2024 17:56:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: ybMIE7ZIPD2yFqI80oL9Tg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 01/35] virshtest: Prepare for testing against output files Date: Fri, 22 Mar 2024 18:55:39 +0100 Message-ID: <94e6294c98fc98f83666183e45bbe2bded932e78.1711129973.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Message-ID-Hash: 443YS22KFKQQBPMRLRBH2QWRCHZW43VL X-Message-ID-Hash: 443YS22KFKQQBPMRLRBH2QWRCHZW43VL X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1711130290073100001 Modify testCompareOutputLit to take a filename argument and compare it against and populate the arguments. For tests which don't use the 'data' from virTestRun, we'll expect to pass the output filename, thus we also propagate it. Signed-off-by: Peter Krempa --- build-aux/syntax-check.mk | 6 +- tests/virshtest.c | 130 +++++++++++++++++++++----------------- 2 files changed, 76 insertions(+), 60 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 2ac8c5760f..0759372b2b 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -1386,7 +1386,7 @@ exclude_file_name_regexp--sc_prohibit_close =3D \ (\.p[yl]$$|\.spec\.in$$|^docs/|^(src/util/vir(file|event)\.c|src/libvirt= -stream\.c|tests/(vir.+mock\.c|commandhelper\.c|qemusecuritymock\.c)|tools/= nss/libvirt_nss_(leases|macs)\.c)|tools/virt-qemu-qmp-proxy$$) exclude_file_name_regexp--sc_prohibit_empty_lines_at_EOF =3D \ - ((^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest|qe= munbdkit)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/virconfdata/= no-newline\.conf$$)|\.bin) + ((^tests/(nodedevmdevctl|viracpi|virhostcpu|virpcitest|virstoragetest|qe= munbdkit|virshtest)data/|docs/js/.*\.js|docs/fonts/.*\.woff|\.diff|tests/vi= rconfdata/no-newline\.conf$$)|\.bin) exclude_file_name_regexp--sc_prohibit_fork_wrappers =3D \ (^(src/(util/(vircommand|virdaemon)|lxc/lxc_controller)|tests/testutils)= \.c$$) @@ -1437,7 +1437,7 @@ exclude_file_name_regexp--sc_require_config_h_first = =3D \ ^(examples/|tools/virsh-edit\.c$$|tests/virmockstathelpers\.c$$|scripts/r= pcgen/tests/test_demo\.c$$) exclude_file_name_regexp--sc_trailing_blank =3D \ - /sysinfodata/.*\.data|/virhostcpudata/.*\.cpuinfo$$ + /sysinfodata/.*\.data|/virhostcpudata/.*\.cpuinfo|tests/virshtestdata/.*= $$ exclude_file_name_regexp--sc_unmarked_diagnostics =3D \ ^(scripts/apibuild.py|tests/virt-aa-helper-test|docs/js/.*\.js)$$ @@ -1466,7 +1466,7 @@ exclude_file_name_regexp--sc_prohibit_mixed_case_abbr= eviations =3D \ ^src/(vbox/vbox_CAPI.*.h|esx/esx_vi.(c|h)|esx/esx_storage_backend_iscsi.= c)$$ exclude_file_name_regexp--sc_prohibit_empty_first_line =3D \ - ^tests/vmwareverdata/fusion-5.0.3.txt|scripts/rpcgen/tests/demo\.c$$ + ^tests/vmwareverdata/fusion-5.0.3.txt|scripts/rpcgen/tests/demo\.c|^test= s/virshtestdata/.*$$ exclude_file_name_regexp--sc_prohibit_useless_translation =3D \ ^tests/virpolkittest.c diff --git a/tests/virshtest.c b/tests/virshtest.c index cf834bb847..5a5068dc78 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -108,8 +108,10 @@ static int testFilterLine(char *buffer, } static int -testCompareOutputLit(const char *expectData, - const char *filter, const char *const argv[]) +testCompareOutputLit(const char *expectFile, + const char *expectData, + const char *filter, + const char *const argv[]) { g_autofree char *actualData =3D NULL; const char *empty =3D ""; @@ -134,8 +136,14 @@ testCompareOutputLit(const char *expectData, if (filter && testFilterLine(actualData, filter) < 0) return -1; - if (virTestCompareToString(expectData, actualData) < 0) { - return -1; + if (expectData) { + if (virTestCompareToString(expectData, actualData) < 0) + return -1; + } + + if (expectFile) { + if (virTestCompareToFileFull(actualData, expectFile, false) < 0) + return -1; } return 0; @@ -151,7 +159,7 @@ static char *custom_uri; "--connect", \ custom_uri -static int testCompareListDefault(const void *data G_GNUC_UNUSED) +static int testCompareListDefault(const void *data) { const char *const argv[] =3D { VIRSH_DEFAULT, "list", NULL }; const char *exp =3D "\ @@ -159,10 +167,10 @@ static int testCompareListDefault(const void *data G_= GNUC_UNUSED) ----------------------\n\ 1 test running\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareListCustom(const void *data G_GNUC_UNUSED) +static int testCompareListCustom(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "list", NULL }; const char *exp =3D "\ @@ -172,10 +180,10 @@ static int testCompareListCustom(const void *data G_G= NUC_UNUSED) 2 fc4 running\n\ 3 fc5 running\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareNodeinfoDefault(const void *data G_GNUC_UNUSED) +static int testCompareNodeinfoDefault(const void *data) { const char *const argv[] =3D { VIRSH_DEFAULT, "nodeinfo", NULL }; const char *exp =3D "\ @@ -188,10 +196,10 @@ Thread(s) per core: 2\n\ NUMA cell(s): 2\n\ Memory size: 3145728 KiB\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareNodeinfoCustom(const void *data G_GNUC_UNUSED) +static int testCompareNodeinfoCustom(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, @@ -208,115 +216,115 @@ Thread(s) per core: 2\n\ NUMA cell(s): 4\n\ Memory size: 8192000 KiB\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDominfoByID(const void *data G_GNUC_UNUSED) +static int testCompareDominfoByID(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "2", NULL }; const char *exp =3D dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit((const char *) data, exp, "\nCPU time:", a= rgv); } -static int testCompareDominfoByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDominfoByUUID(const void *data) { 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((const char *) data, exp, "\nCPU time:", a= rgv); } -static int testCompareDominfoByName(const void *data G_GNUC_UNUSED) +static int testCompareDominfoByName(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "fc4", NULL }; const char *exp =3D dominfo_fc4; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit((const char *) data, exp, "\nCPU time:", a= rgv); } -static int testCompareTaintedDominfoByName(const void *data G_GNUC_UNUSED) +static int testCompareTaintedDominfoByName(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "fc5", NULL }; const char *exp =3D dominfo_fc5; - return testCompareOutputLit(exp, "\nCPU time:", argv); + return testCompareOutputLit((const char *) data, exp, "\nCPU time:", a= rgv); } -static int testCompareDomuuidByID(const void *data G_GNUC_UNUSED) +static int testCompareDomuuidByID(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domuuid", "2", NULL }; const char *exp =3D domuuid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomuuidByName(const void *data G_GNUC_UNUSED) +static int testCompareDomuuidByName(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domuuid", "fc4", NULL }; const char *exp =3D domuuid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomidByName(const void *data G_GNUC_UNUSED) +static int testCompareDomidByName(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domid", "fc4", NULL }; const char *exp =3D domid_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomidByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDomidByUUID(const void *data) { 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((const char *) data, exp, NULL, argv); } -static int testCompareDomnameByID(const void *data G_GNUC_UNUSED) +static int testCompareDomnameByID(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domname", "2", NULL }; const char *exp =3D domname_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomnameByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDomnameByUUID(const void *data) { 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((const char *) data, exp, NULL, argv); } -static int testCompareDomstateByID(const void *data G_GNUC_UNUSED) +static int testCompareDomstateByID(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domstate", "2", NULL }; const char *exp =3D domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomstateByUUID(const void *data G_GNUC_UNUSED) +static int testCompareDomstateByUUID(const void *data) { 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((const char *) data, exp, NULL, argv); } -static int testCompareDomstateByName(const void *data G_GNUC_UNUSED) +static int testCompareDomstateByName(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domstate", "fc4", NULL }; const char *exp =3D domstate_fc4; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED) +static int testCompareDomControlInfoByName(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domcontrol", "fc4", NULL= }; const char *exp =3D "ok\n\n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareGetBlkioParameters(const void *data G_GNUC_UNUSED) +static int testCompareGetBlkioParameters(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "blkiotune", "fv0", NULL = }; const char *exp =3D get_blkio_parameters; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testCompareSetBlkioParameters(const void *data G_GNUC_UNUSED) +static int testCompareSetBlkioParameters(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "blkiotune fv0\ --weight 500\ @@ -332,10 +340,10 @@ static int testCompareSetBlkioParameters(const void *= data G_GNUC_UNUSED) " SET_BLKIO_PARAMETER ";\ blkiotune fv0", NULL }; const char *exp =3D set_blkio_parameters; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadAdd(const void *data G_GNUC_UNUSED) +static int testIOThreadAdd(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "iothreadinfo --domain fc= 4;\ iothreadadd --domain fc4 --id 6;\ @@ -353,10 +361,10 @@ static int testIOThreadAdd(const void *data G_GNUC_UN= USED) 4 0\n\ 6 0\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadDel(const void *data G_GNUC_UNUSED) +static int testIOThreadDel(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "iothreadinfo --domain fc= 4;\ iothreaddel --domain fc4 --id 2;\ @@ -372,10 +380,10 @@ static int testIOThreadDel(const void *data G_GNUC_UN= USED) -----------------------------\n\ 4 0\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadSet(const void *data G_GNUC_UNUSED) +static int testIOThreadSet(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "domstats --domain fc4;\ iothreadset --domain fc4\ @@ -404,10 +412,10 @@ Domain: 'fc4'\n\ iothread.4.poll-max-ns" EQUAL "32768\n\ iothread.4.poll-grow" EQUAL "0\n\ iothread.4.poll-shrink" EQUAL "0\n\n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } -static int testIOThreadPin(const void *data G_GNUC_UNUSED) +static int testIOThreadPin(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "iothreadadd --domain fc5 --id 2;\ @@ -425,18 +433,27 @@ static int testIOThreadPin(const void *data G_GNUC_UN= USED) -----------------------------\n\ 2 0\n\ \n"; - return testCompareOutputLit(exp, NULL, argv); + return testCompareOutputLit((const char *) data, exp, NULL, argv); } struct testInfo { + const char *testname; /* used to generate output filename */ + const char *filter; const char *const *argv; const char *result; }; -static int testCompareEcho(const void *data) +static int testCompare(const void *data) { const struct testInfo *info =3D data; - return testCompareOutputLit(info->result, NULL, info->argv); + g_autofree char *outfile =3D NULL; + + if (info->testname) { + outfile =3D g_strdup_printf("%s/virshtestdata/%s.out", + abs_srcdir, info->testname); + } + + return testCompareOutputLit(outfile, info->result, info->filter, info-= >argv); } @@ -549,9 +566,8 @@ mymain(void) # define DO_TEST(i, result, ...) \ do { \ const char *myargv[] =3D { VIRSH_DEFAULT, __VA_ARGS__, NULL }; \ - const struct testInfo info =3D { myargv, result }; \ - if (virTestRun("virsh echo " #i, \ - testCompareEcho, &info) < 0) \ + const struct testInfo info =3D { NULL, NULL, myargv, result }; \ + if (virTestRun("virsh echo " #i, testCompare, &info) < 0) \ ret =3D -1; \ } while (0) --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org