From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 E548A3858D29 for ; Mon, 22 Mar 2021 19:18:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E548A3858D29 Received: by mail-qt1-x82f.google.com with SMTP id f12so13231000qtq.4 for ; Mon, 22 Mar 2021 12:18:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=XIt0eO1NPUds8ueKJef8aZ1VBDSeUuE9xQBZSTMXyok=; b=M/yixZQbCr8UsXooDgw5sOJj5OiNFAWPpg+qdEX4ErG4YdE4Ob9DNIu+5SwTAnYxW7 uYU29MNNGn9yq2EsM4WfNF8P7MzWiTlVCvBjuTIEzwNCHU88kJQLID46eucIa9gEduIZ R6OJiGvjyCah98NUugqFxulpe5fay2NQmTfgfrga+IbjpLg4smKMzKIaj148HhLbSuQj gwKtWJA2hY+Qibf1BJLcDrJTClGfGtLxTGEr4miCZYyEtwTbPfa9EMV/KUMupvpRgOFi XpO7OSonmmGXoWpP7lWlfKkwQGQyAOm7KHifTFZTtK8VNcGX525TH+LLTXkTg+vzuxcU Hamg== X-Gm-Message-State: AOAM533SdO8uSi/6FTsJdIpqQ7OZcaiwPFl8WYzj63cfZFaytEhSs8cU Y6Lxsy12vO9UcfSXHCdzuhuouFwZYH2okQ== X-Google-Smtp-Source: ABdhPJzIVUyL17DzgWFuUeQVUhoFGrAP2xQrzD8Klnng31u+DN/dE3tUjaSoYmk6g3YCNYqmQiWOMQ== X-Received: by 2002:ac8:5313:: with SMTP id t19mr1361788qtn.148.1616440690113; Mon, 22 Mar 2021 12:18:10 -0700 (PDT) Received: from ?IPv6:2804:18:844:62ae:d820:43e4:85c0:4786? ([2804:18:844:62ae:d820:43e4:85c0:4786]) by smtp.gmail.com with ESMTPSA id a187sm5460950qkd.69.2021.03.22.12.18.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Mar 2021 12:18:09 -0700 (PDT) Subject: Re: [PATCH] tst: Add test for sigtimedwait To: Lukasz Majewski Cc: GNU C Library References: <20210315114239.9070-1-lukma@denx.de> From: Adhemerval Zanella Message-ID: <24e8a41d-e347-2a9a-9966-b5c74b58b5cc@linaro.org> Date: Mon, 22 Mar 2021 16:18:05 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210315114239.9070-1-lukma@denx.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, 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: Mon, 22 Mar 2021 19:18:12 -0000 On 15/03/2021 08:42, Lukasz Majewski wrote: > This change adds new test to assess sigtimedwait's timeout related > functionality - the sigset_t is configured for SIGUSR1, which will > not be triggered, so sigtimedwait just waits for timeout. > > To be more specific - two use cases are checked: > - if sigtimedwait times out immediately when passed struct timespec has > zero values of tv_nsec and tv_sec. > - if sigtimedwait times out after timeout specified in passed argument LGTM with the small nit below. Reviewed-by: Adhemerval Zanella > --- > sysdeps/unix/sysv/linux/Makefile | 5 +- > sysdeps/unix/sysv/linux/tst-sigtimedwait.c | 61 ++++++++++++++++++++++ > 2 files changed, 64 insertions(+), 2 deletions(-) > create mode 100644 sysdeps/unix/sysv/linux/tst-sigtimedwait.c > > diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile > index 41798feb35..a3eba0db01 100644 > --- a/sysdeps/unix/sysv/linux/Makefile > +++ b/sysdeps/unix/sysv/linux/Makefile > @@ -113,8 +113,9 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \ > tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux tst-sysvshm-linux \ > tst-timerfd tst-ppoll tst-futimens tst-utime tst-utimes \ > tst-clock_adjtime tst-adjtimex tst-ntp_adjtime tst-futimes \ > - tst-lutimes tst-ntp_gettime tst-ntp_gettimex tst-getrusage > - > + tst-lutimes tst-ntp_gettime tst-ntp_gettimex tst-getrusage \ > + tst-sigtimedwait > + > # Test for the symbol version of fcntl that was replaced in glibc 2.28. > ifeq ($(have-GLIBC_2.27)$(build-shared),yesyes) > tests += tst-ofdlocks-compat Ok. > diff --git a/sysdeps/unix/sysv/linux/tst-sigtimedwait.c b/sysdeps/unix/sysv/linux/tst-sigtimedwait.c > new file mode 100644 > index 0000000000..95a1b59592 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-sigtimedwait.c > @@ -0,0 +1,61 @@ > +/* Test for sigtimedwait timeout > + Copyright (C) 2021 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +static int test_sigtimedwait_timeout (bool zero_tmo) Put the function name on the next line. > +{ > + /* We wait for half a second. */ > + struct timespec ts; > + xclock_gettime (CLOCK_REALTIME, &ts); > + struct timespec timeout = make_timespec (0, zero_tmo ? 0 : TIMESPEC_HZ/2); > + ts = timespec_add (ts, timeout); > + > + /* Set sigset to just wait for timeout. */ > + sigset_t ss_usr1; > + sigemptyset (&ss_usr1); > + sigaddset (&ss_usr1, SIGUSR1); > + > + int ret = sigtimedwait (&ss_usr1, NULL, &timeout); > + if (ret != -1) > + FAIL_EXIT1 ("sigtimedwait failed: %m\n"); > + > + TEST_TIMESPEC_NOW_OR_AFTER (CLOCK_REALTIME, ts); > + > + return 0; > +} > + Ok. > +static int > +do_test (void) > +{ > + /* Check if sigtimedwait exits immediately. */ > + test_sigtimedwait_timeout (true); > + > + /* Check if sigtimedwait exits after specified timeout. */ > + test_sigtimedwait_timeout (false); > + > + return 0; > +} > + > +#include > Ok.