From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp6-g21.free.fr (smtp6-g21.free.fr [212.27.42.6]) by sourceware.org (Postfix) with ESMTPS id D0677388E807 for ; Tue, 9 Mar 2021 18:09:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D0677388E807 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=opteya.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=ydroneaud@opteya.com Received: from [IPv6:2a01:e35:39f2:1220:ab87:b468:44f5:c88a] (unknown [IPv6:2a01:e35:39f2:1220:ab87:b468:44f5:c88a]) by smtp6-g21.free.fr (Postfix) with ESMTPS id 18C107803BD; Tue, 9 Mar 2021 19:09:01 +0100 (CET) Message-ID: <9a9954265dc62c04a946a6f570ba0ac2130fd535.camel@opteya.com> Subject: Re: [PATCH 1/2] tst: Add test for ntp_gettime From: Yann Droneaud To: Lukasz Majewski , Joseph Myers , Adhemerval Zanella , Florian Weimer , DJ Delorie Cc: GNU C Library , Florian Weimer , Alistair Francis Date: Tue, 09 Mar 2021 19:09:01 +0100 In-Reply-To: <20210309114709.23403-1-lukma@denx.de> References: <20210309114709.23403-1-lukma@denx.de> Organization: OPTEYA Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.38.4 (3.38.4-1.fc33) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_SOFTFAIL, 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, 09 Mar 2021 18:09:23 -0000 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(). It would be better to try again a few times. Regards. -- Yann Droneaud OPTEYA