From nobody Mon Feb 9 09:08:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 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=1647964949; cv=none; d=zohomail.com; s=zohoarc; b=eAMisg16QO4KK9MFRHJYrL4N8Z7dca29eYnNl2TaCIwzck7e5mDeR+n6KZFGRKzEJ+vyjxtwJUKIgGiqTFSEkpTiXqeXESWfl6E9XFLxomV60FUSgqT67mLzVnxmh5OSg9wFlSMbTQE1glisoEe+o0g7WNCxIGuFBFU9PEdtbTk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1647964949; 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=0nF/0YECQrHOh1U1UdPUZh/93f+PbAjMKMShRkJQTRw=; b=GX9YSzicsKaapAJV3vI95tlT3GqDrDjJK2psQSJLhl/GWfa1Z+7hKB/bdeWWjaVUM8RPkk3w8Gm40G0SR3cq80QndEiqS10l0sIycXvodsp3myfoViZ401hs69wgl+6H/jzVnRJKko/arNMoG1LqoQ7hukM61ZXSoquzgphTOb0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1647964949345983.2381080052165; Tue, 22 Mar 2022 09:02:29 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-45-ooDUvWOnPkegBMz7CGIUug-1; Tue, 22 Mar 2022 12:02:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7F928339C8; Tue, 22 Mar 2022 16:02:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DBD740CF900; Tue, 22 Mar 2022 16:02:18 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id D1F55193F50F; Tue, 22 Mar 2022 16:02:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 07E43193F6E1 for ; Tue, 22 Mar 2022 16:02:15 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id E7AA3C07F5B; Tue, 22 Mar 2022 16:02:14 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.152]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F975C27E9B for ; Tue, 22 Mar 2022 16:02:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647964948; 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=0nF/0YECQrHOh1U1UdPUZh/93f+PbAjMKMShRkJQTRw=; b=ToBATPAfEVCQ1PUxdl+VblubXd8vyqcPBICuQR4ttigBr99fcRcwtbbDcrB3dI+q6e0XZ4 ij23IgVu+VQ18hIbPd/kw5JlKLy/qoQxiom0Lt2+q4R9jH4pldTYbjWd5sQrdfPvr3G9kK 6ZxKINkOY5LKZvzay4fBHtS0cKROqL8= X-MC-Unique: ooDUvWOnPkegBMz7CGIUug-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 6/7] commandtest: Test virCommandSetSendBuffer() with virCommandDoAsyncIO() Date: Tue, 22 Mar 2022 17:02:05 +0100 Message-Id: <977c7bc5a11e3d23312c875d1ae8775aa1f51ac4.1647964841.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1647964951635100009 Content-Type: text/plain; charset="utf-8"; x-default="true" Introduce a test case which ensures that a daemonized process can work with virCommandSetSendBuffer() when async IO is enabled. Signed-off-by: Michal Privoznik --- tests/commanddata/test29.log | 19 ++++++++ tests/commandtest.c | 84 ++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 tests/commanddata/test29.log diff --git a/tests/commanddata/test29.log b/tests/commanddata/test29.log new file mode 100644 index 0000000000..49993a4947 --- /dev/null +++ b/tests/commanddata/test29.log @@ -0,0 +1,19 @@ +ARG:--close-stdin +ARG:--readfd +ARG:3 +ENV:DISPLAY=3D:0.0 +ENV:HOME=3D/home/test +ENV:HOSTNAME=3Dtest +ENV:LANG=3DC +ENV:LOGNAME=3Dtest +ENV:PATH=3D/usr/bin:/bin +ENV:TMPDIR=3D/tmp +ENV:USER=3Dtest +FD:0 +FD:1 +FD:2 +FD:3 +FD:6 +DAEMON:yes +CWD:/ +UMASK:0022 diff --git a/tests/commandtest.c b/tests/commandtest.c index 10a051124d..573a4f250d 100644 --- a/tests/commandtest.c +++ b/tests/commandtest.c @@ -25,6 +25,7 @@ #include #ifndef WIN32 # include +# include #endif #include =20 @@ -1157,6 +1158,88 @@ test28(const void *unused G_GNUC_UNUSED) } =20 =20 +static int +test29(const void *unused G_GNUC_UNUSED) +{ + g_autoptr(virCommand) cmd =3D virCommandNew(abs_builddir "/commandhelp= er"); + g_autofree char *pidfile =3D virPidFileBuildPath(abs_builddir, "comman= dhelper"); + pid_t pid; + int buffd; + VIR_AUTOCLOSE outfd =3D -1; + size_t buflen =3D 1024 * 10; + g_autofree unsigned char *buffer =3D NULL; + g_autofree char *outactual =3D NULL; + g_autofree char *outexpect =3D NULL; + size_t i; + size_t outactuallen =3D 0; + int ret =3D -1; + + if (!pidfile) + return -1; + + buffer =3D g_new0(unsigned char, buflen + 1); + for (i =3D 0; i < buflen; i++) { + buffer[i] =3D 'a' + i % ('z' - 'a' + 1); + } + buffer[buflen] =3D '\0'; + + outexpect =3D g_strdup_printf("BEGIN STDOUT\n%sEND STDOUT\n", buffer); + + buffd =3D virCommandSetSendBuffer(cmd, &buffer, buflen); + + virCommandAddArg(cmd, "--close-stdin"); + virCommandAddArg(cmd, "--readfd"); + virCommandAddArgFormat(cmd, "%d", buffd); + + virCommandSetOutputFD(cmd, &outfd); + virCommandSetPidFile(cmd, pidfile); + virCommandDaemonize(cmd); + virCommandDoAsyncIO(cmd); + + if (virCommandRun(cmd, NULL) < 0) { + fprintf(stderr, "Cannot run child %s\n", virGetLastErrorMessage()); + goto cleanup; + } + + if (virPidFileReadPath(pidfile, &pid) < 0) { + fprintf(stderr, "cannot read pidfile: %s\n", pidfile); + goto cleanup; + } + + while (1) { + char buf[1024] =3D { 0 }; + int rc =3D 0; + + rc =3D read(outfd, buf, sizeof(buf)); + if (rc < 0) { + fprintf(stderr, "cannot read from output pipe: errno=3D%d\n", = errno); + goto cleanup; + } + + if (rc =3D=3D 0) + break; + + outactual =3D g_renew(char, outactual, outactuallen + rc + 1); + memcpy(outactual + outactuallen, buf, rc); + outactuallen +=3D rc; + outactual[outactuallen] =3D '\0'; + } + + if (STRNEQ_NULLABLE(outactual, outexpect)) { + virTestDifference(stderr, outexpect, outactual); + goto cleanup; + } + + ret =3D checkoutput("test29"); + + cleanup: + if (pidfile) + unlink(pidfile); + + return ret; +} + + static int mymain(void) { @@ -1254,6 +1337,7 @@ mymain(void) DO_TEST(test26); DO_TEST(test27); DO_TEST(test28); + DO_TEST(test29); =20 return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; } --=20 2.34.1