From nobody Mon Feb 9 20:37:02 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 1711193690409708.3353842597572; Sat, 23 Mar 2024 04:34:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DDD841AAB; Sat, 23 Mar 2024 07:34:48 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C55811DE2; Sat, 23 Mar 2024 07:33:01 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1675F1DCF; Sat, 23 Mar 2024 07:32:56 -0400 (EDT) Received: from mx1.osci.io (polly.osci.io [8.43.85.229]) (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 4A82519CD for ; Sat, 23 Mar 2024 07:32:51 -0400 (EDT) Received: by mx1.osci.io (Postfix, from userid 994) id 8DD7A223D1; Fri, 22 Mar 2024 13:56:34 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by mx1.osci.io (Postfix) with ESMTPS id A95DF223CB for ; Fri, 22 Mar 2024 13:56:33 -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-279-KGqQV190Pvu8waCyKc158g-1; Fri, 22 Mar 2024 13:56:30 -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 9E9E084B165 for ; Fri, 22 Mar 2024 17:56:30 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 184EA492BDA for ; Fri, 22 Mar 2024 17:56:29 +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,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-MC-Unique: KGqQV190Pvu8waCyKc158g-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 12/35] virshtest: Adapt tests for domain id lookup and state query to DO_TEST_SCRIPT Date: Fri, 22 Mar 2024 18:55:50 +0100 Message-ID: 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: GRV6M5P26WK4HZ3NFPSBCWEAOTDDF25Y X-Message-ID-Hash: GRV6M5P26WK4HZ3NFPSBCWEAOTDDF25Y X-MailFrom: SRS0=Xa5W=K4=redhat.com=pkrempa@osci.io 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: 1711193691175100001 All of the commands can be tested in one 'virsh' run in batch mode and tested against a file rather than hardcoded strings. Signed-off-by: Peter Krempa --- tests/virshtest.c | 204 +----------------------------- tests/virshtestdata/domain-id.in | 18 +++ tests/virshtestdata/domain-id.out | 73 +++++++++++ 3 files changed, 92 insertions(+), 203 deletions(-) create mode 100644 tests/virshtestdata/domain-id.in create mode 100644 tests/virshtestdata/domain-id.out diff --git a/tests/virshtest.c b/tests/virshtest.c index cdd5468bc1..53c9042330 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -18,59 +18,10 @@ main(void) #else -# define DOM_FC4_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" -# define DOM_FC5_UUID "08721f99-3d1d-4aec-96eb-97803297bb36" -# define SECURITY_LABEL "libvirt-test (enforcing)" -# define FC4_MESSAGES "tainted: network configuration using opaque shell s= cripts" -# define FC5_MESSAGES "tainted: running with undesirable elevated privileg= es\n\ - tainted: network configuration using opaque shell scripts\= n\ - tainted: use of host cdrom passthrough\n\ - tainted: custom device tree blob used\n\ - tainted: use of deprecated configuration settings\n\ - deprecated configuration: CPU model Deprecated-Test" # define GET_BLKIO_PARAMETER "/dev/hda,700" # define SET_BLKIO_PARAMETER "/dev/hda,1000" # define EQUAL "=3D" -static const char *dominfo_fc4 =3D "\ -Id: 2\n\ -Name: fc4\n\ -UUID: " DOM_FC4_UUID "\n\ -OS Type: linux\n\ -State: running\n\ -CPU(s): 1\n\ -Max memory: 261072 KiB\n\ -Used memory: 131072 KiB\n\ -Persistent: yes\n\ -Autostart: disable\n\ -Managed save: no\n\ -Security model: testSecurity\n\ -Security DOI: \n\ -Security label: " SECURITY_LABEL "\n\ -Messages: " FC4_MESSAGES "\n\ -\n"; -static const char *domuuid_fc4 =3D DOM_FC4_UUID "\n\n"; -static const char *domid_fc4 =3D "2\n\n"; -static const char *domname_fc4 =3D "fc4\n\n"; -static const char *domstate_fc4 =3D "running\n\n"; -static const char *dominfo_fc5 =3D "\ -Id: 3\n\ -Name: fc5\n\ -UUID: " DOM_FC5_UUID "\n\ -OS Type: linux\n\ -State: running\n\ -CPU(s): 4\n\ -Max memory: 2097152 KiB\n\ -Used memory: 2097152 KiB\n\ -Persistent: yes\n\ -Autostart: disable\n\ -Managed save: no\n\ -Security model: testSecurity\n\ -Security DOI: \n\ -Security label: " SECURITY_LABEL "\n\ -Messages: " FC5_MESSAGES "\n\ -\n"; - static const char *get_blkio_parameters =3D "\ weight : 800\n\ device_weight : " GET_BLKIO_PARAMETER "\n\ @@ -159,104 +110,6 @@ static char *custom_uri; "--connect", \ custom_uri -static int testCompareDominfoByID(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "2", NULL }; - const char *exp =3D dominfo_fc4; - return testCompareOutputLit((const char *) data, exp, "\nCPU time:", a= rgv); -} - -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((const char *) data, exp, "\nCPU time:", a= rgv); -} - -static int testCompareDominfoByName(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "fc4", NULL }; - const char *exp =3D dominfo_fc4; - return testCompareOutputLit((const char *) data, exp, "\nCPU time:", a= rgv); -} - -static int testCompareTaintedDominfoByName(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "dominfo", "fc5", NULL }; - const char *exp =3D dominfo_fc5; - return testCompareOutputLit((const char *) data, exp, "\nCPU time:", a= rgv); -} - -static int testCompareDomuuidByID(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "domuuid", "2", NULL }; - const char *exp =3D domuuid_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomuuidByName(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "domuuid", "fc4", NULL }; - const char *exp =3D domuuid_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -static int testCompareDomidByName(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "domid", "fc4", NULL }; - const char *exp =3D domid_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -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((const char *) data, exp, NULL, argv); -} - -static int testCompareDomnameByID(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "domname", "2", NULL }; - const char *exp =3D domname_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -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((const char *) data, exp, NULL, argv); -} - -static int testCompareDomstateByID(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "domstate", "2", NULL }; - const char *exp =3D domstate_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -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((const char *) data, exp, NULL, argv); -} - -static int testCompareDomstateByName(const void *data) -{ - const char *const argv[] =3D { VIRSH_CUSTOM, "domstate", "fc4", NULL }; - const char *exp =3D domstate_fc4; - return testCompareOutputLit((const char *) data, exp, NULL, argv); -} - -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((const char *) data, exp, NULL, argv); -} - static int testCompareGetBlkioParameters(const void *data) { const char *const argv[] =3D { VIRSH_CUSTOM, "blkiotune", "fv0", NULL = }; @@ -404,62 +257,6 @@ mymain(void) custom_uri =3D g_strdup_printf("test://%s/../examples/xml/test/testnod= e.xml", abs_srcdir); - if (virTestRun("virsh dominfo (by id)", - testCompareDominfoByID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh dominfo (by uuid)", - testCompareDominfoByUUID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh dominfo (by name)", - testCompareDominfoByName, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh dominfo (by name, more tainted messages)", - testCompareTaintedDominfoByName, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domid (by name)", - testCompareDomidByName, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domid (by uuid)", - testCompareDomidByUUID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domuuid (by id)", - testCompareDomuuidByID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domuuid (by name)", - testCompareDomuuidByName, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domname (by id)", - testCompareDomnameByID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domname (by uuid)", - testCompareDomnameByUUID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domstate (by id)", - testCompareDomstateByID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domstate (by uuid)", - testCompareDomstateByUUID, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domstate (by name)", - testCompareDomstateByName, NULL) !=3D 0) - ret =3D -1; - - if (virTestRun("virsh domcontrol (by name)", - testCompareDomControlInfoByName, NULL) !=3D 0) - ret =3D -1; - if (virTestRun("virsh blkiotune (get parameters)", testCompareGetBlkioParameters, NULL) !=3D 0) ret =3D -1; @@ -506,6 +303,7 @@ mymain(void) DO_TEST_SCRIPT("info-default", NULL, VIRSH_DEFAULT); DO_TEST_SCRIPT("info-custom", NULL, VIRSH_CUSTOM); + DO_TEST_SCRIPT("domain-id", "\nCPU time:", VIRSH_CUSTOM); # define DO_TEST_FULL(testname_, filter, ...) \ do { \ diff --git a/tests/virshtestdata/domain-id.in b/tests/virshtestdata/domain-= id.in new file mode 100644 index 0000000000..6605baa090 --- /dev/null +++ b/tests/virshtestdata/domain-id.in @@ -0,0 +1,18 @@ +dominfo ef861801-45b9-11cb-88e3-afbfe5370493 +dominfo fc4 +dominfo fc5 + +domid fc4 +domid ef861801-45b9-11cb-88e3-afbfe5370493 + +domuuid 2 +domuuid fc4 + +domname 2 +domname ef861801-45b9-11cb-88e3-afbfe5370493 + +domstate 2 +domstate ef861801-45b9-11cb-88e3-afbfe5370493 +domstate fc4 + +domcontrol fc4 diff --git a/tests/virshtestdata/domain-id.out b/tests/virshtestdata/domain= -id.out new file mode 100644 index 0000000000..8e6174fd21 --- /dev/null +++ b/tests/virshtestdata/domain-id.out @@ -0,0 +1,73 @@ +Id: 2 +Name: fc4 +UUID: ef861801-45b9-11cb-88e3-afbfe5370493 +OS Type: linux +State: running +CPU(s): 1 +Max memory: 261072 KiB +Used memory: 131072 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: =20 +Security label: libvirt-test (enforcing) +Messages: tainted: network configuration using opaque shell scripts + +Id: 2 +Name: fc4 +UUID: ef861801-45b9-11cb-88e3-afbfe5370493 +OS Type: linux +State: running +CPU(s): 1 +Max memory: 261072 KiB +Used memory: 131072 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: =20 +Security label: libvirt-test (enforcing) +Messages: tainted: network configuration using opaque shell scripts + +Id: 3 +Name: fc5 +UUID: 08721f99-3d1d-4aec-96eb-97803297bb36 +OS Type: linux +State: running +CPU(s): 4 +Max memory: 2097152 KiB +Used memory: 2097152 KiB +Persistent: yes +Autostart: disable +Managed save: no +Security model: testSecurity +Security DOI: =20 +Security label: libvirt-test (enforcing) +Messages: tainted: running with undesirable elevated privileges + tainted: network configuration using opaque shell scripts + tainted: use of host cdrom passthrough + tainted: custom device tree blob used + tainted: use of deprecated configuration settings + deprecated configuration: CPU model Deprecated-Test + +2 + +2 + +ef861801-45b9-11cb-88e3-afbfe5370493 + +ef861801-45b9-11cb-88e3-afbfe5370493 + +fc4 + +fc4 + +running + +running + +running + +ok + --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org