From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from bongo.cedar.relay.mailchannels.net (bongo.cedar.relay.mailchannels.net [23.83.210.21]) by sourceware.org (Postfix) with ESMTPS id BA9443858C27 for ; Thu, 15 Apr 2021 05:59:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BA9443858C27 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gotplt.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=siddhesh@gotplt.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 34C41780B9A; Thu, 15 Apr 2021 05:59:25 +0000 (UTC) Received: from pdx1-sub0-mail-a91.g.dreamhost.com (100-98-55-74.trex.outbound.svc.cluster.local [100.98.55.74]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id 9CB487809DB; Thu, 15 Apr 2021 05:59:24 +0000 (UTC) X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from pdx1-sub0-mail-a91.g.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384) by 100.98.55.74 (trex/6.1.1); Thu, 15 Apr 2021 05:59:25 +0000 X-MC-Relay: Good X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Decisive-Continue: 24cfdcdc674f5936_1618466364938_845783838 X-MC-Loop-Signature: 1618466364938:211844919 X-MC-Ingress-Time: 1618466364938 Received: from pdx1-sub0-mail-a91.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a91.g.dreamhost.com (Postfix) with ESMTP id 5779A7E3B9; Wed, 14 Apr 2021 22:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gotplt.org; h=subject:to :references:from:message-id:date:mime-version:in-reply-to :content-type:content-transfer-encoding; s=gotplt.org; bh=ZGphU2 kmA1WDuJp1QGV/T1vHCCA=; b=H1LfPtocxu0uPMBrUhvi4/kJ+ii44/wB+793ZZ M282XVGZoL4b/RkkA2QoTmfXpn6OL7Vj6syPjXqbqsIRG2zR4icPs8ulgPquNVK0 uS7ug9meaM/xGRthkUc0TjlYFOj6ZWad8lwSx3tkmmjqMXeEbzakpEHL4XPZhSCV p/mhE= Received: from [192.168.1.111] (unknown [1.186.101.110]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a91.g.dreamhost.com (Postfix) with ESMTPSA id 46FEB7E3B3; Wed, 14 Apr 2021 22:59:20 -0700 (PDT) Subject: Re: [PATCH 06/15] time: Add getitimer and setitimer basic tests To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20210323134458.2563022-1-adhemerval.zanella@linaro.org> <20210323134458.2563022-7-adhemerval.zanella@linaro.org> X-DH-BACKEND: pdx1-sub0-mail-a91 From: Siddhesh Poyarekar Message-ID: <96c28faa-8911-fc05-54a1-f07b2bbf5031@gotplt.org> Date: Thu, 15 Apr 2021 11:29:15 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <20210323134458.2563022-7-adhemerval.zanella@linaro.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3037.6 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_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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, 15 Apr 2021 05:59:30 -0000 On 3/23/21 7:14 PM, Adhemerval Zanella via Libc-alpha wrote: > Checked on i686-linux-gnu and x86_64-linux-gnu. > --- LGTM with a small nit fixed below. Reviewed-by: Siddhesh Poyarekar > time/Makefile | 2 +- > time/tst-itimer.c | 175 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 176 insertions(+), 1 deletion(-) > create mode 100644 time/tst-itimer.c > > diff --git a/time/Makefile b/time/Makefile > index 99b5d42666..91cb02a003 100644 > --- a/time/Makefile > +++ b/time/Makefile > @@ -49,7 +49,7 @@ tests := test_time clocktest tst-posixtz tst-strptime tst_wcsftime \ > tst-tzname tst-y2039 bug-mktime4 tst-strftime2 tst-strftime3 \ > tst-clock tst-clock2 tst-clock_nanosleep tst-cpuclock1 \ > tst-adjtime tst-ctime tst-difftime tst-mktime4 tst-clock_settime \ > - tst-settimeofday > + tst-settimeofday tst-itimer > > include ../Rules > > diff --git a/time/tst-itimer.c b/time/tst-itimer.c > new file mode 100644 > index 0000000000..e464d6b092 > --- /dev/null > +++ b/time/tst-itimer.c > @@ -0,0 +1,175 @@ > +/* Basic tests for getitimer and setitimer. > + 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 > +#include > + > +static sig_atomic_t cnt; > + > +static void > +alrm_handler (int sig) > +{ > + if (++cnt > 3) > + cnt = 3; > +} > + > +static void > +intr_sleep (int sec) > +{ > + struct timespec ts = { .tv_sec = sec, .tv_nsec = 0 }; > + while (nanosleep (&ts, &ts) == -1 && errno == EINTR) > + ; > +} > + > +static int > +do_test (void) > +{ > + struct itimerval it, it_old; > + const int timers[] = { ITIMER_REAL, ITIMER_VIRTUAL, ITIMER_PROF }; > + for (int i = 0; i < array_length (timers); i++) > + { > + TEST_COMPARE (getitimer (timers[i], &it), 0); > + > + /* No timer set, all value should be 0. */ > + TEST_COMPARE (it.it_interval.tv_sec, 0); > + TEST_COMPARE (it.it_interval.tv_usec, 0); > + TEST_COMPARE (it.it_value.tv_sec, 0); > + TEST_COMPARE (it.it_value.tv_usec, 0); > + > + it.it_interval.tv_sec = 10; > + it.it_interval.tv_usec = 20; > + TEST_COMPARE (setitimer (timers[i], &it, NULL), 0); > + > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old), > + 0); > + /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while s/single-sort/single-shot/ > + other timers returns setitimer value. */ > + if (timers[i] == ITIMER_REAL) > + { > + TEST_COMPARE (it_old.it_interval.tv_sec, 0); > + TEST_COMPARE (it_old.it_interval.tv_usec, 0); > + } > + else > + { > + TEST_COMPARE (it_old.it_interval.tv_sec, 10); > + TEST_COMPARE (it_old.it_interval.tv_usec, 20); > + } > + > + /* Create a periodic timer and check if the return value is the one > + previously set. */ > + it.it_interval.tv_sec = 10; > + it.it_interval.tv_usec = 20; > + it.it_value.tv_sec = 30; > + it.it_value.tv_usec = 40; > + TEST_COMPARE (setitimer (timers[i], &it, NULL), 0); > + > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, &it_old), > + 0); > + TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec); > + TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec); > + > + if (sizeof (time_t) == 4) > + continue; > + > + /* Same as before, but with a 64 bit time_t value. */ > + it.it_interval.tv_sec = (time_t) 0x1ffffffffull; > + it.it_interval.tv_usec = 20; > + it.it_value.tv_sec = 0; > + it.it_value.tv_usec = 0; > + > + /* Linux does not provide 64 bit time_t support for getitimer and > + setitimer on architectures with 32 bit time_t support. */ > + if (sizeof (__time_t) == 8) > + { > + TEST_COMPARE (setitimer (timers[i], &it, NULL), 0); > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, > + &it_old), > + 0); > + /* ITIMER_REAL returns { 0, 0 } for single-sort timers, while other > + timers returns setitimer value. */ > + if (timers[i] == ITIMER_REAL) > + { > + TEST_COMPARE (it_old.it_interval.tv_sec, 0ull); > + TEST_COMPARE (it_old.it_interval.tv_usec, 0); > + } > + else > + { > + TEST_COMPARE (it_old.it_interval.tv_sec, 0x1ffffffffull); > + TEST_COMPARE (it_old.it_interval.tv_usec, 20); > + } > + } > + else > + { > + TEST_COMPARE (setitimer (timers[i], &it, NULL), -1); > + TEST_COMPARE (errno, EOVERFLOW); > + } > + > + /* Create a periodic timer and check if the return value is the one > + previously set. */ > + it.it_interval.tv_sec = (time_t) 0x1ffffffffull; > + it.it_interval.tv_usec = 20; > + it.it_value.tv_sec = 30; > + it.it_value.tv_usec = 40; > + if (sizeof (__time_t) == 8) > + { > + TEST_COMPARE (setitimer (timers[i], &it, NULL), 0); > + > + TEST_COMPARE (setitimer (timers[i], &(struct itimerval) { 0 }, > + &it_old), > + 0); > + TEST_COMPARE (it.it_interval.tv_sec, it_old.it_interval.tv_sec); > + TEST_COMPARE (it.it_interval.tv_usec, it_old.it_interval.tv_usec); > + } > + else > + { > + TEST_COMPARE (setitimer (timers[i], &it, NULL), -1); > + TEST_COMPARE (errno, EOVERFLOW); > + } > + } > + > + { > + struct sigaction sa = { .sa_handler = alrm_handler, .sa_flags = 0 }; > + sigemptyset (&sa.sa_mask); > + xsigaction (SIGALRM, &sa, NULL); > + } > + > + /* Setup a timer to 0.1s and sleep for 1s and check to 3 signal handler > + execution. */ > + it.it_interval.tv_sec = 0; > + it.it_interval.tv_usec = 100000; > + it.it_value.tv_sec = 0; > + it.it_value.tv_usec = 100000; > + > + /* Check ITIMER_VIRTUAL and ITIMER_PROF would require to generate load > + and be subject to system load. */ > + cnt = 0; > + TEST_COMPARE (setitimer (ITIMER_REAL, &it, NULL), 0); > + intr_sleep (1); > + TEST_COMPARE (cnt, 3); > + TEST_COMPARE (setitimer (ITIMER_REAL, &(struct itimerval) { 0 }, NULL), 0); > + > + return 0; > +} > + > +#include >