From nobody Mon May 20 14:38:32 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1666880491; cv=none; d=zohomail.com; s=zohoarc; b=a69IcDDydSyAK7UPsEDH72AQmT4R5Pd4TX5nAcUrt8NyEH9lyrWuVGFrFXC2+7aZatQsBPpD2tQrMn8ZePACWlZyA4yfc/nEC3wO2fJzLAmA0nYpmW0uf/yELwPpuCiFcZfREBJuIJdX/b7NGkpO2Wgj+NpkkQgV93LvUwcXRRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666880491; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=sHYyMytvaRwCrcUxnHHFfEwhoSYAHml8PTkMZH1b3Uw=; b=DlQRG9kAoSBt4UVP/CCK6QlRI0AVGBlNt+NPod9frK/RDBwtDXOAtTcuUPvNjFuoQAaOewqc0iXdnMKIXkUZfIH0idcBtX1EM03p/UyqugvzqEDzv6WwQP3YnmSzGaA6yHIhvhlBPeLfCkQadgYKuEGS5b9bso7D6SPAGl+usec= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1666880490992458.94967812272546; Thu, 27 Oct 2022 07:21:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oo3in-0007P2-UT; Thu, 27 Oct 2022 10:19:01 -0400 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 1oo3iI-00079B-UY for qemu-devel@nongnu.org; Thu, 27 Oct 2022 10:18:33 -0400 Received: from mail-wm1-x335.google.com ([2a00:1450:4864:20::335]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oo3iE-0007rM-F3 for qemu-devel@nongnu.org; Thu, 27 Oct 2022 10:18:30 -0400 Received: by mail-wm1-x335.google.com with SMTP id y10so1150582wma.0 for ; Thu, 27 Oct 2022 07:18:20 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id h7-20020a5d4307000000b002366e3f1497sm1307155wrq.6.2022.10.27.07.18.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 07:18:19 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id AAAAF1FFB7; Thu, 27 Oct 2022 15:18:18 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=sHYyMytvaRwCrcUxnHHFfEwhoSYAHml8PTkMZH1b3Uw=; b=s0SQQT2W7t4NgUVAG2OcZemaN6JCVGChS9WW6wQBcHaT1BBVDIztRC43QT1uOVcOIe YLsTDMcutIanFkR7VyXP5nrdrKtay0JUoFMKpw0K/ARCvnWl7HxtCxKt670prxxboM/1 3YlwA0u+k89TBHjHy13Maeo1F/gt8Xl/5Q8ZvNHhpAr5hkgwSK0tF2HuQYfOOpknhM5t iFGFa2SdroS5WhpFgToH8Rsm0Gz4U9UJqy/homfcxueu5sClQT0jOCCrwbvGZrzlaNnX 7LxKHJfNx2FWZRk/MGGcEqWp9YkEsTaDUYk9hOg6xvxUva0aubrBoX57/vArM+XcMT+H 966A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=sHYyMytvaRwCrcUxnHHFfEwhoSYAHml8PTkMZH1b3Uw=; b=DAdBdF7RHzOx/FLjC6XBavwqyiCyaUhstnpeB9kH3LYVzgVuFBh3EYNEO6WxDkk9zq TtE79nomIGdllaPwmyywwe6y3aTLNRpeTYU5geqBuXnD9lWgh4r/Zjshh6oDeM3H2y/A aaHNCJavFkjpHCj7bzCcuDvZQbxTAX2LCpMFIIdXIabpu2GEctsFKO6T89lWPWGyx12j UWwwDfvb5p9tqiGdan1Gqnz4Fg6sQglIxUKTX4ELdvfKjVeWiiwSh1bdBYXurC27xZkh 3x83iPee1fQOl+wm5mb5pbMUG5VVlvSWZiA/BKCuLV+0U8ORFVKfYt0uUBbP1KRtfOyU AlWw== X-Gm-Message-State: ACrzQf1Bfw25L+/7s2I0ZV28PniyUn5j666eM7LAhs0ywr52PpsGMNcg n3XZ0/8NvsYmph3/HLdz0uILNw== X-Google-Smtp-Source: AMsMyM66n6kOVtqW+J5K5OxgBfIEkxVCq899u0YDUV8Y1ttLpS9DGmkqQefVpGKusWAcMx5zvmKrOQ== X-Received: by 2002:a1c:7215:0:b0:3c7:130c:a77f with SMTP id n21-20020a1c7215000000b003c7130ca77fmr6313784wmc.151.1666880299527; Thu, 27 Oct 2022 07:18:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= , Thomas Huth , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Juan Quintela Subject: [RFC PATCH] tests/unit: cleanups for test-io-channel-command Date: Thu, 27 Oct 2022 15:18:15 +0100 Message-Id: <20221027141815.2571621-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 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=2a00:1450:4864:20::335; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x335.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_NONE=-0.0001, SPF_HELO_NONE=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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1666880491500100001 This test is hanging under heavy load when the two socats race while trying to create the socket. I've tried various approaches to avoid the race but it seems "creat=3D0" won't stop socat trying to create a pipe if it executes first. In the end I just use a small sleep which seems to be reliable enough on the load situations I've tried. While I was there I also properly created a tmpdir for the socket to live in which is cleaned up at the end of the test. Signed-off-by: Alex Benn=C3=A9e Cc: Thomas Huth Cc: Daniel P. Berrang=C3=A9 Cc: Marc-Andr=C3=A9 Lureau Cc: Juan Quintela --- tests/unit/test-io-channel-command.c | 45 +++++++++++++++++----------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/tests/unit/test-io-channel-command.c b/tests/unit/test-io-chan= nel-command.c index 7eee939c07..54bb0f139a 100644 --- a/tests/unit/test-io-channel-command.c +++ b/tests/unit/test-io-channel-command.c @@ -19,6 +19,7 @@ */ =20 #include "qemu/osdep.h" +#include #include "io/channel-command.h" #include "io-channel-helpers.h" #include "qapi/error.h" @@ -26,32 +27,32 @@ =20 #define TEST_FIFO "test-io-channel-command.fifo" =20 -#define SOCAT_SRC "PIPE:" TEST_FIFO ",wronly" -#define SOCAT_DST "PIPE:" TEST_FIFO ",rdonly" - static char *socat =3D NULL; =20 static void test_io_channel_command_fifo(bool async) { + g_autofree gchar *tmpdir =3D g_dir_make_tmp("qemu-test-io-channel.XXXX= XX", NULL); + g_autofree gchar *fifo =3D g_strdup_printf("%s/%s", tmpdir, TEST_FIFO); + g_autoptr(GString) srcargs =3D g_string_new(socat); + g_autoptr(GString) dstargs =3D g_string_new(socat); + g_auto(GStrv) srcargv; + g_auto(GStrv) dstargv; QIOChannel *src, *dst; QIOChannelTest *test; - const char *srcargv[] =3D { - socat, "-", SOCAT_SRC, NULL, - }; - const char *dstargv[] =3D { - socat, SOCAT_DST, "-", NULL, - }; =20 - if (!socat) { - g_test_skip("socat is not found in PATH"); - return; - } + g_string_append_printf(srcargs, " - PIPE:%s,wronly", fifo); + g_string_append_printf(dstargs, " PIPE:%s,rdonly -", fifo); + + srcargv =3D g_strsplit(srcargs->str, " ", -1); + dstargv =3D g_strsplit(dstargs->str, " ", -1); =20 - unlink(TEST_FIFO); - src =3D QIO_CHANNEL(qio_channel_command_new_spawn(srcargv, + src =3D QIO_CHANNEL(qio_channel_command_new_spawn((const char**) srcar= gv, O_WRONLY, &error_abort)); - dst =3D QIO_CHANNEL(qio_channel_command_new_spawn(dstargv, + /* try to avoid a race to create the socket */ + g_usleep(1000); + + dst =3D QIO_CHANNEL(qio_channel_command_new_spawn((const char**) dstar= gv, O_RDONLY, &error_abort)); =20 @@ -62,17 +63,27 @@ static void test_io_channel_command_fifo(bool async) object_unref(OBJECT(src)); object_unref(OBJECT(dst)); =20 - unlink(TEST_FIFO); + g_rmdir(tmpdir); } =20 =20 static void test_io_channel_command_fifo_async(void) { + if (!socat) { + g_test_skip("socat is not found in PATH"); + return; + } + test_io_channel_command_fifo(true); } =20 static void test_io_channel_command_fifo_sync(void) { + if (!socat) { + g_test_skip("socat is not found in PATH"); + return; + } + test_io_channel_command_fifo(false); } =20 --=20 2.34.1