From patchwork Thu Oct 27 14:18:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 619196 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp327972pvb; Thu, 27 Oct 2022 07:21:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5CDdmJl4jk2zQNgzWBCpK2QpmtiLWBI60hrpbmGUzLp7FfhLsmmD71v5prH6IE1/hZQ67V X-Received: by 2002:a37:b7c3:0:b0:6f7:65f6:a896 with SMTP id h186-20020a37b7c3000000b006f765f6a896mr10113821qkf.293.1666880490607; Thu, 27 Oct 2022 07:21:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666880490; cv=none; d=google.com; s=arc-20160816; b=a/9xGrvchW52ulyn6vOUu6lV7H0nPRcw2lW0Lk7MWreCXP+WA5nMqLQUCEP2idr+xA YBNxYwrUuYw1UIADKXqW0B3a1fWmbVpL3/LcAqZXkgkBcfxh3uKWP0iC92FN3Du9Z3d+ tunU5ZBhOA2Fm6BBgzteG5obu1iQOUEtGnXoD10HCw2/wpsKTmZNY2NoJEnQa5SH0x0s 8UdPukWCLcP6rvevH4O5wksKeLH0WlOTN+EGkWBkCqsSeJQN8C5AxAVj4BRsBfrUThk3 lV0QiuMzyjvwnUCnS5wBvIjUAXMDemnbSQ8cTr/0vx2WuHEZHIGNq6x/fHvqWC+Yko45 yIFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=sHYyMytvaRwCrcUxnHHFfEwhoSYAHml8PTkMZH1b3Uw=; b=plAjDMFl27aWKDIZli1tQuawDfW2JjZ+i6UGWqYBJhLEws09O1Ts6u04BtlBPB+ViN l+U9aOZqy6jIxzOmVohMFdInaNN+HC6d+/+jPm96BTAFeefnpnNIit+z8AP2WnnYSbc7 fU9OZMc92Ys+t2Y9c0zKY+jirB+18P93G63fbNFgO7KHrDFM4axL9V3zXRMwrhaEsRSQ s2Q5zq2SzxmIDXqegyycfkBVvDMBnnHOprZNKvpj9q8z7069HqbWrSj2HCoUxMPG7uGC lat2tvJnfMNxiZ/LRYhOsBH7ipRqorSN3XNSPmOnhdIrrRSQ17O2l48Gepvq7qKWKuK9 YLxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s0SQQT2W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id fv2-20020a056214240200b004b3f36b1fbbsi1069313qvb.493.2022.10.27.07.21.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 27 Oct 2022 07:21:30 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=s0SQQT2W; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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) 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-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) 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) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , =?utf-8?q?Daniel_P_=2E_Berrang=C3=A9?= , =?utf-8?q?Mar?= =?utf-8?q?c-Andr=C3=A9_Lureau?= , 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 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+patch=linaro.org@nongnu.org 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=0" 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ée Cc: Thomas Huth Cc: Daniel P. Berrangé Cc: Marc-André 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-channel-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 @@ */ #include "qemu/osdep.h" +#include #include "io/channel-command.h" #include "io-channel-helpers.h" #include "qapi/error.h" @@ -26,32 +27,32 @@ #define TEST_FIFO "test-io-channel-command.fifo" -#define SOCAT_SRC "PIPE:" TEST_FIFO ",wronly" -#define SOCAT_DST "PIPE:" TEST_FIFO ",rdonly" - static char *socat = NULL; static void test_io_channel_command_fifo(bool async) { + g_autofree gchar *tmpdir = g_dir_make_tmp("qemu-test-io-channel.XXXXXX", NULL); + g_autofree gchar *fifo = g_strdup_printf("%s/%s", tmpdir, TEST_FIFO); + g_autoptr(GString) srcargs = g_string_new(socat); + g_autoptr(GString) dstargs = g_string_new(socat); + g_auto(GStrv) srcargv; + g_auto(GStrv) dstargv; QIOChannel *src, *dst; QIOChannelTest *test; - const char *srcargv[] = { - socat, "-", SOCAT_SRC, NULL, - }; - const char *dstargv[] = { - socat, SOCAT_DST, "-", NULL, - }; - 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 = g_strsplit(srcargs->str, " ", -1); + dstargv = g_strsplit(dstargs->str, " ", -1); - unlink(TEST_FIFO); - src = QIO_CHANNEL(qio_channel_command_new_spawn(srcargv, + src = QIO_CHANNEL(qio_channel_command_new_spawn((const char**) srcargv, O_WRONLY, &error_abort)); - dst = QIO_CHANNEL(qio_channel_command_new_spawn(dstargv, + /* try to avoid a race to create the socket */ + g_usleep(1000); + + dst = QIO_CHANNEL(qio_channel_command_new_spawn((const char**) dstargv, O_RDONLY, &error_abort)); @@ -62,17 +63,27 @@ static void test_io_channel_command_fifo(bool async) object_unref(OBJECT(src)); object_unref(OBJECT(dst)); - unlink(TEST_FIFO); + g_rmdir(tmpdir); } 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); } 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); }