From patchwork Thu Mar 25 20:00:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 42772 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 11A123858039; Thu, 25 Mar 2021 20:00:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11A123858039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1616702418; bh=ickU5kopD9vNvSpEqat5S6lmxwgU3NwdP6Tyf2HdBfI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BKcP3k57p9QCFX03p9A7kg7pnSA3h364j9761imHXBYXPHMenDfF1vtw+3Fe4m2dK g0zdDfZTFjw3zLKMsorxfVyNdHQXgCXSOvzK2RVJ8kvto1nDr5VbW4NYQOhoTEIW7M SGr8sEBxDAluKzWoFdF4afJ8hrpI5AokA1PLMUXA= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by sourceware.org (Postfix) with ESMTPS id 06DF83858001 for ; Thu, 25 Mar 2021 20:00:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 06DF83858001 Received: by mail-qt1-x82f.google.com with SMTP id i19so2623183qtv.7 for ; Thu, 25 Mar 2021 13:00:13 -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:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ickU5kopD9vNvSpEqat5S6lmxwgU3NwdP6Tyf2HdBfI=; b=RyXzoJ1A6SdPXjCwSSe5dIRs+2NLfhN6FuAWo6tDfxxbNoSwmVONbrfET4kT9xeRj7 BrxBCjIA2Ad9m9k3ouLc8RjcWvwM8fg1rRi88cBY6V3jXGn0yUq6ED2cfyAxlWc7w9OU bmdNri3ZZpBqW1z2Ky5dlizwWeF3bNv0c18h94k1AFXJNWj3TN/SRb6sMfIBQQhFguVY TQe5TFlmtTcbZ3xO06TIdaIkGs9lgKH/r4IDmce64tvEWUDd5a5SKBhbCpCj99ogTvjo KadNeFv5RSAE3oK5ocMrSRl+0urLNro7mSaDZotGhQtk6TmSqCkc34AVZJJK0YyySbM4 z9yw== X-Gm-Message-State: AOAM532yHOnECtfR8ehqP6OXFhkfPW+mucN7CNehyquNz4cvWaGMzPD8 UGyB8zs9VMO8uOJzyn7Yr+APQL9e4B7sRFig X-Google-Smtp-Source: ABdhPJzBA9Sx6r+PPHCogJ96Fp3IA8nwWQaPum5REfRCDT+Sjtx1/c+xS4vozuG4EBJbXFjxv5jWyw== X-Received: by 2002:ac8:4681:: with SMTP id g1mr9565151qto.190.1616702412458; Thu, 25 Mar 2021 13:00:12 -0700 (PDT) Received: from localhost.localdomain ([177.194.41.149]) by smtp.googlemail.com with ESMTPSA id i8sm4217627qtj.16.2021.03.25.13.00.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Mar 2021 13:00:12 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH] misc: Fix tst-select timeout handling (BZ#27648) Date: Thu, 25 Mar 2021 17:00:07 -0300 Message-Id: <20210325200007.3571113-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 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-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Netto Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. --- misc/tst-select.c | 85 ++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/misc/tst-select.c b/misc/tst-select.c index 7c310256c5..530181c264 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 with simulating a 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; }