From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 4AE793858004 for ; Mon, 22 Mar 2021 19:47:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4AE793858004 Received: by mail-qk1-x729.google.com with SMTP id y18so11892009qky.11 for ; Mon, 22 Mar 2021 12:47:29 -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=ge5gN8IZYl1bg2vqFlEb9oEOYNhDNO+3hRgUYvesBlg=; b=ISajlsXkiP/ZL9BdLrj7I/7RnkpQsOkIOflBm8+aUpoZbG+WxNMjQEa+puW90keygN WVvVVh91OJH0Bq5cS9tMyA2uRDrhDg8oUBujFJ1Uy5MvqOanzLYn6NhFDaK01kGm4oXj 1qZCVRiEVNjIaSJuBcN1EQ65niFXl3Xz03M31jMr1mCrFcRmCJryZq38oUEa9dZENR/y 2ZZYGGk9m9kjJ8J5SB11o9Vdln+HtBlF6hsKlIxXnkuO2tlrz21Yj5HGVumiBNlIpi0j 7MJin7R6JaUPKuIG1vSPz/+XjXFISig4paMGKkFdBh5IoKiZXbh9rgNJbWTLv7mORwPN xLiQ== X-Gm-Message-State: AOAM530JzDeuYoUkMcx9L8gJxJu47ToagwnbQE4SUJZEa+1L3GGaNxqC eXmeUjg+2nGzMLIp6gacqZ5HzB0bjT4VxQ== X-Google-Smtp-Source: ABdhPJwJLCB3iiOEGYGIVcJHn9gNPxypKpzOH2IjFdV1TcwpUsV+2SRC9xDpEvi3S+UUjf7JzRxGtA== X-Received: by 2002:a05:620a:2915:: with SMTP id m21mr1698879qkp.147.1616442448569; Mon, 22 Mar 2021 12:47:28 -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 z7sm11518235qkf.136.2021.03.22.12.47.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Mar 2021 12:47:28 -0700 (PDT) Subject: Re: [PATCH] tst: Provide test for getrusage To: Lukasz Majewski Cc: GNU C Library References: <20210315104223.32542-1-lukma@denx.de> From: Adhemerval Zanella Message-ID: <85d5e1b7-46c7-5904-0856-fc5f90493295@linaro.org> Date: Mon, 22 Mar 2021 16:47:25 -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: <20210315104223.32542-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:47:31 -0000 On 15/03/2021 07:42, Lukasz Majewski wrote: > This commit adds test to check if getrusage provides correct time > accounting for some busy wait loop. > > To be more specific - the time is measured in a loop by wrappers > from glibc's libsupport and checked if timeout has passed. > > Afterwards, the data from struct rusage, namely ru_stime and ru_utime > is summed up and compared with time from busy waiting. > --- > sysdeps/unix/sysv/linux/Makefile | 2 +- > sysdeps/unix/sysv/linux/tst-getrusage.c | 55 +++++++++++++++++++++++++ > 2 files changed, 56 insertions(+), 1 deletion(-) > create mode 100644 sysdeps/unix/sysv/linux/tst-getrusage.c > > diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile > index 6a45ac820a..a93fa4ca50 100644 > --- a/sysdeps/unix/sysv/linux/Makefile > +++ b/sysdeps/unix/sysv/linux/Makefile > @@ -113,7 +113,7 @@ 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-lutimes tst-ntp_gettime tst-ntp_gettimex tst-getrusage > tests-internal += tst-ofdlocks-compat tst-sigcontext-get_pc > tests-time64 += \ > tst-futimes-time64\ > diff --git a/sysdeps/unix/sysv/linux/tst-getrusage.c b/sysdeps/unix/sysv/linux/tst-getrusage.c > new file mode 100644 > index 0000000000..068becdadb > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-getrusage.c > @@ -0,0 +1,55 @@ > +/* 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 > + > +#define TST_GETRUSAGE_TIMEOUT 1 > + > +static int > +do_test (void) > +{ > + struct timespec tv_then, tv_now, gru_u, gru_s, s, r; > + struct rusage ru; > + int ret; > + > + tv_then = xclock_now (CLOCK_REALTIME); > + /* Busy wait for 1 second. */ > + do > + { > + tv_now = xclock_now (CLOCK_REALTIME); > + r = timespec_sub (tv_now, tv_then); > + } while ( r.tv_sec != TST_GETRUSAGE_TIMEOUT ); > + > + ret = getrusage (RUSAGE_SELF, &ru); > + if (ret == -1) > + FAIL_EXIT1 ("getrusage failed: %m\n"); > + > + gru_u = make_timespec (ru.ru_utime.tv_sec, ru.ru_utime.tv_usec * 1000); > + gru_s = make_timespec (ru.ru_stime.tv_sec, ru.ru_stime.tv_usec * 1000); > + s = timespec_add (gru_u, gru_s); > + > + TEST_COMPARE (support_timespec_check_in_range > + ((struct timespec) { 1, 0 }, s, 0.8, 1.2), 1); > + > + return 0; > +} > + > +#include > Timer accounting tests are tricky to get right and prone to show a lot of false positive failures and has bitten us in the past (check 04deeaa9ea74 and 9a29f1a2ae3d4b). So I think we should be as simple as possible and take in consideration that tests will run a timer shared machine so even with a busy wait the result timer might not take in consideration the desirable timeout. So for geturage (which afaik is also deprecated on future POSIX) I more simpler tests would be to: 1. Check for invalid 'who' (the EFAULT result from man-pages only trigger where syscall is issued directly, which is not always the case for glibc). 2. Issue getusage and check if the ru_utime.tv_nsec and ru_stime.tv_nsec are within the microseconds range. 3. Do some very short busy wait (10ms) and check if the ru_utime.tv_sec and ru_stime.tv_sec are equal or larger than the previous one. Also, I think this tests should generic, so move to resource folder.