From nobody Wed May 15 03:52:49 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 167721307647199.95177355138173; Thu, 23 Feb 2023 20:31:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVPiz-00074C-I8; Thu, 23 Feb 2023 23:30:25 -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 1pVLqT-0005RF-RH for qemu-devel@nongnu.org; Thu, 23 Feb 2023 19:21:53 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVLqS-0000Cl-9F for qemu-devel@nongnu.org; Thu, 23 Feb 2023 19:21:53 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 70C5E5C01AE; Thu, 23 Feb 2023 19:21:49 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Thu, 23 Feb 2023 19:21:49 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 23 Feb 2023 19:21:48 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=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=1677198109; x=1677284509; bh=mh PfI2B83HcaOVUPGacb7vOqA72CJmYkLPX8XYkeom4=; b=GElvW12r+wdX1fhn47 TSSX9I8dcBhKc4vbkLf654lV0VIRfFP7pONmqGKad6SnQXXmD9F35yTHhL5XuIIP qpkbv9xJjPwzBYIu16HpAO2jGMdTu9hc0xdiTFICHTnnB+0uQxThJr/beRX1u9V3 Zr4p4AByezG2sswZGtn54nLwYjO/zgED2/mRJduI0wNj+LsI5FK+lhAA2HYGiJg+ 6FqnS1sB3fbeV+EwoGLEolb5UszYsiIk5Gh3lhDR/l0ZoVDPQTMt9GGFkgGkaapc tI9eG14R0vvFp/W9MAESRfCvdJYhnx/BQbe3TtUYOCpCXKVQBw5Q8dbWusoZ+EuT /ouw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=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=1677198109; x=1677284509; bh=mhPfI2B83HcaO VUPGacb7vOqA72CJmYkLPX8XYkeom4=; b=gImZQdmFrMmqv32F0P4w9otoeX43k ZyoIM4SeZpBqDYW28YOuqUlsZ9HcPZhgOqbMSSpGU7cT+YluC+YXd92ACfzrnJ4t nFSH3PxzG6YDSnqEzJuX+lEaa8Jz1uDtX7KvJDk/Q6NIN/cgZykkX/LQ0deuIB5q /HpiwE8ZHOi+0KBzaNz2OKrpkqvbP2u5BSSITqtrWtBmsaerEZhakwrbup1kJAph NQfv3yupfROZZng2kpRia5wiqi0piZJ4T+SX+/Q2o71zU4LBE88PEZC3eh3kDU2x viODvbGZneQ8qW+VPgc+VnwWfDHEwNBcD53k6cYDr/4kDpE+ejE6WUCZQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekvddgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpefhvffufffkofgjfhgggfestdekredtredt tdenucfhrhhomhepffgrnhhivghlucgiuhcuoegugihusegugihuuhhurdighiiiqeenuc ggtffrrghtthgvrhhnpefgkeduleekhfetvefhgefgvdegfeejfefguedvuddthffggffh hedtueeuteefieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegugihusegugihuuhhurdighiii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: Michael Roth , Konstantin Kostiuk , qemu-devel@nongnu.org Subject: [PATCH 1/3] qga: test: Use absolute path to test data Date: Thu, 23 Feb 2023 17:21:30 -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.29; envelope-from=dxu@dxuuu.xyz; helo=out5-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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 23 Feb 2023 23:30:19 -0500 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: 1677213078527100009 Content-Type: text/plain; charset="utf-8" It looks like qga's working directory is in a tempdir. So the relative path that the test case gives qga through the QGA_OS_RELEASE=3D env variable does not resolve correctly. Fix by doing a poor man's path canonicalization of the test data file. Note we cannot use g_canonicalize_filename() b/c that helper was only introduced in glib 2.58 and the current GLIB_VERSION_MAX_ALLOWED is pinned to 2.56. Signed-off-by: Daniel Xu --- tests/unit/test-qga.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index b4e0a14573..9d8e1d1cd3 100644 --- a/tests/unit/test-qga.c +++ b/tests/unit/test-qga.c @@ -881,13 +881,16 @@ static void test_qga_guest_get_osinfo(gconstpointer d= ata) { TestFixture fixture; const gchar *str; + g_autofree const gchar *cwd; g_autoptr(QDict) ret =3D NULL; char *env[2]; QDict *val; =20 + cwd =3D g_get_current_dir(); env[0] =3D g_strdup_printf( - "QGA_OS_RELEASE=3D%s%c..%cdata%ctest-qga-os-release", - g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_D= IR_SEPARATOR); + "QGA_OS_RELEASE=3D%s%c%s%c..%cdata%ctest-qga-os-release", + cwd, G_DIR_SEPARATOR, g_test_get_dir(G_TEST_DIST), G_DIR_SEPARATOR, + G_DIR_SEPARATOR, G_DIR_SEPARATOR); env[1] =3D NULL; fixture_setup(&fixture, NULL, env); =20 --=20 2.39.1 From nobody Wed May 15 03:52:49 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 1677213076604626.8650297601104; Thu, 23 Feb 2023 20:31:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVPjK-00078n-Nj; Thu, 23 Feb 2023 23:30:46 -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 1pVNSr-0001qh-En for qemu-devel@nongnu.org; Thu, 23 Feb 2023 21:05:38 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVNSo-0007Pj-7s for qemu-devel@nongnu.org; Thu, 23 Feb 2023 21:05:37 -0500 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 895855C019E; Thu, 23 Feb 2023 21:05:33 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 23 Feb 2023 21:05:33 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 23 Feb 2023 21:05:32 -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=1677204333; x=1677290733; bh=dG UQpzCg8TTG1lYtYf7iL4BAdJ4WD0zj1nWU7lBFehI=; b=DsNXUQ67in6N4Q9Pnb W2uEBU2zCc7A0SHSvlXP3Zt/mwnPNYOI2MbuDljmqxkPTJYoGi79ZJUt5xraXxNn yjWCyjpz33Nu1t26GUAusbHCQj0iLhVucwheZZFR8Vbh5g4UI60aWP9arSNhYZHF gP36jMcdOzmVqk7Quplf5xrT9hZq7qaQVqK0sgqzMVek71ivSCxoesMlRoYlNsbO SJ5EmPTYntpq18q1zXcVzotTbb2pPdyZ2ClwikMYKkRF9nQnAK/vFta90EiIAsqH BLq2D7wvUyzjufP4Qcj39Zy5bFc2i88Ew2tL8s34rIz3ZnK+clYpnh1KVaPjUcen y61A== 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=1677204333; x=1677290733; bh=dGUQpzCg8TTG1 lYtYf7iL4BAdJ4WD0zj1nWU7lBFehI=; b=tlrYsgjf2NEexXJNEgQqJIdogRgDF QSDvk8wSkDAxb5zd03cwRhmJBco1Ew5xfN8dgja/65rl72tCIa8Dc9kgMfUDBPaH ovpHitijhDWrK13m7MjOwX1R8znJQvhftvduRBC5EaOZiQZVyynU3RQ68qBDVVeJ yYzs84QRiJfDcsB1iiGDZI2moddsPgSnU5/nuLJ+qlmG4ffAEY8EmKeep8vShh6v hhhVnbjjjTrLgxcOucYKBkf0Ev9ezO6EwbqDtHqRuyiTIryk+cEjPRmAAWiRDs05 Q9Xoj1YW5wufKV4DBQLZg0bbV/uxQQxjd0T6OlFSnEVUfQjS7cYESVTCw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekvddgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: michael.roth@amd.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org, dxu@dxuuu.xyz Subject: [PATCH 2/3] qga: Add optional `merge-output` flag to guest-exec qapi Date: Thu, 23 Feb 2023 19:05:14 -0700 Message-Id: <6ed3091be8bc0ae8d3fee767b6e7400a8e32c493.1677197937.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.27; envelope-from=dxu@dxuuu.xyz; helo=out3-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_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 23 Feb 2023 23:30:45 -0500 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: 1677213078543100012 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 | 13 ++++++++++++- qga/qapi-schema.json | 6 +++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/qga/commands.c b/qga/commands.c index 360077364e..14b970e768 100644 --- a/qga/commands.c +++ b/qga/commands.c @@ -274,6 +274,15 @@ static void guest_exec_child_watch(GPid pid, gint stat= us, gpointer data) /** Reset ignored signals back to default. */ static void guest_exec_task_setup(gpointer data) { + bool has_merge =3D *(bool *)data; + + if (has_merge) { + if (dup2(STDOUT_FILENO, STDERR_FILENO) !=3D 0) { + slog("dup2() failed to merge stderr into stdout: %s", + strerror(errno)); + } + } + #if !defined(G_OS_WIN32) struct sigaction sigact; =20 @@ -385,6 +394,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; @@ -398,6 +408,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 @@ -421,7 +432,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..4192fcc5a4 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. +# defaults to false. # # 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 Wed May 15 03:52:49 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 1677213076510723.1375069647788; Thu, 23 Feb 2023 20:31:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVPjJ-000787-3i; Thu, 23 Feb 2023 23:30:45 -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 1pVM3E-00067l-9c for qemu-devel@nongnu.org; Thu, 23 Feb 2023 19:35:04 -0500 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pVM3B-0003mh-Qy for qemu-devel@nongnu.org; Thu, 23 Feb 2023 19:35:03 -0500 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 57E345C005E; Thu, 23 Feb 2023 19:35:01 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Thu, 23 Feb 2023 19:35:01 -0500 Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 23 Feb 2023 19:35:00 -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=1677198901; x=1677285301; bh=ep ENDiq/A2ouFrRvdVIfHeqR+yIzIpI+H0pVokqpzuc=; b=ToI/hpX2kFiHywxuRK xwSUxdj3hlFfCqkZcjHa2Ue+x9ywdZ/prdvCM9z9yabdijOW7BLHvLmzkLmUPjAh pgCtf3AxmU6MQ5WFPFxhtfo4lPg8US0crcTdrCqLIhsMIvM/m/kJGdGOvbGYW9k5 reSgQT2GgszWMPTuOxYBEvXpjLweFepaWMiLeJMbxGDUIHXDcsfwzCcxJBRP1jK9 HncSkRZN0IsCTxuGpwA8gQVfj3z3rGfP1KA7NUSgSzr3w71nux9+3WU2hwAjX/Oh aUYD+MlPfLsx9J0DSONxuBuzijvM/UI4BDpedc/JXQZxrrnm3++1aEopCtXGOBj1 nV/Q== 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=1677198901; x=1677285301; bh=epENDiq/A2ouF rRvdVIfHeqR+yIzIpI+H0pVokqpzuc=; b=n999HVFI/qIj6uZBOxt2n/nBfQes/ TqowZNN3rPZoAHJ8Vtyl8SFsAiRWhvpklKtqQ77VywvNJWzvLMXrOCWbf2qarvOE 3+mM5fvWwU2N4vZE6yGLEc45DNtuZ125Gi4kr+Li+/Mp7WcHyOppIPokynsqJ7Ic Q59WUvoqKjQ0ZJxQFcs1YExxbvLsJNl/0yt6Nt6aEX6RuzyrNBM6L6WMsFvSmEbX msNyIMeC2cJf4GJ7lKvRks51cOF0GzQSSmylxdOeJUdKVgW2M6KuxJevIIa6rRBj XIkGWYuhqOUEFSg6NxPgM7eyXPgz/XnOdxUdRhMXH7wD3HN+wqner2B+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekvddgvdduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffucdljedtmdenucfjughrpefhvf evufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpeffrghnihgvlhcuighuuceo ugiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvghrnhepgfefgfegjefhudeike dvueetffelieefuedvhfehjeeljeejkefgffeghfdttdetnecuvehluhhsthgvrhfuihii vgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguhesugiguhhuuhdrgiihii X-ME-Proxy: Feedback-ID: i6a694271:Fastmail From: Daniel Xu To: michael.roth@amd.com, kkostiuk@redhat.com Cc: qemu-devel@nongnu.org Subject: [PATCH 3/3] qga: test: Add tests for `merge-output` flag Date: Thu, 23 Feb 2023 17:34:35 -0700 Message-Id: <2d68032724822784750df4edc4df0c578c878871.1677197937.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.29; envelope-from=dxu@dxuuu.xyz; helo=out5-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, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 23 Feb 2023 23:30:40 -0500 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: 1677213078532100010 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 | 128 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 111 insertions(+), 17 deletions(-) diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c index 9d8e1d1cd3..0b3966024c 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,21 +801,7 @@ 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 */ exitcode =3D qdict_get_int(val, "exitcode"); @@ -802,6 +812,86 @@ 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); + + 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) +{ + 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); + + 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); +} + static void test_qga_guest_exec_invalid(gconstpointer fix) { const TestFixture *fixture =3D fix; @@ -975,6 +1065,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