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 3D6693846020 for ; Thu, 6 May 2021 09:12:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3D6693846020 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 C500482A80; Thu, 6 May 2021 11:12:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1620292353; bh=KaXDqROnLoYvY48wcy4dkyLm1CZtsZaCQYg/IvGWDAU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aF5bfTziMniDgPwHqXdbLDDIX1XrI2kuZ2w0fBWizyRI8o+beeGWWQPGybWTgUJ0j Y34/GlzrxqVWZAoNXa0HAystnhE07anTDwxvKB6Sl+BZ7O1Xh088lqwOnjsW6AZDgf bNQZ6ooXJ13szGmczqWbq3mekCRbhskNSGGVmKxVngLk6KphsltN1W1FBpx+L9Scgq IOGFs/kKKZ9zyM46a3VD8IGIFSJs4Kg4SGU+qgq9jTrBAIas2VVhflmxulCNpOySnS 4YU9SLvtk4dhlmbxwmMQUH6NzTdw3UTSvrmB5F7ASJSwdpeUPhtsWIPS3N6PNrwpAB xdASK058nxmlA== Date: Thu, 6 May 2021 11:12:31 +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: <20210506111231.2bf5993f@jawa> In-Reply-To: <20210413103055.5ec6e118@jawa> References: <20210323143509.11810-1-lukma@denx.de> <20210331145105.2c9a0c5e@jawa> <20210413103055.5ec6e118@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_/ay8FfJiHcAAN=8n+dFcohlS"; 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.1 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: Thu, 06 May 2021 09:12:36 -0000 --Sig_/ay8FfJiHcAAN=8n+dFcohlS Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Tue, 13 Apr 2021 10:30:55 +0200 Lukasz Majewski wrote: > Dear Community, >=20 > > 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? =20 >=20 > Are there any more comments regarding this patch? Gentle ping on this patch. >=20 > > =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 =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_/ay8FfJiHcAAN=8n+dFcohlS Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmCTswAACgkQAR8vZIA0 zr04Lwf/ZODXFgo4AuvnS8j1jCNFOg+gylU3AlxLA9zSWLYH7kSl7sufDkZ5xNou nVsG9Z8+aXGrzc7mkGxdw43XtcdUvT7pHfAD4VpwzUr6j8m4uV9sMpK39PQqvWul k/XrK2PsuyRfeqxEsc7q0eUzaTaRsxfIvs38Q6+zclqXO9fBmkdDTzgkwXob6L8j tBLfQKbrER4odgRlinFkqcj2bqzXRBt5/LlqJHr4kyMSSmYeuPZhyTCzAIq9jQtY VPQtiYDGJz7Oim6aS3Xb7bYgqTaNaQ3AJA+dVyxAWajsFUwc43GEwNfErruNN/Px rnijmU70e/GLfaaoLFNJpRCrbcW2Nw== =UbiC -----END PGP SIGNATURE----- --Sig_/ay8FfJiHcAAN=8n+dFcohlS--