From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id D640E39551E8 for ; Tue, 13 Apr 2021 21:04:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D640E39551E8 Received: by mail-qk1-x733.google.com with SMTP id 18so2515479qkl.3 for ; Tue, 13 Apr 2021 14:04:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=PeTjAwiJTHXdDFvxv96PKnWjGHCiUZ4vevRrddREEJI=; b=Bh8yygwAaV6ydMjQeW2P0nLhqyweOLeUJ6jzptZk0DGKr/QzAcpK3IyjE2RWOTPVCq kiOANp0fF1Nez1meIBKg6JZhXUEqvO8pxXxK/j03ZxAZXdWULYPTrnVzpAY3/uHPzsh8 g90twERkwZRQn1a2pqErcyivkxizk8pSLZzhlTx2kDRVIRK3aFAlR/RoPo3gcUPO6Q+W HrXcKpkYYyl0G98MGLZXqO6pfd+l8fNhZzKxGy7NQG4rxNPQOfIpH5aede6aMzDddtSg Heg73S46ZI++lP/1cbHXF/iXqJiOCRZcVcDkW5Z8Wf4CPSADICzp5pBkRg0rGBUWJihH kl/A== X-Gm-Message-State: AOAM532qKA4wbii47p9/FNZE8bO4BwlFIVzisxcro9/5Tk8kHmjXw67h 6ZrFM2n963oe5t4LOYxWNF7IO/NjOD9J2U8M X-Google-Smtp-Source: ABdhPJy1KZsfB/CXmLCy5b3OSkFy1WzIkzuFPh33x/viQWMvFXOA64Bzil0j26hGWcFfVi0fVlNfvw== X-Received: by 2002:a37:acd:: with SMTP id 196mr35608778qkk.219.1618347851282; Tue, 13 Apr 2021 14:04:11 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id g8sm10003383qtm.29.2021.04.13.14.04.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 14:04:11 -0700 (PDT) From: Adhemerval Zanella To: libc-stable@sourceware.org Subject: [PATCH 2.33 COMMITTED 2/6] misc: Fix tst-select timeout handling (BZ#27648) Date: Tue, 13 Apr 2021 18:04:01 -0300 Message-Id: <20210413210405.913196-2-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20210413210405.913196-1-adhemerval.zanella@linaro.org> References: <20210413210405.913196-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-stable@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-stable mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 13 Apr 2021 21:04:13 -0000 Instead of polling the stderr, create two pipes and fork to check if child timeout as expected similar to tst-pselect.c. Also lower the timeout value. Checked on x86_64-linux-gnu. (cherry picked from commit 1b53b5d970c232b48843c778ac4566ff5b566c3b) --- NEWS | 1 + misc/tst-select.c | 85 ++++++++++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/NEWS b/NEWS index 6f32249818..4bc898e858 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,7 @@ The following bugs are resolved with this release: [27304] pthread_cond_destroy does not pass private flag to futex system calls [27537] test-container: Always copy test-specific support files [27577] elf/ld.so --help doesn't work + [27648] FAIL: misc/tst-select Version 2.33 diff --git a/misc/tst-select.c b/misc/tst-select.c index 7c310256c5..5ad057cd51 100644 --- a/misc/tst-select.c +++ b/misc/tst-select.c @@ -16,54 +16,79 @@ License along with the GNU C Library; if not, see . */ -#include #include -#include -#include +#include #include -#include #include +#include +#include -#define TST_SELECT_TIMEOUT 1 -#define TST_SELECT_FD_ERR 2 +struct child_args +{ + int fds[2][2]; + struct timeval tmo; +}; -static int -test_select_timeout (bool zero_tmo) +static void +do_test_child (void *clousure) { - const int fds = TST_SELECT_FD_ERR; - int timeout = TST_SELECT_TIMEOUT; - struct timeval to = { 0, 0 }; - struct timespec ts; - fd_set rfds; + struct child_args *args = (struct child_args *) clousure; - FD_ZERO (&rfds); - FD_SET (fds, &rfds); + close (args->fds[0][1]); + close (args->fds[1][0]); - if (zero_tmo) - timeout = 0; + fd_set rfds; + FD_ZERO (&rfds); + FD_SET (args->fds[0][0], &rfds); - to.tv_sec = timeout; - ts = xclock_now (CLOCK_REALTIME); - ts = timespec_add (ts, (struct timespec) { timeout, 0 }); + struct timespec ts = xclock_now (CLOCK_REALTIME); + ts = timespec_add (ts, (struct timespec) { args->tmo.tv_sec, 0 }); - /* Wait for timeout. */ - int ret = select (fds + 1, &rfds, NULL, NULL, &to); - if (ret == -1) - FAIL_EXIT1 ("select failed: %m\n"); + int r = select (args->fds[0][0] + 1, &rfds, NULL, NULL, &args->tmo); + TEST_COMPARE (r, 0); TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts); - return 0; + xwrite (args->fds[1][1], "foo", 3); } static int do_test (void) { - /* Check if select exits immediately. */ - test_select_timeout (true); - - /* Check if select exits after specified timeout. */ - test_select_timeout (false); + struct child_args args; + + xpipe (args.fds[0]); + xpipe (args.fds[1]); + + /* The child select should timeout and write on its pipe end. */ + args.tmo = (struct timeval) { .tv_sec = 0, .tv_usec = 250000 }; + { + struct support_capture_subprocess result; + result = support_capture_subprocess (do_test_child, &args); + support_capture_subprocess_check (&result, "tst-select-child", 0, + sc_allow_none); + } + + /* Same as before, but simulating polling. */ + args.tmo = (struct timeval) { .tv_sec = 0, .tv_usec = 0 }; + { + struct support_capture_subprocess result; + result = support_capture_subprocess (do_test_child, &args); + support_capture_subprocess_check (&result, "tst-select-child", 0, + sc_allow_none); + } + + xclose (args.fds[0][0]); + xclose (args.fds[1][1]); + + { + fd_set rfds; + FD_ZERO (&rfds); + FD_SET (args.fds[1][0], &rfds); + + int r = select (args.fds[1][0] + 1, &rfds, NULL, NULL, &args.tmo); + TEST_COMPARE (r, 1); + } return 0; } -- 2.27.0