From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-out.m-online.net (mail-out.m-online.net [212.18.0.9]) by sourceware.org (Postfix) with ESMTPS id 399C43846078 for ; Thu, 4 Feb 2021 16:39:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 399C43846078 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=none smtp.mailfrom=lukma@denx.de Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4DWklx1bsKz1qtxT; Thu, 4 Feb 2021 17:39:25 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4DWklx0Ck5z1t6pl; Thu, 4 Feb 2021 17:39:25 +0100 (CET) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.182]) by localhost (dynscan1.mail.m-online.net [192.168.6.70]) (amavisd-new, port 10024) with ESMTP id c7D_CNBaMMQC; Thu, 4 Feb 2021 17:39:22 +0100 (CET) X-Auth-Info: hcgjtX8c8QQlCdGtKmaWRxmIlWIhvWfxuggU6EvAYeI= Received: from jawa (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.mnet-online.de (Postfix) with ESMTPSA; Thu, 4 Feb 2021 17:39:22 +0100 (CET) Date: Thu, 4 Feb 2021 17:39:16 +0100 From: Lukasz Majewski To: Adhemerval Zanella Cc: Joseph Myers , Paul Eggert , Alistair Francis , Arnd Bergmann , Alistair Francis , GNU C Library , Florian Weimer , Carlos O'Donell , Florian Weimer , Zack Weinberg Subject: Re: [PATCH v3] tst: Provide test for timerfd related functions Message-ID: <20210204173916.694f0559@jawa> In-Reply-To: References: <20210114154027.3240-1-lukma@denx.de> Organization: denx.de X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/+AVGA7EME+zp2wW17W4HQ+X"; protocol="application/pgp-signature" X-Spam-Status: No, score=-15.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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, 04 Feb 2021 16:39:29 -0000 --Sig_/+AVGA7EME+zp2wW17W4HQ+X Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Hi Adhemerval, > On 14/01/2021 12:40, Lukasz Majewski wrote: > > This change adds new test to assess functionality of timerfd_* > > functions. > > It creates new timer (operates on its file descriptor) and checks > > if time before and after sleep is between expected values. > >=20 > > --- > > Changes for v2: > > - Provide extra space before opening '(' in function calls and > > definitions > > - Use the xclose instead of close > > - Remove the abs(diff) call > > - Refactor the code to replace tabs with spaces > >=20 > > Changes for v3: > > - Use FAIL_EXIT where possible > > - Remove not needed {} =20 >=20 > Ok with the fixed below. >=20 > > --- > > sysdeps/unix/sysv/linux/Makefile | 3 +- > > sysdeps/unix/sysv/linux/tst-timerfd.c | 82 > > +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 > > deletion(-) create mode 100644 sysdeps/unix/sysv/linux/tst-timerfd.c > >=20 > > diff --git a/sysdeps/unix/sysv/linux/Makefile > > b/sysdeps/unix/sysv/linux/Makefile index 6df4779126..7503b356c8 > > 100644 --- a/sysdeps/unix/sysv/linux/Makefile > > +++ b/sysdeps/unix/sysv/linux/Makefile > > @@ -107,7 +107,8 @@ tests +=3D tst-clone tst-clone2 tst-clone3 > > tst-fanotify tst-personality \ tst-quota tst-sync_file_range > > tst-sysconf-iov_max tst-ttyname \ test-errno-linux tst-memfd_create > > tst-mlock2 tst-pkey \ tst-rlimit-infinity tst-ofdlocks tst-gettid > > tst-gettid-kill \ > > - tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux > > tst-sysvshm-linux > > + tst-tgkill tst-sysvsem-linux tst-sysvmsg-linux > > tst-sysvshm-linux \ > > + tst-timerfd > > tests-internal +=3D tst-ofdlocks-compat tst-sigcontext-get_pc > > =20 > > CFLAGS-tst-sigcontext-get_pc.c =3D -fasynchronous-unwind-tables =20 >=20 > Ok. >=20 > > diff --git a/sysdeps/unix/sysv/linux/tst-timerfd.c > > b/sysdeps/unix/sysv/linux/tst-timerfd.c new file mode 100644 > > index 0000000000..130650fca2 > > --- /dev/null > > +++ b/sysdeps/unix/sysv/linux/tst-timerfd.c > > @@ -0,0 +1,82 @@ > > +/* Test for timerfd related functions > > + 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 int > > +do_test (void) > > +{ > > + struct itimerspec settings =3D { { 2, 0 }, { 2, 0 } }; > > + struct itimerspec val1, val2; > > + int fd, ret; > > + > > + fd =3D timerfd_create (CLOCK_REALTIME, 0); > > + if (fd < 0) > > + FAIL_EXIT1 ("*** timerfd_create failed: %m"); > > + > > + /* Set the timer. */ > > + ret =3D timerfd_settime (fd, 0, &settings, NULL); > > + if (ret !=3D 0) > > + { > > + xclose (fd); =20 >=20 > No need to close the file descriptor (the tests will exit anyway). > Same for the following xclose. Ok, removed. >=20 > > + FAIL_EXIT1 ("*** timerfd_settime failed: %m\n"); > > + } > > + > > + /* Read the timer just before sleep. */ > > + ret =3D timerfd_gettime (fd, &val1); > > + if (ret !=3D 0) > > + { > > + xclose (fd); > > + FAIL_EXIT1 ("*** timerfd_gettime failed: %m\n"); > > + }> + > > + /* Sleep for 1 second. */ > > + ret =3D usleep (1000000); > > + if (ret !=3D 0) > > + { > > + xclose (fd); > > + FAIL_EXIT1 ("*** usleep failed: %m\n"); > > + } > > + > > + /* Read the timer just after sleep. */ > > + ret =3D timerfd_gettime (fd, &val2); > > + xclose (fd); > > + if (ret !=3D 0) > > + FAIL_EXIT1 ("*** timerfd_gettime failed: %m\n"); > > + > > + /* Check difference between timerfd_gettime calls. */ > > + long long int diff =3D val2.it_value.tv_sec - val1.it_value.tv_sec; > > + diff *=3D 1000000000; > > + diff +=3D val2.it_value.tv_nsec - val1.it_value.tv_nsec; > > + /* Subtrack time we have been sleeping (1s). */ > > + diff -=3D 1000000000; > > + > > + if (diff > 100000000) > > + FAIL_EXIT1 ("*** The diff between timerfd calls (%lld) is > > wrong!\n", diff); =20 >=20 > We have libsupport timespec helper functions to check for it: >=20 > struct timespec r =3D timespec_sub (val2.it_value, val1.it_value); > TEST_COMPARE (support_timespec_check_in_range ((struct timespec) { > 1, 0 }, r, 1.0, 1.5), 0); >=20 > It assumes that the interval between timefd_gettime will be between > 1s and 1.5s. I think it should be a fair assumption, even for a high > loaded system. Ok. I've fixed it. >=20 > > + > > + return 0; > > +} > > + > > +#include > > =20 Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de --Sig_/+AVGA7EME+zp2wW17W4HQ+X Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmAcIzQACgkQAR8vZIA0 zr3ZLQgAjvZUDcJwbw2kVJRXvg/6AZgxZvshVvOpnUk25UNAzQ+OZmow8rWZHz0U stA6l+odvwsMwC/XrVadwIXhcWSjHP8ZOjk0HlvYu7EQCYdmMWWdc+CCUJwr7pJ7 ZjYKq1xTUrCLXDBYgqUsvXfvw3hVEbef9OdKa6pbWsqKsj0JlOaSZeO7DAXvPc8b SY+OgLq0fRRyi97Vg1o82yBN8/ky3gb17022Xlx5wUGeDGAa89/hE7vDcCMZg+JM X33ey0J9zFEkjga83eTciIVVYy1csaWXNGens4rWouzRBjsVLAMn7Gpi31viykAK 4s3jGtgRBJqsolAB4kfq++Yk37Uunw== =aalC -----END PGP SIGNATURE----- --Sig_/+AVGA7EME+zp2wW17W4HQ+X--