From patchwork Mon Oct 31 13:10:09 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: 620235 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2819109pvb; Mon, 31 Oct 2022 06:20:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM41R7yE6k7YENrrWtIEX7Ktkt7j3/YT358HFZvKZdU90xEFMk0eaYoWWOm9pYfe1dNauEur X-Received: by 2002:a05:622a:44b:b0:39c:f5bf:694d with SMTP id o11-20020a05622a044b00b0039cf5bf694dmr10429587qtx.531.1667222454152; Mon, 31 Oct 2022 06:20:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667222454; cv=none; d=google.com; s=arc-20160816; b=cvH0gsFhiHyFneOKvzvKuMeh+GTRbxShsDu2TBAckx3NoglWmxLyuSzjf6jGZpOaK3 urrqOJb4Lv/W32RDuMvVCkdzAcK+NZw75cZ4tc5f2cq6W1DRoqDqtoHajrCzMxjTpx4w FWFvyhHQCRv4X0E9tvi0gbJs/SSU4xCAWsfrEUHGsMwdVhulXYrXP/vvM0FC5s/6qAor mkq1UUxWol2kZ9gejCQZtlMCVF2Jsm2RnE8uHaZGY6alhT5XFUzdjWaESM8Kl9LquoOO E7QnRTAbFt7aa+AjVvyhSYhnR91/S+D31GqSoNFqrAarNHDSP7KKH0zH1KiUb6+HtZLv 6xtA== 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=38CIqeK6tAYrMp96yOEjbU4GfBGml0abO/Zm0V1JKyw=; b=A/gjqtbdWlU8k/C60fbpgolbT88saaRbFVgL9uhLEMbNEpOYEM/qCPMkxKPDx9GgVT IjrC2041UXxqpEEVAxqFRXioLMyXHOLnDk1lt+ehNqHe0+575oMq26aRf3vr/yg5tbP/ WF2Pqp9LWIw/oV8hMpz9CO+bw9mp2g52LEwdwP0xSCAujii32C0T+Rm51IXGsDVPWqlo cYfQ1myRnsmzu3ndfjU2iqb3AOfTMLVrYjsbBgrLsbWkwGxyB7ftd3RTTBzf7awkjROp K25ibUEzg6stauXM7CbGKXtgZxIBJ61B864kF5SLz2mXYE1MB0f6gH257a3Pmgl0OYQ7 tn7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=i3yUo005; spf=pass (google.com: domain of qemu-devel-bounces+peter.griffin=linaro.org+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+peter.griffin=linaro.org+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 br14-20020a05620a460e00b006ce4c19d1aasi4007353qkb.35.2022.10.31.06.20.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Oct 2022 06:20:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+peter.griffin=linaro.org+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=i3yUo005; spf=pass (google.com: domain of qemu-devel-bounces+peter.griffin=linaro.org+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+peter.griffin=linaro.org+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 1opUiZ-0005Mj-8g; Mon, 31 Oct 2022 09:20:43 -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 1opUi1-0003JZ-Hx for qemu-devel@nongnu.org; Mon, 31 Oct 2022 09:20:09 -0400 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1opUhr-0005S7-JQ for qemu-devel@nongnu.org; Mon, 31 Oct 2022 09:20:09 -0400 Received: by mail-wr1-x435.google.com with SMTP id k8so15976332wrh.1 for ; Mon, 31 Oct 2022 06:19:58 -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=38CIqeK6tAYrMp96yOEjbU4GfBGml0abO/Zm0V1JKyw=; b=i3yUo005Q9AZdYSkRkt2ilYEugHuZPjzLyaP5L7wRCcGJMGQAdXeOt9Ez63H84afO7 YM6EsEdDMQT+DRLUf6U1ZfLdio1lSup5bsmR07mDrJqQotJkyco+lW74ApGBsKFsG/Sh kko3fRWWK1wn6LdE4aTgupilZiJfQej7MEKbIdCQ4fyR6X4dps2TBFZhQNSo62YSJhfJ GeUdM64cY/5/UrO3/nGzbdZWZ/F58o51wJb/L/zjZMnaDCrBd1c0kmx/MCBMrChnb4E9 LiUfsCPPD97UMm3F632IYAUbLQEKwdmqf9y5J3C1N0/b+rvH5rwHCHaIuD/dFfPmr6PD +dlA== 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=38CIqeK6tAYrMp96yOEjbU4GfBGml0abO/Zm0V1JKyw=; b=GsizgXpPH0HSFi5ZkmUSNnZSrnSSpGaRCz97N/nquCrimtzJrHFkCeLArCrb9FlVAN 3SJghHJm9twLKg5R1p9u/y73Uapz6xDuvAgvjOMQC/ppwFcsicJLGCQB6wLDCfmQoJMD cXliBBrAPaH0DtpSLdyrqbDdxGrNqXUPz10M1VeVjLSrozQ1yM+04v/WZEZKAfVlxZPR 54cmR7rHpE5aOo8DEkNRZZ4SuNMXpkQP+i+ESs4aihzzmCNhTUF0ctbZhO7lr/TXNjTx wO6I7ljJygMirt7W1xerOPv/oEs6RfpcZffAGsbrue6xHq0ssL/lrITcmFXdxIrikIJs WJ4w== X-Gm-Message-State: ACrzQf0rnGq2+3EUWu8bHx40Bv7wg5E5F08e7FBXJISDPLXGfbceqSvB R6y4VK3JqOQz+ZBV1tFdfR2WJg== X-Received: by 2002:a5d:588f:0:b0:231:c661:5cee with SMTP id n15-20020a5d588f000000b00231c6615ceemr8386955wrf.18.1667222397585; Mon, 31 Oct 2022 06:19:57 -0700 (PDT) Received: from zen.linaroharston ([185.81.254.11]) by smtp.gmail.com with ESMTPSA id p11-20020a05600c468b00b003cf75213bb9sm1771353wmo.8.2022.10.31.06.19.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Oct 2022 06:19:54 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id C95731FFD3; Mon, 31 Oct 2022 13:10:13 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Daniel_P_?= =?utf-8?q?=2E_Berrang=C3=A9?= , Thomas Huth , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , Juan Quintela Subject: [PULL 30/31] tests/unit: cleanups for test-io-channel-command Date: Mon, 31 Oct 2022 13:10:09 +0000 Message-Id: <20221031131010.682984-31-alex.bennee@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221031131010.682984-1-alex.bennee@linaro.org> References: <20221031131010.682984-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::435; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x435.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+peter.griffin=linaro.org+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 Reviewed-by: Daniel P. Berrangé Cc: Thomas Huth Cc: Marc-André Lureau Cc: Juan Quintela Message-Id: <20221027183637.2772968-30-alex.bennee@linaro.org> diff --git a/tests/unit/test-io-channel-command.c b/tests/unit/test-io-channel-command.c index 7eee939c07..43e29c8cfb 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); }