From nobody Mon Feb 9 19:10:44 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 1711194589591654.0461846829163; Sat, 23 Mar 2024 04:49:49 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 5EEA01B47; Sat, 23 Mar 2024 07:49:48 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 019FD189F; Sat, 23 Mar 2024 07:34:53 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id EB40D1E54; Sat, 23 Mar 2024 07:34:46 -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 9BA851B9D for ; Sat, 23 Mar 2024 07:32:52 -0400 (EDT) Received: by mx1.osci.io (Postfix, from userid 994) id EE6DC223EC; Fri, 22 Mar 2024 13:56:50 -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)) (No client certificate requested) by mx1.osci.io (Postfix) with ESMTPS id 4F4F1223EF for ; Fri, 22 Mar 2024 13:56:50 -0400 (EDT) Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-613-w-guBF9sNESsiDDiskDmaQ-1; Fri, 22 Mar 2024 13:56:48 -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 07E5B3C0D7B6 for ; Fri, 22 Mar 2024 17:56:48 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 74BC5492BDB for ; Fri, 22 Mar 2024 17:56:47 +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: w-guBF9sNESsiDDiskDmaQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 30/35] virshtest: Adapt 'virsh-read-bufsiz' and 'virsh-read-non-seekable' Date: Fri, 22 Mar 2024 18:56:08 +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: JLA2PLWHE7EGKDQJ5MK4DJY6D7NB5FOA X-Message-ID-Hash: JLA2PLWHE7EGKDQJ5MK4DJY6D7NB5FOA 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: 1711194590473100001 Test both situations (reading from non-regular file and reading a file larger than (arbitrary) buffer size) via 'virshtest'. To feed the pipe we need to create a thread that does it, but otherwise it's fairly straightforward. Signed-off-by: Peter Krempa --- tests/meson.build | 2 - tests/virsh-read-bufsiz | 49 --------------- tests/virsh-read-non-seekable | 51 --------------- tests/virshtest.c | 90 +++++++++++++++++++++++++++ tests/virshtestdata/read-big-pipe.out | 7 +++ 5 files changed, 97 insertions(+), 102 deletions(-) delete mode 100755 tests/virsh-read-bufsiz delete mode 100755 tests/virsh-read-non-seekable create mode 100644 tests/virshtestdata/read-big-pipe.out diff --git a/tests/meson.build b/tests/meson.build index 46e1679ad7..c760fe68d9 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -691,8 +691,6 @@ if conf.has('WITH_LIBVIRTD') 'libvirtd-fail', 'libvirtd-pool', 'virsh-auth', - 'virsh-read-bufsiz', - 'virsh-read-non-seekable', 'virsh-self-test', 'virsh-uriprecedence', 'virt-admin-self-test', diff --git a/tests/virsh-read-bufsiz b/tests/virsh-read-bufsiz deleted file mode 100755 index a61816c25b..0000000000 --- a/tests/virsh-read-bufsiz +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/sh -# ensure that reading a file larger than BUFSIZ works - -# Copyright (C) 2008, 2010 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" =3D yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=3D0 - -# Output a valid definition, to be used as input. -$abs_top_builddir/tools/virsh -c test:///default dumpxml 1 > xml.t || fail= =3D1 - -# Change the VM name and UUID -sed -e "s|test|newtest|g" \ - -e "\|.*|d" \ - xml.t > xml - -for i in before after; do - # The largest BUFSIZ I've seen is 128K. This is slightly larger. - printf %132000s ' ' > sp || fail=3D1 - in=3Din-$i - # Append or prepend enough spaces to push the size over the limit: - ( test $i =3D before && cat sp xml || cat xml sp ) > $in || fail=3D1 - - $abs_top_builddir/tools/virsh --connect test:///default define $in > out= || fail=3D1 - printf "Domain 'newtest' defined from $in\n\n" > exp || fail=3D1 - compare exp out || fail=3D1 -done - -(exit $fail); exit $fail diff --git a/tests/virsh-read-non-seekable b/tests/virsh-read-non-seekable deleted file mode 100755 index 0f7504c800..0000000000 --- a/tests/virsh-read-non-seekable +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -# ensure that certain file-reading commands can handle non-seekable files - -# Copyright (C) 2008 Red Hat, Inc. - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 2 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see -# . - -. "$(dirname $0)/test-lib.sh" - -if test "$VERBOSE" =3D yes; then - set -x - $abs_top_builddir/tools/virsh --version -fi - -fail=3D0 - -cat <<\EOF > dom - - t2 - 004b96e1-2d78-c30f-5aa5-000000000000 - 8388608 - 2 - - xen - - restart - destroy - restart - -EOF - -$abs_top_builddir/tools/virsh -c test:///default define dom > /dev/null ||= fail=3D1 - -mkfifo_or_skip_ fifo -cat dom > fifo & - -$abs_top_builddir/tools/virsh -c test:///default define fifo > /dev/null |= | fail=3D1 - -(exit $fail); exit $fail diff --git a/tests/virshtest.c b/tests/virshtest.c index 8bb94b7693..f520ff9fc9 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -1,11 +1,14 @@ #include #include +#include #include "internal.h" #include "testutils.h" #include "vircommand.h" +#include "util/virthread.h" + #define VIR_FROM_THIS VIR_FROM_NONE #ifdef WIN32 @@ -103,6 +106,90 @@ static int testCompare(const void *data) } +static void +testPipeFeeder(void *opaque) +{ + /* feed more than observed buffer size which was historically 128k in = the + * test this was adapted from */ + size_t emptyspace =3D 140 * 1024; + const char *pipepath =3D opaque; + const char *xml =3D + "\n" + " t2\n" + " 004b96e1-2d78-c30f-5aa5-000000000000\n" + " 8388608\n" + " 2\n" + " \n" + " xen\n" + " \n" + "\n"; + size_t xmlsize =3D strlen(xml); + g_autofree char *doc =3D g_new0(char, emptyspace + xmlsize + 1); + VIR_AUTOCLOSE fd =3D -1; + + if ((fd =3D open(pipepath, O_RDWR)) < 0) { + fprintf(stderr, "\nfailed to open pipe '%s': %s\n", pipepath, g_st= rerror(errno)); + return; + } + + memset(doc, ' ', emptyspace); + virStrcpy(doc + emptyspace, xml, xmlsize); + + if (safewrite(fd, doc, emptyspace + xmlsize + 1) < 0) { + fprintf(stderr, "\nfailed to write to pipe '%s': %s\n", pipepath, = g_strerror(errno)); + return; + } +} + + +static int +testVirshPipe(const void *data G_GNUC_UNUSED) +{ + char tmpdir[] =3D "/tmp/libvirt_virshtest_XXXXXXX"; + g_autofree char *pipepath =3D NULL; + virThread feeder; + bool join =3D false; + g_autofree char *cmdstr =3D NULL; + const char *argv[] =3D { VIRSH_DEFAULT, NULL, NULL }; + int ret =3D -1; + + if (!g_mkdtemp(tmpdir)) { + fprintf(stderr, "\nfailed to create temporary directory\n"); + return -1; + } + + pipepath =3D g_strdup_printf("%s/pipe", tmpdir); + + + cmdstr =3D g_strdup_printf("define %s ; list --all", pipepath); + argv[3] =3D cmdstr; + + if (mkfifo(pipepath, 0600) < 0) { + fprintf(stderr, "\nfailed to create pipe '%s': %s\n", pipepath, g_= strerror(errno)); + goto cleanup; + } + + if (virThreadCreate(&feeder, true, testPipeFeeder, pipepath) < 0) + goto cleanup; + + join =3D true; + + if (testCompareOutputLit(abs_srcdir "/virshtestdata/read-big-pipe.out", + "/tmp/libvirt_virshtest", argv) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + if (join) + virThreadJoin(&feeder); + unlink(pipepath); + rmdir(tmpdir); + + return ret; +} + + static int mymain(void) { @@ -238,6 +325,9 @@ mymain(void) "checkpoint-create test --redefine checkpoint-c2.xml ;" "checkpoint-info test c2"); + if (virTestRun("read-big-pipe", testVirshPipe, NULL) < 0) + ret =3D -1; + VIR_FREE(custom_uri); return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tests/virshtestdata/read-big-pipe.out b/tests/virshtestdata/re= ad-big-pipe.out new file mode 100644 index 0000000000..340432210d --- /dev/null +++ b/tests/virshtestdata/read-big-pipe.out @@ -0,0 +1,7 @@ +Domain 't2' defined from=20 + + Id Name State +----------------------- + 1 test running + - t2 shut off + --=20 2.44.0 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org