From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x332.google.com (mail-ot1-x332.google.com [IPv6:2607:f8b0:4864:20::332]) by sourceware.org (Postfix) with ESMTPS id 2CED83858001 for ; Thu, 25 Mar 2021 21:07:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2CED83858001 Received: by mail-ot1-x332.google.com with SMTP id v24-20020a9d69d80000b02901b9aec33371so3333939oto.2 for ; Thu, 25 Mar 2021 14:07:23 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=rdHK87j9dehYGJ2jpjXywL2MKHgCEPctchN3bs1kPE4=; b=mL1TF7aT0HgGZJb0SpHe1g3CSMYXtmgtaHcbesq1tJq2XLTlYMX8JkjYW+FnJ220Zx oqBiiZZuYsQPo9J/DUx9r7V9L3tkpO3mi1074K6MEicPVKUjx7EJ2+CT+HDbxfGjkDEC vAFfzBAbhnrwMzqfGVhASos+ja65vUkPLlmBgAjWjgwUUANnHxCCvtyOIm7/GFufZi1Y E2STHr3rngJSjE8ci1cAP5mgU0buI9WxRvAqfyQLI6bC/Z80Xwl99A6IoKdOUSG/88yR /R7sgjcTdHmxfOP4GzQB9VSXGdN4G7f+ngIJICN208AeLpZo3h/fDaYeV0GdWh9Ccw9N iLXw== X-Gm-Message-State: AOAM532pGOD1up6eVDNAzus96cyb6UiV3avZn/2tnaljkN1b5OpjVUjt Rub/H+lKOxQmEtTQaOM1MkqeHMCHqCTHB4VqNfg= X-Google-Smtp-Source: ABdhPJypk+JDXzQ609hxRyHxheAV06c6dM1BgfL9Lx28d+GKvL2Izxf/AIvjLFWbGGBG+NYeRkOZdUK6LHE2f6xaeD0= X-Received: by 2002:a05:6830:90c:: with SMTP id v12mr9093887ott.179.1616706442526; Thu, 25 Mar 2021 14:07:22 -0700 (PDT) MIME-Version: 1.0 References: <20210325200007.3571113-1-adhemerval.zanella@linaro.org> In-Reply-To: <20210325200007.3571113-1-adhemerval.zanella@linaro.org> From: "H.J. Lu" Date: Thu, 25 Mar 2021 14:06:46 -0700 Message-ID: Subject: Re: [PATCH] misc: Fix tst-select timeout handling (BZ#27648) To: Adhemerval Zanella Cc: GNU C Library Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3036.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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-List-Received-Date: Thu, 25 Mar 2021 21:07:24 -0000 On Thu, Mar 25, 2021 at 1:00 PM Adhemerval Zanella wrote: > > 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; > } > -- > 2.27.0 > LGTM. Thanks. -- H.J.