From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) by sourceware.org (Postfix) with ESMTPS id 6F5AB388A400 for ; Tue, 13 Apr 2021 08:30:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6F5AB388A400 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lukma@denx.de Received: from jawa (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id 900BB804B3; Tue, 13 Apr 2021 10:30:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1618302656; bh=OYo7J0H7JBQbsqLNAp7PR9x04suOlJBqUtzq3wkgj/I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=IoYRqY6bDNT2TPQ1OmO7ur7fx0lbfW6/HpbgNdw/iuYsRU5xhzQUQg4swSNM/JMwE zNJkhiCqBGKmYWk15gODhNnMYPMxqReXuRJf7ak+Gbd9ZmcpRclcxIo4s9S6dx5Hnc 4auyFQ+5O93zLgszYFsgi5mQ5kKlKWVqet2PPqZjhP1ulE0h+nkeimWWSdVhpDVbFA R21yazsgQCEz80N6oWRxMhcOgJjpGBUw8bMC6uq2gaQ+85gwpwql2aw6rHRdKIspC1 Z1dl1Nh9BAmco68oaSqPvUAVpOqi1rjuVsujxpcfJyLQYLLfExu4efyw1eOpt5rqQk SwDOp9gBE/L2g== Date: Tue, 13 Apr 2021 10:30:55 +0200 From: Lukasz Majewski To: Joseph Myers , Adhemerval Zanella Cc: Florian Weimer , GNU C Library Subject: Re: [PATCH v2] tst: Provide test for getrusage Message-ID: <20210413103055.5ec6e118@jawa> In-Reply-To: <20210331145105.2c9a0c5e@jawa> References: <20210323143509.11810-1-lukma@denx.de> <20210331145105.2c9a0c5e@jawa> 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_/Ex9REiN7ThRoqCDTNU8Xv7V"; protocol="application/pgp-signature" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, 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: Tue, 13 Apr 2021 08:31:00 -0000 --Sig_/Ex9REiN7ThRoqCDTNU8Xv7V Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Dear Community, > Dear Community, >=20 > > This commit adds test to check if getrusage works correctly. As the > > first check - if the wrong 'who' parameter causes errno set to > > EINVAL. > >=20 > > Next for the ru_{us}time.tv_usec fields it is checked if they are in > > microseconds range. > >=20 > > The last check is to perform busy wait loop for 10ms and afterwards > > assess if ru_{us}time.tv_sec are not smaller than values read on the > > test start. > >=20 > > Changes for v2: > > - Add check for EINVAL return value > > - Check if getrusage ru_{su}time.tv_usec are in correct microseconds > > range > > - Busy wait for 10ms and then compare getrusage system and user > > times (in seconds) if they are equal or larger than previous ones =20 >=20 > Gentle ping on this patch. Are there any more comments? Are there any more comments regarding this patch? >=20 > > --- > > resource/Makefile | 2 +- > > resource/tst-getrusage.c | 67 > > ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 > > insertions(+), 1 deletion(-) create mode 100644 > > resource/tst-getrusage.c > >=20 > > diff --git a/resource/Makefile b/resource/Makefile > > index bd9e716749..e236df3d7c 100644 > > --- a/resource/Makefile > > +++ b/resource/Makefile > > @@ -25,6 +25,6 @@ headers :=3D sys/resource.h bits/resource.h > > sys/vlimit.h \ routines :=3D getrlimit setrlimit getrlimit64 > > setrlimit64 getrusage ulimit \ vlimit vtimes getpriority > > setpriority nice=20 > > -tests =3D tst-getrlimit bug-ulimit1 > > +tests =3D tst-getrlimit bug-ulimit1 tst-getrusage > > =20 > > include ../Rules > > diff --git a/resource/tst-getrusage.c b/resource/tst-getrusage.c > > new file mode 100644 > > index 0000000000..da721b0613 > > --- /dev/null > > +++ b/resource/tst-getrusage.c > > @@ -0,0 +1,67 @@ > > +/* Test for getrusage. > > + 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 > > + > > +static int > > +do_test (void) > > +{ > > + struct timespec tv_then, tv_now, r; > > + struct rusage ru, ru_then; > > + int ret; > > + > > + /* Check for invalid 'who' parameter. */ > > + ret =3D getrusage (-100, &ru); > > + if (! (ret =3D=3D -1 && errno =3D=3D EINVAL)) > > + FAIL_EXIT1 ("getrusage failed - EINVAL expected\n"); > > + > > + /* Check if ru_stime.tv_usec and ru_utime.tv_usec are correct. > > */ > > + ret =3D getrusage (RUSAGE_SELF, &ru_then); > > + if (ret =3D=3D -1) > > + FAIL_EXIT1 ("getrusage failed: %m\n"); > > + > > + TEST_VERIFY (ru_then.ru_utime.tv_usec >=3D 0); > > + TEST_VERIFY (ru_then.ru_utime.tv_usec < 1000000); > > + > > + TEST_VERIFY (ru_then.ru_stime.tv_usec >=3D 0); > > + TEST_VERIFY (ru_then.ru_stime.tv_usec < 1000000); > > + > > + tv_then =3D xclock_now (CLOCK_REALTIME); > > + /* Busy wait for 10 miliseconds. */ > > + do > > + { > > + tv_now =3D xclock_now (CLOCK_REALTIME); > > + r =3D timespec_sub (tv_now, tv_then); > > + } > > + while (r.tv_nsec <=3D 10000000); > > + > > + ret =3D getrusage (RUSAGE_SELF, &ru); > > + if (ret =3D=3D -1) > > + FAIL_EXIT1 ("getrusage failed: %m\n"); > > + > > + TEST_VERIFY (ru.ru_utime.tv_sec >=3D ru_then.ru_utime.tv_sec); > > + TEST_VERIFY (ru.ru_stime.tv_sec >=3D ru_then.ru_stime.tv_sec); > > + > > + return 0; > > +} > > + > > +#include =20 >=20 >=20 >=20 >=20 > Best regards, >=20 > Lukasz Majewski >=20 > -- >=20 > 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 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_/Ex9REiN7ThRoqCDTNU8Xv7V Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmB1Vr8ACgkQAR8vZIA0 zr07gQgAtVgb5rmAJJWesSPweyGemiXUvGgIO8/ZuJ2yhLVaFap8vChKm0msiBeW iF+c4fO54EOCH0zT/R55IizfsvV7JXGu+iG9INxhutX+3z7Kh3G70Y5TXsd9Iz2a s18Fkt4q7ovkJgjWrj0Kcuti9xRGWeu3d9pwKCEnerJMNyXkxGZ06x6DZxIM7LmP nTFA0+thwFGBXfLZy70IfQiAQC9ahpbfKWtprfGjFZ8ppJA3jwcV0vxqJ2Ukx3fI zZGxg65OaFjaOUsDYwB9wMpJCWX7AcFobDPjocxmY86+ohU2HMJ/Av7vjt3WL0kp cYgblfxXnnNR3nm3rsPG9pXdBJWrIA== =H3r6 -----END PGP SIGNATURE----- --Sig_/Ex9REiN7ThRoqCDTNU8Xv7V--