From nobody Sun May 19 10:01:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1677610301545412.8989504488221; Tue, 28 Feb 2023 10:51:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pX548-0006kr-12; Tue, 28 Feb 2023 13:51:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pX546-0006kg-St for qemu-devel@nongnu.org; Tue, 28 Feb 2023 13:51:06 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pX545-0006zK-Cu for qemu-devel@nongnu.org; Tue, 28 Feb 2023 13:51:06 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id E647E5C00D8; Tue, 28 Feb 2023 13:51:04 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Tue, 28 Feb 2023 13:51:04 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Feb 2023 13:51:04 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1677610264; x= 1677696664; bh=HIHkUaAmd5J5Zb5kIv9UKGwuKi6dQDwTNzuIX4wlNzo=; b=M Kl1bqOrNuW5aZUjsxlhxh+Z2HaLl8H9O4A0Qil+BGEl1plFrusvqcev+C5tdSip5 izi/ukeznr07BfHty7zTLO8hLIG5XUUsboyZ+6HLM64gvqaavsUzLBg4R8YxKmGR PPDcXZ5WhzvHsRd1Hj3+O0kRf5HkR7szFh5E2+aCPV1ILy7y0oVxAZcobh7Yxbab ts1B3XyzlN2pFwdhFIkyIMEX7wl21tWNfNzyYIuT2vQ1+0IRP5fyPrQ37bEHx2Id hJxCKlItpuBJlSi2zuV9F0PjBfYkBm8+2otN1S/pzNguvqnIZPDceA+0GzEJ7k3d EhHaTDUP0irZ02dpCvU9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1677610264; x= 1677696664; bh=HIHkUaAmd5J5Zb5kIv9UKGwuKi6dQDwTNzuIX4wlNzo=; b=o qkeJEP12/pQqPFUyDfGde6RR0HSjxe3ga5ZsN/9DZUjZtdR6Tv2X9+DtKlmffaGJ en6Epkt0C2bo+peRVN03TTf+2bKdUKVYQV/ymGI/LfYgzoPbME6TIJ2PfUUpWNUP 6rYuF7ihCRRI8Dor350GL/GSqIdU1JHqrz0wdqZu3roLhHivPJJNoa1l3iCSb6M7 leoeYjdXiZclbJV5TPvttFibBaBp6lBbGx4kghjYd4ld1e1eD7GKQF9bJhKEUX6p lNNcLNTOtJikVVnZm+wLVlNFUmOW8fUVxFhTXT6dOivyAFIkFrJsj072o38wEhT1 1l2JI7vzPw+VkIGLB1WBQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudelfedgheegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpefhvfevufffkffojghfgggtgfesthekredt redtjeenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqe enucggtffrrghtthgvrhhnpeetheekkefggfeivedvtefgleeiffdtleegfeeuledvuddt vdduhfekgfdutdevkeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrih hlfhhrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , marcandre.lureau@gmail.com Cc: qemu-devel@nongnu.org Subject: [PATCH v2 1/3] crypto/luks: Initialize stack variable to silence warning Date: Tue, 28 Feb 2023 11:50:34 -0700 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.25; envelope-from=dxu@dxuuu.xyz; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1677610303298100007 With `../configure --enable-sanitizers`, I was getting the following build error: In file included from /usr/include/string.h:535, from /home/dxu/dev/qemu/include/qemu/osdep.h:99, from ../crypto/block-luks.c:21: In function =E2=80=98memset=E2=80=99, inlined from =E2=80=98qcrypto_block_luks_store_key=E2=80=99 at = ../crypto/block-luks.c:843:9: /usr/include/bits/string_fortified.h:59:10: error: =E2=80=98splitke= ylen=E2=80=99 may be used uninitialized [-Werror=3Dmaybe-uninitialized] 59 | return __builtin___memset_chk (__dest, __ch, __len, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 | __glibc_objsize0 (__dest)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~ ../crypto/block-luks.c: In function =E2=80=98qcrypto_block_luks_sto= re_key=E2=80=99: ../crypto/block-luks.c:699:12: note: =E2=80=98splitkeylen=E2=80=99 = was declared here 699 | size_t splitkeylen; | ^~~~~~~~~~~ cc1: all warnings being treated as errors The function is actually correct -- in the cleanup branch `splitkeylen` usage is guarded by checking `splitkey` nullness. But the compiler is not smart enough to realize that. Fix warning by initializing the variable. Signed-off-by: Daniel Xu --- crypto/block-luks.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypto/block-luks.c b/crypto/block-luks.c index 5688783ab1..bfdef25c80 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -696,7 +696,7 @@ qcrypto_block_luks_store_key(QCryptoBlock *block, QCryptoBlockLUKS *luks =3D block->opaque; QCryptoBlockLUKSKeySlot *slot; g_autofree uint8_t *splitkey =3D NULL; - size_t splitkeylen; + size_t splitkeylen =3D 0; g_autofree uint8_t *slotkey =3D NULL; g_autoptr(QCryptoCipher) cipher =3D NULL; g_autoptr(QCryptoIVGen) ivgen =3D NULL; --=20 2.39.1 From nobody Sun May 19 10:01:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167761037115853.29905508481477; Tue, 28 Feb 2023 10:52:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pX54I-0006oN-0t; Tue, 28 Feb 2023 13:51:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pX54D-0006mF-MY for qemu-devel@nongnu.org; Tue, 28 Feb 2023 13:51:14 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pX54B-00071D-1n for qemu-devel@nongnu.org; Tue, 28 Feb 2023 13:51:12 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 97AE35C0071; Tue, 28 Feb 2023 13:51:10 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 28 Feb 2023 13:51:10 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Feb 2023 13:51:09 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1677610270; x=1677696670; bh=De orb2Ky87bZWhMlXAeaO6j5gbitnxMii99qAMinGqU=; b=N8GD97VOY58jWFxuHf 81WgCTCICDguSBoDV9zkmJT/2suYa4rJLwuMeQfGtJXWjdq6APc/NFTvdD9H4RH5 lAiO3HCD+oMptMCt5I66pI2w7jxo/Vttjymwsz7HFW0FmlCuaXEz7VR1GQe8L6Nl waZo3WhQfdqS1U9VG52HU/ehGqJzf3JV2T/Vs5ZEBPp3Z4AE1a4HlPGxQ0bw/nYr /P3YVQUyhEAIP6ZFJgvdcqz3jfLodT+dncydlyzKT+5rnFDSsbiKZV4C+T+ECDYW JsfebRY3XS2qfZQsMKaERth7k1I6YeTkJknC0lGll4GrV7bhGO5l6YCTExlOOgj5 aKGw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1677610270; x=1677696670; bh=Deorb2Ky87bZW hMlXAeaO6j5gbitnxMii99qAMinGqU=; b=pQwBZlsAfRVS7z/CF/sRHTFVX0eQ+ 2garmF3rcGPImwrkSsOnUATF9CF+lsUt/nUSsd/C9TZip8n7Rf7U3Hmvwc9+w5we hnhmfiLlSVfNVC5aTZCk7lJn9Bek/3ZQCoyPpA1f3A8omYSAuAN1526nQ0alnfp/ ZhiTYi44N1qvLGa8YpXELuhtFKFT+jtLYaAXIgZBTl+TS4wbSVI+7JTcYdprrjyO hmB7w4DSjsA44G6Lov+6NofxejjReLBMwXmYlkprJWXa/NsR5MBoUoetT293vy+A LCMMhGVmZ1pkKtUd38/avJePfAmwkrRO7W3n1TITUYWMK6z14PM9vGadw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudelfedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: kkostiuk@redhat.com, michael.roth@amd.com, marcandre.lureau@gmail.com Cc: qemu-devel@nongnu.org Subject: [PATCH v2 2/3] qga: Add optional `merge-output` flag to guest-exec qapi Date: Tue, 28 Feb 2023 11:50:35 -0700 Message-Id: X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.25; envelope-from=dxu@dxuuu.xyz; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1677610371628100001 Content-Type: text/plain; charset="utf-8" Currently, the captured output (via `capture-output`) is segregated into separate GuestExecStatus fields (`out-data` and `err-data`). This means that downstream consumers have no way to reassemble the captured data back into the original stream. This is relevant for chatty and semi-interactive (ie. read only) CLI tools. Such tools may deliberately interleave stdout and stderr for visual effect. If segregated, the output becomes harder to visually understand. This commit adds a new optional flag to the guest-exec qapi to merge the output streams such that consumers can have a pristine view of the original command output. Signed-off-by: Daniel Xu --- qga/commands.c | 14 ++++++++++++-- qga/qapi-schema.json | 6 +++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/qga/commands.c b/qga/commands.c index 172826f8f8..e13a8e86df 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -270,12 +270,20 @@ static void guest_exec_child_watch(GPid pid, gint sta= tus, gpointer data) g_spawn_close_pid(pid); } =20 -/** Reset ignored signals back to default. */ static void guest_exec_task_setup(gpointer data) { #if !defined(G_OS_WIN32) + bool has_merge =3D *(bool *)data; struct sigaction sigact; =20 + if (has_merge) { + if (dup2(STDOUT_FILENO, STDERR_FILENO) !=3D 0) { + slog("dup2() failed to merge stderr into stdout: %s", + strerror(errno)); + } + } + + /* Reset ignored signals back to default. */ memset(&sigact, 0, sizeof(struct sigaction)); sigact.sa_handler =3D SIG_DFL; =20 @@ -384,6 +392,7 @@ GuestExec *qmp_guest_exec(const char *path, bool has_env, strList *env, const char *input_data, bool has_capture_output, bool capture_output, + bool has_merge_output, bool merge_output, Error **errp) { GPid pid; @@ -397,6 +406,7 @@ GuestExec *qmp_guest_exec(const char *path, GIOChannel *in_ch, *out_ch, *err_ch; GSpawnFlags flags; bool has_output =3D (has_capture_output && capture_output); + bool has_merge =3D (has_merge_output && merge_output); g_autofree uint8_t *input =3D NULL; size_t ninput =3D 0; =20 @@ -420,7 +430,7 @@ GuestExec *qmp_guest_exec(const char *path, } =20 ret =3D g_spawn_async_with_pipes(NULL, argv, envp, flags, - guest_exec_task_setup, NULL, &pid, input_data ? &in_fd : NULL, + guest_exec_task_setup, &has_merge, &pid, input_data ? &in_fd := NULL, has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &ger= r); if (!ret) { error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message); diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json index 796434ed34..9c2367acdf 100644 --- a/qga/qapi-schema.json +++ b/qga/qapi-schema.json @@ -1211,6 +1211,9 @@ # @input-data: data to be passed to process stdin (base64 encoded) # @capture-output: bool flag to enable capture of # stdout/stderr of running process. defaults to false. +# @merge-output: bool flag to merge stdout/stderr of running process +# into stdout. only effective if used with @capture-output. +# not effective on windows guests. defaults to false. (sinc= e 8.0) # # Returns: PID on success. # @@ -1218,7 +1221,8 @@ ## { 'command': 'guest-exec', 'data': { 'path': 'str', '*arg': ['str'], '*env': ['str'], - '*input-data': 'str', '*capture-output': 'bool' }, + '*input-data': 'str', '*capture-output': 'bool', + '*merge-output': 'bool' }, 'returns': 'GuestExec' } =20 =20 --=20 2.39.1 From nobody Sun May 19 10:01:16 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 167761035866252.26691582418812; Tue, 28 Feb 2023 10:52:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pX54I-0006om-7u; Tue, 28 Feb 2023 13:51:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pX54G-0006nr-DM for qemu-devel@nongnu.org; Tue, 28 Feb 2023 13:51:16 -0500 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pX54E-00071l-JD for qemu-devel@nongnu.org; Tue, 28 Feb 2023 13:51:16 -0500 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id C11265C00CF; Tue, 28 Feb 2023 13:51:13 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 28 Feb 2023 13:51:13 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Feb 2023 13:51:12 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm3; t=1677610273; x=1677696673; bh=OK mgUdQ/AbIr0037Bdi6kfEzLOqPts9KtHWtFOPs0WI=; b=JlJuerdDASBVhrzeJR u0IHcQ3KeGgrIPV0BXuSJX8b/FtZM70YGwiTBFcSilexgiPaDU+vvdzsOHQaver7 0Hme+3nzXQxS3NYkBlbCRYM/+k6w3FCMfWvucbm+EjcueCSBcw1MvX49dv7KpHww 65MbGszHz5/+MEGSb32D0jbjzo9zFm30I4oaR7Pb7ljXhCQp0vddK6ypDplDWNx1 xE8alSGd0wCSjt6RfDGUybdOga8HhGg2YgqHW3Eg7X1+RAxaT23Ln8/nv6/BLsf9 BgSJHf/JtNcmlSzS3fzaCfmUUpjaB+m/fEKavAFG0Jq2uysQDSuwnHT45Vmhu5QS LTxg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1677610273; x=1677696673; bh=OKmgUdQ/AbIr0 037Bdi6kfEzLOqPts9KtHWtFOPs0WI=; b=b27ywx+d6G9SMUil7zXDU63WCUVa0 Ff1ndh1GhUgvxh3PqefxBVuxSLy4WJC1CaEFge7TARYKniDFRj1Oxu4PR2YIGdxh DBeyzKlHo6EW2JmiUMVjCH5qpqrMZseMGiduVLbw508KWvyYtZ6npLqP/XTqxAAW JSJjVfiwkMPI478a05c7uJtCiDHeIpnL/Dvy8MqNvfo626djShRwILWfNB0u2146 Ln9dS/46FmMcuDEGj6JqfCBEt1kEavJSOZqDUHr9GQCGYQbdH2PasXfXf3Xz6uEd JT0xeasF5Pl4FreA72G1Cy8yVaTPGHca06Icqtyi/vDIE+Sjb34SZ6Mpw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudelfedgheehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: kkostiuk@redhat.com, michael.roth@amd.com, marcandre.lureau@gmail.com Cc: qemu-devel@nongnu.org Subject: [PATCH v2 3/3] qga: test: Add tests for `merge-output` flag Date: Tue, 28 Feb 2023 11:50:36 -0700 Message-Id: <4d6cb0a2de825fc23c859a2b25836111e8ac0872.1677609866.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=66.111.4.25; envelope-from=dxu@dxuuu.xyz; helo=out1-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1677610359535100001 Content-Type: text/plain; charset="utf-8" This commit adds a test to ensure `merge-output` functions as expected. We also add a negative test to ensure we haven't regressed previous functionality. Signed-off-by: Daniel Xu --- tests/unit/test-qga.c | 133 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 116 insertions(+), 17 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index b4e0a14573..02eb4bf980 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -755,6 +755,31 @@ static void test_qga_fsfreeze_status(gconstpointer fix) g_assert_cmpstr(status, =3D=3D, "thawed"); } =20 +static QDict *wait_for_guest_exec_completion(int fd, int64_t pid) +{ + QDict *ret =3D NULL; + int64_t now; + bool exited; + QDict *val; + + now =3D g_get_monotonic_time(); + do { + ret =3D qmp_fd(fd, + "{'execute': 'guest-exec-status'," + " 'arguments': { 'pid': %" PRId64 " } }", pid); + g_assert_nonnull(ret); + val =3D qdict_get_qdict(ret, "return"); + exited =3D qdict_get_bool(val, "exited"); + if (!exited) { + qobject_unref(ret); + } + } while (!exited && + g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND); + g_assert(exited); + + return ret; +} + static void test_qga_guest_exec(gconstpointer fix) { const TestFixture *fixture =3D fix; @@ -762,9 +787,8 @@ static void test_qga_guest_exec(gconstpointer fix) QDict *val; const gchar *out; g_autofree guchar *decoded =3D NULL; - int64_t pid, now, exitcode; + int64_t pid, exitcode; gsize len; - bool exited; =20 /* exec 'echo foo bar' */ ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" @@ -777,23 +801,10 @@ static void test_qga_guest_exec(gconstpointer fix) g_assert_cmpint(pid, >, 0); qobject_unref(ret); =20 - /* wait for completion */ - now =3D g_get_monotonic_time(); - do { - ret =3D qmp_fd(fixture->fd, - "{'execute': 'guest-exec-status'," - " 'arguments': { 'pid': %" PRId64 " } }", pid); - g_assert_nonnull(ret); - val =3D qdict_get_qdict(ret, "return"); - exited =3D qdict_get_bool(val, "exited"); - if (!exited) { - qobject_unref(ret); - } - } while (!exited && - g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND); - g_assert(exited); + ret =3D wait_for_guest_exec_completion(fixture->fd, pid); =20 /* check stdout */ + val =3D qdict_get_qdict(ret, "return"); exitcode =3D qdict_get_int(val, "exitcode"); g_assert_cmpint(exitcode, =3D=3D, 0); out =3D qdict_get_str(val, "out-data"); @@ -802,6 +813,90 @@ static void test_qga_guest_exec(gconstpointer fix) g_assert_cmpstr((char *)decoded, =3D=3D, "\" test_str \""); } =20 +static void test_qga_guest_exec_output_no_merge(gconstpointer fix) +{ + const TestFixture *fixture =3D fix; + g_autoptr(QDict) ret =3D NULL; + QDict *val; + const gchar *out, *err; + g_autofree guchar *out_decoded =3D NULL; + g_autofree guchar *err_decoded =3D NULL; + int64_t pid, exitcode; + gsize len; + + /* exec 'echo foo bar' */ + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" + " 'path': '/bin/bash'," + " 'arg': [ '-c', 'for i in $(seq 4); do if (( $i %% 2 ));= then echo stdout; else echo stderr 1>&2; fi; done;' ]," + " 'capture-output': true } }"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + val =3D qdict_get_qdict(ret, "return"); + pid =3D qdict_get_int(val, "pid"); + g_assert_cmpint(pid, >, 0); + qobject_unref(ret); + + ret =3D wait_for_guest_exec_completion(fixture->fd, pid); + + val =3D qdict_get_qdict(ret, "return"); + exitcode =3D qdict_get_int(val, "exitcode"); + g_assert_cmpint(exitcode, =3D=3D, 0); + + /* check stdout */ + out =3D qdict_get_str(val, "out-data"); + out_decoded =3D g_base64_decode(out, &len); + g_assert_cmpint(len, =3D=3D, 14); + g_assert_cmpstr((char *)out_decoded, =3D=3D, "stdout\nstdout\n"); + + /* check stderr */ + err =3D qdict_get_try_str(val, "err-data"); + err_decoded =3D g_base64_decode(err, &len); + g_assert_cmpint(len, =3D=3D, 14); + g_assert_cmpstr((char *)err_decoded, =3D=3D, "stderr\nstderr\n"); +} + +static void test_qga_guest_exec_output_merge(gconstpointer fix) +{ +#if !defined(G_OS_WIN32) + const TestFixture *fixture =3D fix; + g_autoptr(QDict) ret =3D NULL; + QDict *val; + const gchar *out, *err; + g_autofree guchar *decoded =3D NULL; + int64_t pid, exitcode; + gsize len; + + /* exec 'echo foo bar' */ + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" + " 'path': '/bin/bash'," + " 'arg': [ '-c', 'for i in $(seq 4); do if (( $i %% 2 ));= then echo stdout; else echo stderr 1>&2; fi; done;' ]," + " 'capture-output': true," + " 'merge-output': true } }"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + val =3D qdict_get_qdict(ret, "return"); + pid =3D qdict_get_int(val, "pid"); + g_assert_cmpint(pid, >, 0); + qobject_unref(ret); + + ret =3D wait_for_guest_exec_completion(fixture->fd, pid); + + val =3D qdict_get_qdict(ret, "return"); + exitcode =3D qdict_get_int(val, "exitcode"); + g_assert_cmpint(exitcode, =3D=3D, 0); + + /* check stdout */ + out =3D qdict_get_str(val, "out-data"); + decoded =3D g_base64_decode(out, &len); + g_assert_cmpint(len, =3D=3D, 28); + g_assert_cmpstr((char *)decoded, =3D=3D, "stdout\nstderr\nstdout\nstde= rr\n"); + + /* check stderr */ + err =3D qdict_get_try_str(val, "err-data"); + g_assert_null(err); +#endif +} + static void test_qga_guest_exec_invalid(gconstpointer fix) { const TestFixture *fixture =3D fix; @@ -972,6 +1067,10 @@ int main(int argc, char **argv) g_test_add_data_func("/qga/blockedrpcs", NULL, test_qga_blockedrpcs); g_test_add_data_func("/qga/config", NULL, test_qga_config); g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec); + g_test_add_data_func("/qga/guest-exec-output-no-merge", &fix, + test_qga_guest_exec_output_no_merge); + g_test_add_data_func("/qga/guest-exec-output-merge", &fix, + test_qga_guest_exec_output_merge); g_test_add_data_func("/qga/guest-exec-invalid", &fix, test_qga_guest_exec_invalid); g_test_add_data_func("/qga/guest-get-osinfo", &fix, --=20 2.39.1