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.10]) by sourceware.org (Postfix) with ESMTPS id EB0B83857817 for ; Wed, 10 Mar 2021 09:01:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EB0B83857817 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=whitebox@nefkom.net Received: from frontend01.mail.m-online.net (unknown [192.168.8.182]) by mail-out.m-online.net (Postfix) with ESMTP id 4DwR0H2Hddz1s0tT; Wed, 10 Mar 2021 10:01:51 +0100 (CET) Received: from localhost (dynscan1.mnet-online.de [192.168.6.70]) by mail.m-online.net (Postfix) with ESMTP id 4DwR0G6WXmz1sP6w; Wed, 10 Mar 2021 10:01:50 +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 AIFWbULzoPid; Wed, 10 Mar 2021 10:01:49 +0100 (CET) X-Auth-Info: Y83QrRqv4FMy+tmNqcdlZS5HpIxP1t/2RvpT3YGS2vmGIrDdpxMg3gMeZ9gsTXmj Received: from igel.home (ppp-46-244-173-168.dynamic.mnet-online.de [46.244.173.168]) (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; Wed, 10 Mar 2021 10:01:49 +0100 (CET) Received: by igel.home (Postfix, from userid 1000) id 890412C35D4; Wed, 10 Mar 2021 10:01:48 +0100 (CET) From: Andreas Schwab To: Yann Droneaud Cc: Lukasz Majewski , Joseph Myers , Adhemerval Zanella , Florian Weimer , DJ Delorie , Alistair Francis , Florian Weimer , GNU C Library Subject: Re: [PATCH 1/2] tst: Add test for ntp_gettime References: <20210309114709.23403-1-lukma@denx.de> <9a9954265dc62c04a946a6f570ba0ac2130fd535.camel@opteya.com> X-Yow: CHUBBY CHECKER owns my BUILDING! Date: Wed, 10 Mar 2021 10:01:48 +0100 In-Reply-To: <9a9954265dc62c04a946a6f570ba0ac2130fd535.camel@opteya.com> (Yann Droneaud's message of "Tue, 09 Mar 2021 19:09:01 +0100") Message-ID: <87k0qfv0ub.fsf@igel.home> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1.91 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_LOW, 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: Wed, 10 Mar 2021 09:01:56 -0000 On Mär 09 2021, Yann Droneaud wrote: > Hi, > > Le mardi 09 mars 2021 à 12:47 +0100, Lukasz Majewski a écrit : > > diff --git a/sysdeps/unix/sysv/linux/tst-ntp_gettime.c > b/sysdeps/unix/sysv/linux/tst-ntp_gettime.c > new file mode 100644 > index 0000000000..5a1261fd35 > --- /dev/null > +++ b/sysdeps/unix/sysv/linux/tst-ntp_gettime.c > @@ -0,0 +1,49 @@ > +/* Test for ntp_gettime > +   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 > + > +#ifndef NTP_GETTIME_SYSCALL > +# define NTP_GETTIME_SYSCALL ntp_gettime > +#endif > + > +# define STR(__s) #__s > + > +static int > +do_test (void) > +{ > +  struct timespec tv_now; > +  struct ntptimeval ntv; > + > +  int ret = NTP_GETTIME_SYSCALL (&ntv); > +  if (ret == -1) > +    FAIL_EXIT1 (STR(NTP_GETTIME_SYSCALL)" failed: %m\n"); > + > +  tv_now = xclock_now (CLOCK_REALTIME); > + > +  if (tv_now.tv_sec != ntv.time.tv_sec) > +    FAIL_EXIT1 ("ntp_gettime provided wrong time!\n"); > + > > This can fail if ntv.time.tv_usec is somewhere around 999999µs and the > process is scheduled before completing xclock_now(). That can be made race-free by calling xclock_now before and after NTP_GETTIME_SYSCALL, and repeat if the result of the two xclock_now calls do not agree. Andreas. -- Andreas Schwab, schwab@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."