From patchwork Thu Oct 27 18:36:35 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: 619202 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp496883pvb; Thu, 27 Oct 2022 11:54:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6mKyONoz/lMcWUYtr/AvIR2MHpNXOIWBa7RzJsX6dmYmxcChqqyF33CBFw2ax/r9VdPZ3V X-Received: by 2002:a05:620a:bc2:b0:6cf:468e:b8ce with SMTP id s2-20020a05620a0bc200b006cf468eb8cemr34694242qki.699.1666896853510; Thu, 27 Oct 2022 11:54:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666896853; cv=none; d=google.com; s=arc-20160816; b=CaaOkQ2EVdnYXJgCkKaDZ7GrWtFrm1ep6E5c0iXXumwhdKEVaVD7vRW+4LUDPB+92R qDinqg7sPepFuxYWd5X4jab0Tmahw359r//8/nNnSUtnzqUk6zZJOQhivRIN9Z7hOUoG OzqrOxFNrCNVq4D0MuDdmKDEMCGRLkZQrYlkkBAezNMp5h9Oq7Hs43BHCf5wdD1srpKS 1JmB+uWGUeuGYVVGgVKDkyZ+pRSwA44Yfi9yppf48uM3uHO8vrwgLZdz1GsyNx+I5ElA w3ouLzYxZIO7qpk8cKJHhQUkUmojjJLxeuV2NJfY3IzQOYVml+rA3CCJNXgfgGZtf5mW stTg== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=sHYyMytvaRwCrcUxnHHFfEwhoSYAHml8PTkMZH1b3Uw=; b=OLbxd6sZlBa14ZOULgHARtHYiq+L3hCzbrXogU//zNar4Dp6kzkvYPIbJBePeyvwqZ Vdl43vbM6WGDaSpF3KNPsjrSFwn5NuuLvuzAxoqiD0z4KlgSmXjrRhOAP9mw6rzhJtfj cgPPXMS+gG+teeJfVy+ioKfvSQINJd1tqklk4n9+INcvhFOxWEslmGF3Sd3xHdMD0v9G G3S86T1PpHJhIB4VYo/7EbPXLrm76ToffVZA02HFBrq1L6IerN7dvJr7fPhJXtPIh/pz 7yk/bRR74mrOfVzGfAiyTq4k6kjtYrRSswnX9FS83lBkHPK4v6qV8ASX/ZPiioc70SXf v0Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i7CMzyk2; 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 ESMTP id y19-20020ac87c93000000b003975b079163si1271940qtv.427.2022.10.27.11.54.13 for ; Thu, 27 Oct 2022 11:54:13 -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=i7CMzyk2; 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 1oo7tF-0005ki-Cj; Thu, 27 Oct 2022 14:46:05 -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 1oo7sC-0005SR-8m for qemu-devel@nongnu.org; Thu, 27 Oct 2022 14:45:03 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oo7s6-0004jT-U0 for qemu-devel@nongnu.org; Thu, 27 Oct 2022 14:44:59 -0400 Received: by mail-wr1-x42d.google.com with SMTP id bs21so3717074wrb.4 for ; Thu, 27 Oct 2022 11:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sHYyMytvaRwCrcUxnHHFfEwhoSYAHml8PTkMZH1b3Uw=; b=i7CMzyk2Q/F/37Y8xk/nuncJNSx1vG9hbjqjaNU7I6xAjqq8xZAyG2rzAF7QhOYz31 fQk5uEXt6kZMwFWxZzFoatSA1PMhpBhN4q95vOLpoK96TtkLalZ9C41xJcEa8FbKz1IA gtrxP9h5VSFTAgOvm8B5sEd4HpKHE+qzqn2xNyAj41f1xNhmDvCvDwzOI8W9FmvXwVUU rkbDGrT8zvmGG+Awx9tSLw/TJcy516G7DqQOZrww0PkoGRPxr+nFwuufE1cQxbt478wn 1WMUyn6hpAHAP/cUC+LJSSAkWs/bkddk0to6SNhYjSAmoA0arjGr/FGQtj8F5taeFRm4 NQKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sHYyMytvaRwCrcUxnHHFfEwhoSYAHml8PTkMZH1b3Uw=; b=KxQEoZPVusoKhHsSCuOBbIBaa+znjSaqZiby3CTHYYYBodKXkxqFX2l0CDLgv7vwkH IMhJte2ivIqpB1/P3kqsIwQOYdsLchvUEXB0p+ADRCUGp3qMQ0sLRqLp73MUxARTFG0k ivtKTSJq9JjePmRDS8jVTzmj5h2fu4hfELwyImy8sYCtYEXjK56R7emMTxj2bhfDe6r3 BpzdHIGf6G7zMqDRgv1PtrHbnljeWVDZeorG6p6jzOtp9Y13QlB0ID9/uUkf3xyJCvZh SE2rmdT520sHUci8QPVSaTpMh3TQo0NxHijwuGuMejwAKPfKgQ9HscbA2vcLX1WsaVdH x5Sw== X-Gm-Message-State: ACrzQf20edvv4w5tk1Wiookdz/i5mx0ArfFpCtNG9NkBZvdlJtS1hVAF ua6zGtn714Gwd4mT4hxfhjIE3Q== X-Received: by 2002:a05:6000:144f:b0:231:2053:ef7c with SMTP id v15-20020a056000144f00b002312053ef7cmr32995992wrx.179.1666896293358; Thu, 27 Oct 2022 11:44:53 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id e8-20020adffd08000000b0022e653f5abbsm1770173wrr.69.2022.10.27.11.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Oct 2022 11:44:51 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 10C031FFBC; Thu, 27 Oct 2022 19:36:40 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: fam@euphon.net, berrange@redhat.com, f4bug@amsat.org, aurelien@aurel32.net, pbonzini@redhat.com, stefanha@redhat.com, crosa@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , Thomas Huth , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Juan Quintela Subject: [PATCH v4 29/30] tests/unit: cleanups for test-io-channel-command Date: Thu, 27 Oct 2022 19:36:35 +0100 Message-Id: <20221027183637.2772968-30-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221027183637.2772968-1-alex.bennee@linaro.org> References: <20221027183637.2772968-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.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 Reviewed-by: Daniel P. Berrangé --- 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); }